dolphinden
BAN USER#include <vector>
#include <map>
#include <queue>
using namespace std;
std::vector<int> get_reporters(int id, std::map<int, std::vector<int>>& mp) {
std::vector<int> res;
std::queue<std::map<int, std::vector<int>>::iterator> qu;
auto iter = mp.find(id);
bool bFirst = true;
while (iter != mp.end()) {
if (qu.empty() && !bFirst)
break;
else if (!qu.empty()){
iter = qu.front();
qu.pop();
bFirst = false;
}
for (int i = 0; i < iter->second.size(); ++i) {
auto it = mp.find(iter->second[i]);
res.push_back(iter->second[i]);
if (it != mp.end()) {
qu.push(it);
}
}
}
return res;
}
int main()
{
std::map<int, std::vector<int>> mp = { std::pair<int, std::vector<int> >(1, {2,3,4}) ,
std::pair<int, std::vector<int> >(3, {5,6,7}) ,
std::pair<int, std::vector<int> >(5, {8,9,10}) };
std::vector<int> res = get_reporters(1, mp);
return 0;
}
- dolphinden May 11, 2018string create_signature(string s){
string sig = "";
for(int i = 0 ; i < s.size(); ++i){
if(sig.find(s[i]) == string::npos)
sig.push_back(s[i]);
}
sort(sig.begin(), sig.end());
return sig;
}
void output_distinct_patterns(vector<string>& v){
map<string, int> mm;
for(auto s : v){
string sig = create_signature(s);
auto it = mm.find(sig);
if(it == mm.end()){
mm.emplace(sig, 1);
}
else{
it->second++;
}
}
auto iter = mm.begin();
for(; iter != mm.end(); ++iter){
cout << iter->first << " " << iter->second << endl;
}
}
int main() {
vector<string> v = {"abbba", "ab", "ba", "abcd", "abdc", "adbc", "aabddc"};
output_distinct_patterns(v);
return 0;
}
- dolphinden October 02, 2017#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#define PI 3.14159265
using namespace std;
struct Point{
double x, y;
};
int get_angle(const Point& p){
return atan2 (p.y,p.x) * 180 / PI;
}
int best_angle(const vector<Point>& points, int v_angle){
int res = 0;
multimap<int, Point> mm;
for(int i = 0 ; i < points.size(); ++i){
mm.insert(pair<const int, Point>(get_angle(points[i]), points[i]));
cout << get_angle(points[i]) << " " << points[i].x << " " << points[i].y << endl;
}
int current_angle = 0;
auto iter = mm.begin(), iterE = mm.begin();
while(iterE != mm.end() && current_angle <= v_angle){
++iterE;
if(res < current_angle)
res=current_angle;
current_angle = iterE->first - iter->first;
}
while(iterE != mm.end()){
if(current_angle == v_angle){
res = current_angle;
break;
}
else if(current_angle > v_angle){
++iter;
} else{
++iterE;
if(res < current_angle)
res = current_angle;
}
current_angle = iterE->first - iter->first;
}
return res;
}
void test(int case_n, const vector<Point>& vp, int v){
cout << "test case " << case_n << " :" << endl;
cout << "input : " << endl;
cout << "angle : " << v << endl;
cout << "points : " << endl;
int a = best_angle(vp, v);
cout << "output : " << a << endl;
cout << "-----------------------" << endl << endl;
}
int main() {
test(1, vector<Point>({{10,10}, {10,5}, {6,8}, {1,9}, {9,4}}), 0);
test(2, vector<Point>({{10,10}, {10,5}, {6,8}, {1,9}, {9,4}}), 15);
test(3, vector<Point>({{10,10}, {10,5}, {6,8}, {1,9}, {9,4}}), 45);
test(4, vector<Point>({{10,10}, {10,5}, {6,8}, {3,9}, {9,4}}), 0);
test(5, vector<Point>({{10,10}, {10,5}, {6,8}, {3,9}, {9,4}}), 45);
test(6, vector<Point>({{10,10}, {10,5}, {6,8}, {3,9}, {9,4}}), 60);
test(7, vector<Point>({{10,10}, {10,5}, {6,8}, {4,9}, {9,4}}), 31);
test(8, vector<Point>({{10,10}, {10,5}, {6,8}, {4,9}, {9,4}}), 72);
test(9, vector<Point>({{10,10}, {10,5}, {6,8}, {4,9}, {9,4}}), 180);
return 0;
}
- dolphinden June 16, 2017
- dolphinden June 18, 2019