![Attaullah8207](/avatars/2752.jpg)
Attaullah8207
11.02.2021 •
Mathematics
On a 6 sided dice, what is the probability of rolling a number less than 3 and 6. P(n<3 and 6)
3/6
1/18
1/2
1/12
Solved
Show answers
More tips
- C Computers and Internet How to Format Your C Drive: Detailed Guide and Tips...
- F Food and Cooking How to Properly Cook Buckwheat?...
- F Food and Cooking How Many Grams Are In a Tablespoon?...
- L Leisure and Entertainment Carving: History and Techniques for Creating Vegetable and Fruit Decorations...
- P Photography and Videography How to Choose the Perfect Photo Paper for Your Images?...
- H Health and Medicine What vaccines do children need?...
- H Health and Medicine Reasons for the Appearance of Warts: Everything You Need to Know...
- A Art and Culture How to Learn Screaming: Step-by-Step Guide for Beginners...
- H Health and Medicine Contraceptive Pills After 35: The Importance Of Choosing The Right Medication...
- C Computers and Internet How to Choose a Monitor?...
Answers on questions: Mathematics
- M Mathematics Mr. O’Hara has developed a test of mechanical aptitude. At the beginning of a course in auto mechanics, he gives this test to his students. At the end of the year, he compares...
- M Mathematics The fraction 6/10 is equivalent to which of the following? 12/24 or 24/40 or 3/6 or 16/20...
- M Mathematics Square root 2 Times Square root 10 divided by square root 5...
- M Mathematics The length of a rope 18 metre 17cm what is the total length of 5 Sach rupees ...
- P Physics Can heating cooking oil you’ll be classified as producing a chemical change?...
- C Chemistry Which has a stronger attraction between particles water or methane?...
- M Mathematics Which shows how to find 9*305 mentally using the distributive property...
- M Mathematics Please help me. I’m so confused....
Ответ:
Step-by-step explanation:
Iterate the tags string and populate the containers to hold the tags and distance from (0, 0) (sqrt(X[i] * X[i] + Y[i] * Y[i]))Find the max distance of repeated tags while calculating distance of all tag points and keep the max distance so far.Now max distance among from the repeated tags which would be condition whether the points can be included in the circle or not. Iterate the X and Y axis array/vector , validate the distance against max distance. if the distance is less than max distance then point can be included into the circle.Time complexity approximately O(2N). Correct me if it wrong./ C++ Solution /
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <climits>
using namespace std;
int solution(string &S, vector<int> & X, vector<int> & Y)
{
vector<char> tags;
vector<int> tagsDis;
int sameTagDis = 0;
int noOfPoints = 0;
int maxDis = INT_MIN;
size_t N = X.size();
vector<char> ::iterator itr;
for(size_t i = 0; i < S.length() ; i++) {
int tmp = 0;
if(tags.size() == 0) {
tags.push_back(S.at(i));
tmp = sqrt((X[i] * X[i]) + (Y[i] * Y[i]));
tagsDis.push_back(tmp);
noOfPoints++;
} else {
itr = std::find(tags.begin(), tags.end(), S.at(i));
if (itr != tags.end()) {
int idx = std::distance(tags.begin(), itr);
tmp = sqrt((X[i] * X[i]) + (Y[i] * Y[i]));
tmp = std::max(tmp, tagsDis[idx]);
maxDis = std::max(maxDis, tmp);
tagsDis.push_back(tmp);
} else {
int tmpDis = sqrt((X[i] * X[i]) + (Y[i] * Y[i]));
tags.push_back(S.at(i));
noOfPoints++;
}
}
}
noOfPoints = 0;
for(size_t i = 0; i < N; i++) {
int tmpDis = sqrt((X[i] * X[i]) + (Y[i] * Y[i]));
if(maxDis > tmpDis) {
noOfPoints++;
}
}
return noOfPoints;
}
int main()
{
/*string S("ABDCA");
vector <int> X {2, -1,-4, -3, 3};
vector <int> Y {2, -2, 4, 1, -3};*/
/*string S("ABB");
vector <int> X {1, -2, 2};
vector <int> Y {1, -2, 2};*/
string S("ABDCAD");
vector <int> X {2, -1,-4, -3, 3, 2};
vector <int> Y {2, -2, 4, 1, -3, 2};
int N = solution(S, X, Y);
cout << "N : " << N << "\n";
}
//
Better solution will be appriciated.