/* * Union two person. * * TODO union by rank. * * :param a, b: persons' index. * :param ancestors: ancestors list. */ void union_(int a, int b, int *ancestors) { int ap, bp; ap = find_(a, ancestors); bp = find_(b, ancestors); /* TODO union by rank */ ancestors[ap] = bp; }
range next(range r, int type=0) const { for (r = find_(r.second); r.first != r.second; r = find_(r.second)) { nal_unit_header* h = reinterpret_cast<nal_unit_header*>(r.first+4); if (h->nri < 3) { continue; } if (type && h->type != type) { printf("nal nri %d type %d\n", int(h->nri), int(h->type)); continue; } printf("nal nri %d type %d, len %u\n", int(h->nri), int(h->type), int(r.second-r.first)); break; } return r; //find_(begin_); }
VTYPE get(const char* name, uint8_t n = 0) const { auto i = find_(name, n); if(i >= NUM) { return 0; } return value_[i]; }
range next(uint8_t* p, int type=0) const { range r = find_(p); for (; r[0] != r[1]; r = find_(r[1])) { nal_unit_header* h = reinterpret_cast<nal_unit_header*>(r[0]+4); if (h->nri < 3) { continue; } if (type && h->type != type) { LOGD("nal nri %d type %d", int(h->nri), int(h->type)); continue; } LOGD("nal nri %d type %d, len %u", int(h->nri), int(h->type), int(r[1]-r[0])); break; } return r; //find_(begin_); }
bool TwoThreeTree::find_(Node *node, int key) const{ if (node == NULL)//only root return false; if (node->isLeaf()) return node->key == key; return find_(node->child[node->findChildNo(key)], key); }
void query_relationship(int n, char (*persons)[MAX_PERSON_NAME_LENGTH], int *ancestors) { int i, a_idx, b_idx; char a_name[MAX_PERSON_NAME_LENGTH], b_name[MAX_PERSON_NAME_LENGTH]; for (i = 0; i < n; i++) { scanf("%s %s", a_name, b_name); /* TODO Error handling here. */ a_idx = find_person(a_name, persons); b_idx = find_person(b_name, persons); if (find_(a_idx, ancestors) == find_(b_idx, ancestors)) printf("%s\n", HAS_RELATIONSHIP); else printf("%s\n", HAS_NO_RELATIONSHIP); } }
int main(){ int n, q, t, a, b, f = 0; scanf("%d", &t); while(t--){ if(f++) putchar(10); scanf("%d", &n); V = n - 1; for(int i = 0; i < n; i++) scanf("%d%d", &p[i].x, &p[i].y); scanf("%d", &q); for(int i = 1; i <= n; i++) leader[i] = i; for(int i = 0; i < q; i++){ scanf("%d%d", &a, &b); int fa = find_(a), fb = find_(b); if(fa != fb) leader[fa] = fb, V--; } for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) dist[i *n + j].x = i + 1, dist[i *n + j].y = j + 1, dist[i * n + j].dis = (p[i].x - p[j].x) * (p[i].x - p[j].x) + (p[i].y - p[j].y) * (p[i].y - p[j].y); qsort(dist, n * n, sizeof(point), compare); if(!V) puts("No new highways need"); else{ int i = 0; while(V--){ while(1){ int fa = find_(dist[i].x), fb = find_(dist[i].y); if(fa != fb){ printf("%d %d\n", dist[i].x, dist[i].y); leader[fa] = fb; break; } i++; } } } } return 0; }
int main(){ int n, q, t, a, b, f = 0; while(scanf("%d", &n) > 0){ V = n - 1; for(int i = 0; i < n; i++) scanf("%d%d", &p[i].x, &p[i].y); scanf("%d", &q); for(int i = 1; i <= n; i++) leader[i] = i; for(int i = 0; i < q; i++){ scanf("%d%d", &a, &b); int fa = find_(a), fb = find_(b); if(fa != fb) leader[fa] = fb, V--; } for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) dist[i *n + j].x = i + 1, dist[i *n + j].y = j + 1, dist[i * n + j].dis = (p[i].x - p[j].x) * (p[i].x - p[j].x) + (p[i].y - p[j].y) * (p[i].y - p[j].y); qsort(dist, n * n, sizeof(point), compare); if(!V) puts("0.00"); else{ int i = 0; double ans = 0; while(V--){ while(1){ int fa = find_(dist[i].x), fb = find_(dist[i].y); if(fa != fb){ ans += sqrt(dist[i].dis); leader[fa] = fb; break; } i++; } } printf("%.2lf\n", ans); } } return 0; }
point_t* find_(node_t* node, double x, double y) { if (node_isleaf(node)) { if (node->point->x == x && node->point->y == y) { return node->point; } } else { point_t test; test.x = x; test.y = y; return find_(get_quadrant_(node, &test), x, y); } return NULL; }
void add_key_string_list(bp::ptree& pt, const std::string& key, const std::vector<std::string>& seq, bool append) { typedef bp::ptree::assoc_iterator a_it; typedef bp::ptree::value_type pt_value_type; a_it it = find_(pt, key, !append); if(it == pt.not_found()) { pt_value_type v(key, bp::ptree()); add_string_list(v.second, seq, true); pt.push_back(v); } else add_string_list(it->second, seq, append); }
Fx* FxManager::getFx( const tstring& resourceID ) { Fx* pEffect = find_( resourceID ); if (!pEffect) { pEffect = new Fx; if (pEffect->create( resourceID )) { add_( pEffect, resourceID ); } else { delete pEffect; pEffect = Fx::getNullObject(); } } return pEffect; }
int main(){ for(int i = 2; i < 1000000; i++) if(p[i] == 0){ prime[pct++] = i; for(int j = i * 2; j < 1000000; j += i) p[j] = 1; } int t, n, fg; scanf("%d", &t); while(t--){ scanf("%d", &n); for(int i = 0; i < n; i++) scanf("%d", &s[i]); if(find_(n)) puts("This sequence is anti-primed."); } return 0; }
int find_(int x){ gap[x] += gap[leader[x]]; return x == leader[x] ? x : (leader[x] = find_(leader[x])); }
bp::ptree::const_assoc_iterator c_find_(const bp::ptree& pt, const std::string& key, bool get_first) { return find_(const_cast<bp::ptree&>(pt), key, get_first); }
bool set(const char*name, uint8_t n, VTYPE value) { auto i = find_(name, n); if(i >= NUM) return false; value_[i] = value; return true; }
/** * Search if tree has point and return point pointer * * quadtree_search(quadtree_t *tree, double x, y) * @return *point */ point_t * quadtree_search(quadtree_t *tree, double x, double y) { return find_(tree->root, x, y); }
void merge_(int a, int b){ djs[find_(a)] = find_(b); }
bool TwoThreeTree::find(int key)const{ return find_(root, key); }
int find_(int x){ return (x == djs[x]) ? x : (djs[x] = find_(djs[x])); }
bool erase(const char* name, uint8_t n = 0) { auto i = find_(name, n); if(i >= NUM) return false; table_[i] = nullptr; return true; }
const game::GameObject* common::GameWorld::who_were(utils::Point site) const { bool success; auto index = find_(site, success); return success ? objects_[index].get() : nullptr; }
bool find(const char* name, uint8_t n = 0) const { return find_(name, n) < NUM; }