-
Notifications
You must be signed in to change notification settings - Fork 0
/
maxPointsIncludedInCircle.cpp
86 lines (66 loc) · 2.25 KB
/
maxPointsIncludedInCircle.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
// Example program
#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";
}