vector <string> countDescendants(vector <string> parentData) { f = true; vector <string> ret, fail; ST tmp = ""; tr(it, parentData) tmp += *it; while(tmp.length() > 0) { int idx = tmp.find(' '); vs.pb(tmp.substr(0, idx)); if(idx == string::npos) break; tmp = tmp.substr(idx+1); } sort(all(vs)); vs.resize(unique(all(vs)) - vs.begin()); tr(it, vs) { int idx = it->find(','); ST ch = it->substr(0, idx), par = it->substr(idx+1); cnt[ch] = cnt[par] = 0; g[par].pb(ch); }
int main() { int N; ST st; cin >> N >> st; map <char, int> mp; forn(i, st.size()) mp[st[i]]++; ST ret; tr(it, mp) { if(it->second % N != 0 ) { cout << -1 << endl; return 0; } forn(i, it->second/N) ret += it->first; } forn(i, N) cout << ret; cout << endl; return 0; }
/** Set the data costs of the MRF. */ void set_data_costs(std::vector<FaceInfo> const & face_infos, ST const & data_costs, std::vector<mrf::Graph::Ptr> const & mrfs) { /* Set data costs for all labels except label 0 (undefined) */ for (std::size_t i = 0; i < data_costs.rows(); i++) { ST::Row const & data_costs_for_label = data_costs.row(i); std::vector<std::vector<mrf::SparseDataCost> > costs(mrfs.size()); for(std::size_t j = 0; j < data_costs_for_label.size(); j++) { const std::size_t id = data_costs_for_label[j].first; const float data_cost = data_costs_for_label[j].second; const std::size_t component = face_infos[id].component; const std::size_t cid = face_infos[id].id; //TODO change index type of mrf::Graph costs[component].push_back({static_cast<int>(cid), data_cost}); } int label = i + 1; for (std::size_t j = 0; j < mrfs.size(); ++j) { mrfs[j]->set_data_costs(label, costs[j]); } } for (std::size_t i = 0; i < mrfs.size(); ++i) { /* Set costs for undefined label */ std::vector<mrf::SparseDataCost> costs(mrfs[i]->num_sites()); for (std::size_t j = 0; j < costs.size(); j++) { costs[j].site = j; costs[j].cost = MRF_MAX_ENERGYTERM; } mrfs[i]->set_data_costs(0, costs); } }
inline ST escapeCStringTpl(const ST &ba) { ST ret; ret.reserve(ba.length() * 2); for (int i = 0; i < ba.length(); ++i) { CT c = ba.at(i); switch (c) { case '\\': ret += "\\\\"; break; case '\a': ret += "\\a"; break; case '\b': ret += "\\b"; break; case '\f': ret += "\\f"; break; case '\n': ret += "\\n"; break; case '\r': ret += "\\r"; break; case '\t': ret += "\\t"; break; case '\v': ret += "\\v"; break; case '"': ret += "\\\""; break; default: if (c < 32 || c == 127) { ret += '\\'; ret += '0' + (c >> 6); ret += '0' + ((c >> 3) & 7); ret += '0' + (c & 7); } else { ret += c; } }
QScriptValue convert_script_value_f_size<ST>::operator()(QScriptEngine*eng, const ST & s) const { QScriptValue obj = eng->newObject(); obj.setProperty("width", QScriptValue(eng, s.width())); obj.setProperty("height", QScriptValue(eng, s.height())); return obj; }
int countInv(ST st) { int ret = 0; forn(i, st.size()) forab(j, i+1, st.size() - 1) if(st[j] < st[i]) ret++; return ret; }
void f() { if(s.length() == 0) return; // cout << s << " ; "; int idx = 0; forn(i, s.length()) if(s[i] > s[idx]) idx = i; ret += s[idx]; if(idx < s.length()) { s = s.substr(idx+1); f(); } }
int PermutationSum::add (int n) { SS ss; ss << n; ST st; st = ss.str(); sort(all(st)); cout << ss.str() << endl; int ret = 0; do { ret += atoi(st.c_str()); } while(next_permutation(all(st))); return ret; }
//2.【非递归版】 void solve(int root) { static Nod stk[maxn]; memset(vis, 0, sizeof(vis)); stk[0].init(root, E[root]); int len = 1; int lev = 0; cnt = 0; route[root] = 0; //update route! while(1) { Nod & cur = stk[len-1]; //here, b means current Nod, nxt means nxt's pointer(as buf.nxt)! if(false == vis[cur.b]) { vis[cur.b] = 1; F[++ cnt] = cur.b; rmq[cnt] = lev; P[cur.b] = cnt; } else if(cur.nxt == -1) { if(--len == 0) break; F[++ cnt] = stk[len-1].b; rmq[cnt] = -- lev; } else { int & i = cur.nxt; if(!vis[buf[i].b]) { route[buf[i].b] = route[cur.b] + V[i]; //update route! lev ++; stk[len ++].init(buf[i].b, E[buf[i].b]); } i = buf[i].nxt; } } st.init(2 * n - 1); }
int main(){ scanf("%d%d", &N, &Q); M = 1; while(M < N) M <<= 1; ST st = ST(); for(int i = 0; i < N; i++){ int h; scanf("%d", &h); st.update(h, i); } while(Q--){ int a, b; scanf("%d%d", &a, &b); a--; // cerr << a << " " << b << " " << st.get_max(a,b) << " " << st.get_min(a,b) << endl; printf("%d\n", st.get_max(a,b)-st.get_min(a,b)); } return 0; }
int bar(int a){ int r = a; a1.foo(); a2.foo(); b1.foo(); b2.foo(); c1.foo(); d1.foo(); e1.foo(); t1.foo(); t2.foo(); #pragma omp target teams ++r; return r + *R; }
/** Remove all edges of nodes which corresponding face has not been seen in any texture view. */ void isolate_unseen_faces(UniGraph * graph, ST const & data_costs) { int num_unseen_faces = 0; for (std::uint32_t i = 0; i < data_costs.cols(); i++) { ST::Column const & data_costs_for_face = data_costs.col(i); if (data_costs_for_face.size() == 0) { num_unseen_faces++; // get all the adjacent facets of the i-the facet // each facet is corresponding to // the a node in the UnifindGraph std::vector<std::size_t> const & adj_nodes = graph->get_adj_nodes(i); for (std::size_t j = 0; j < adj_nodes.size(); j++) graph->remove_edge(i, adj_nodes[j]); } } std::cout << "\t" << num_unseen_faces << " faces have not been seen by a view." << std::endl; }
int bar(int a){ int r = a; a1.foo(); a2.foo(); b1.foo(); b2.foo(); c1.foo(); d1.foo(); e1.foo(); t1.foo(); t2.foo(); #pragma omp target simd for (int i = 0; i < 10; ++i) ++r; return r + *R; }
int main() { setlocale( LC_ALL, "Russian" ); ST obj; cout << "Введите значение х (количество элементов в первом массиве): " << endl; int x; cin >> x; if(x <= 0) { cout << "х должен быть положительным числом! " << endl; } else { cout << endl; cout << "Начальный массив: " << endl; obj.set(x); cout << "Массив после сортировки: " << endl; obj.sort(x); } getch(); return 0; }
int main13123131(int argc, const char * argv[]) { srand((unsigned)time(NULL)); int N; N = 100000; clock_t begin,end; ST st; for (int i=0;i<N;i++) { Item it; it.rand(); // cout<<it.key()<<" "<<it.INFO()<<endl; st.insert(it); } Key v = 0; double result = 0; for (int i = 0; i < 10000; i++) { v=1 + (int) (element * (::rand() / (RAND_MAX + 1.0))); begin = clock(); st.search(v); end = clock(); double t = double (end-begin)/CLOCKS_PER_SEC * 1000; result += t; } result=result/10000*1000; cout<<"ST contains: "<<st.count()<<" elements"<<endl; // if (result.null()) // cout<<"Can not find the Key:"<<v; // else // cout<<"Key: "<<result.key()<<" Value:"<<result.INFO(); // double timeConsumed_ = double (end-begin)/CLOCKS_PER_SEC * 1000; cout<<endl<<result<<" ms"; return 0; }
int maxCities(int n, vector<int> a, vector<int> b, vector<int> len) { if (n <= 2) return n; vector<vector<int>> adjNode(n); for (int i = 0; i < n-1; ++i) { --a[i]; --b[i]; adjNode[a[i]].push_back(b[i]); adjNode[b[i]].push_back(a[i]); distMap[{a[i], b[i]}] = len[i]; distMap[{b[i], a[i]}] = len[i]; } int maxCount = 2; for (int i = 0; i < n; ++i) { Mii m; for (int j : adjNode[i]) { Si s; // node, parent ST<Pii> st; Vi d(n, -1); d[i] = 0; st.emplace(j, i); while (!st.empty()) { Pii p = st.top(); d[p.first] = dist(p.first, p.second) + d[p.second]; s.insert(d[p.first]); st.pop(); for (int k : adjNode[p.first]) { if (k == p.second) continue; st.emplace(k, p.first); } } for (int dd : s) { if (m.count(dd)) { ++m[dd]; } else m[dd] = 1; } } for (Pii t : m) { if (t.second > maxCount) maxCount = t.second; } } return maxCount; }
// CK2-LABEL: _Z3bari int bar(int arg){ ST<int> A; return A.foo(arg); }
#define pb push_back #define present(x, c) ((c).find(x) != (c).end()) //map & set// #define cpresent(x, c) (find( (c).begin(), (c).end(), x) != (c).end()) //vector & list// #define read(n) scanf("%d", &n) #define write(n) printf("%d ", n) #define writeln(n) printf("%d\n", n) #ifdef DEBUG #undef DEBUG #endif #define DEBUG ST s, t; vi mx, mn; vector <bool> in; int main() { cin >> s >> t; DEBUG(s); DEBUG(t); mx.resize(s.size(), 0); mn.resize(s.size(), t.size()); in.resize(s.size(), false); if(s.size() < t.size() || s.front() != t.front() || s.back() != t.back()) { DEBUG("#0");
int maintest() { srand((unsigned)time(NULL)); // clock_t begin,end; /* ST st; //INSERT ELEMENTS for (int i=0;i<N;i++) { Item it(i,i*0.1); // cout<<it.key()<<" "<<it.INFO()<<endl; st.insert(it); } Key v = 0; double result = 0; for (int i = 0; i < repeat; i++) { v=1 + (int) (N * (::rand() / (RAND_MAX + 1.0))); begin = clock(); st.search(v).INFO(); end = clock(); double t = double (end-begin)/CLOCKS_PER_SEC * 1000; result += t; } result=result/repeat; cout<<"ST contains: "<<st.count()<<" elements"<<endl; cout<<"The search cost "<<result<<" ms"; */ /* Binary search st */ int key_[N]; float val_[N]; for (int i=0; i<N ; i++) { key_[i] = 0; val_[i] = 0; } ST bsst; for (int i=0; i<N; i++) { Item item(i,i*0.1); //insert items if (binarysearch2(item.key(),0, bsst.count(),key_) == -1) { int j=bsst.count(); while(item.key()<key_[j-1]) { if(j==0) break; key_[j]=key_[j-1]; val_[j]=val_[j-1]; j--; } key_[j]=item.key(); val_[j]=item.INFO(); } else { val_[binarysearch2(item.key(),0, bsst.count(),key_)] = item.INFO(); } bsst.insert(item); } Key v = 0; double result = 0; clock_t begin,end; begin = clock(); for (int i = 0; i < repeat; i++) { v=1 + (int) (N * (::rand() / (RAND_MAX + 1.0))); Item x = bsst.search(N/2); } end = clock(); result=double (end-begin)/CLOCKS_PER_SEC * 1000; cout<<"ST contains: "<<bsst.count()<<" elements"<<endl; cout<<"The search cost "<<result<<" ms"; result = 0; int max = bsst.count()-1; begin = clock(); for (int i=0; i <repeat; i++) { v=1 + (int) (N * (::rand() / (RAND_MAX + 1.0))); binarysearch2(max,0, max,key_); } end = clock(); result=double (end-begin)/CLOCKS_PER_SEC * 1000; // result=result/repeat; cout<<endl<<"BSST contains: "<<bsst.count()<<" elements"<<endl; cout<<"The search cost "<<result<<" ms"; return 0; }
int query(int a, int b) { //传入两个节点,返回他们lca节点编号 return F[st.query(P[a], P[b])]; }
void solve(int root) { memset(vis, 0, sizeof(vis)); route[root] = cnt = 0; dfs(root, 0); st.init(2*n-1); }
bool process(ST file) { ifstream in1(file.c_str()); if(in1 == nullptr) return false; ST outfile = "ocf." + file; ofstream out1(outfile.c_str()); ST st; vs includes; while(getline(in1, st)) { if(st.size() >= 8 && st.substr(0, 8) == "#include") includes.pb(st); else out1 << st << endl; } out1.flush(); ST tmpfile = "sqae." + file; ST command = "cpp " + outfile + " > " + tmpfile; system(command.c_str()); int idx = file.find_first_of('.'); // ST name = file.substr(0, idx) + "_new.cpp"; ST name = file.substr(0, idx) + "_preprocessed.cpp"; ifstream in2(tmpfile.c_str()); // ofstream out2(("new_" + file).c_str()); ofstream out2(name.c_str()); bool isTypedef = false; // out2 << "//%%%%%%%%%%%%\n//%%%%lost%%%%\n//%%%%%%%%%%%%\n\n"; out2 << "//Name : Shinchan Nohara\n" "//Age : 5 years\n" "//Organisation : Kasukabe Defense Force\n\n"; for(auto &x: includes) out2 << x << endl; bool blankLine = false; while(getline(in2, st)) { if(st.size() >= 2 && st.substr(0, 2) == "# ") continue; if(blankLine && st == "") continue; blankLine = false; if(isTypedef && !(st.size() >= 7 && st.substr(0, 7) == "typedef")) out2 << endl; if(st.size() >= 7 && st.substr(0, 7) == "typedef") { isTypedef = true; out2 << endl; } if(st == "") blankLine = true; int i; for(i = 0; i < st.size() && st[i] == ' '; i++) out2 << "\t"; out2 << st.substr(i); } system(("rm " + tmpfile).c_str()); system(("rm " + outfile).c_str()); return true; }
void constraints() { ST seg; ST const seg_c; typedef typename segment_traits<ST>::topology_type topology_type; typedef typename segment_traits<ST>::segment_key_iterator segment_key_iterator; typedef typename segment_traits<ST>::segment_skey_iterator segment_skey_iterator; typedef typename segment_traits<ST>::segment_vertex_quantity_iterator vertex_key_iterator; typedef typename segment_traits<ST>::segment_edge_quantity_iterator edge_key_iterator; typedef typename segment_traits<ST>::segment_facet_quantity_iterator facet_key_iterator; typedef typename segment_traits<ST>::segment_cell_quantity_iterator cell_key_iterator; typedef typename segment_traits<ST>::vertex_type vertex_type; typedef typename segment_traits<ST>::edge_type edge_type; typedef typename segment_traits<ST>::facet_type facet_type; typedef typename segment_traits<ST>::cell_type cell_type; typedef typename segment_traits<ST>::vertex_handle vertex_handle; typedef typename segment_traits<ST>::edge_handle edge_handle; typedef typename segment_traits<ST>::facet_handle facet_handle; typedef typename segment_traits<ST>::cell_handle cell_handle; typedef typename segment_traits<ST>::vertex_iterator vertex_iterator; typedef typename segment_traits<ST>::edge_iterator edge_iterator; typedef typename segment_traits<ST>::facet_iterator facet_iterator; typedef typename segment_traits<ST>::cell_iterator cell_iterator; boost::function_requires< GSSETopologyConcept<topology_type> > (); // gsse segment concept checks // -------------------------- // naming // std::string s; seg.set_name(s); s = seg_c.get_segment_name(); // -------------------------- // segment quantity key iterations // segment_key_iterator sk_it; sk_it = seg_c.segment_key_begin(); sk_it = seg_c.segment_key_end(); segment_skey_iterator ssk_it; ssk_it = seg_c.segment_skey_begin(); ssk_it = seg_c.segment_skey_end(); vertex_key_iterator vk_it; vk_it = seg_c.vertex_key_begin(); vk_it = seg_c.vertex_key_end(); edge_key_iterator ek_it; ek_it = seg_c.edge_key_begin(); ek_it = seg_c.edge_key_end(); facet_key_iterator fk_it; fk_it = seg_c.facet_key_begin(); fk_it = seg_c.facet_key_end(); cell_key_iterator ck_it; ck_it = seg_c.cell_key_begin(); ck_it = seg_c.cell_key_end(); // -------------------------- // quantity key sizes // unsigned int size; size = seg_c.vertex_key_size(); size = seg_c.edge_key_size(); size = seg_c.facet_key_size(); size = seg_c.cell_key_size(); size = seg_c.segment_key_size(); size = seg_c.vertex_size(); size = seg_c.edge_size(); size = seg_c.facet_size(); size = seg_c.cell_size(); // -------------------------- // topological traversal // vertex_iterator vertex_it = seg_c.vertex_begin(); vertex_it = seg_c.vertex_begin(); edge_iterator edge_it = seg.edge_begin(); // [RH][TODO] .. maybe we can a const segment as well edge_it = seg.edge_begin(); facet_iterator facet_it = seg.facet_begin(); facet_it = seg.facet_begin(); cell_iterator cell_it = seg_c.cell_begin(); cell_it = seg_c.cell_begin(); // boost::function_requires<GSSEIteratorConcept<edge_iterator> > (); // boost::function_requires<GSSEIteratorConcept<facet_iterator> > (); // -------------------------- // topology retrieval // topology_type& topo = seg.retrieve_topology(); topology_type const& topo_c = seg_c.retrieve_topology(); ignore_unused_variable_warning(topo); ignore_unused_variable_warning(topo_c); }
void view_selection(ST const & data_costs, UniGraph * graph, Settings const & settings) { UniGraph mgraph(*graph); isolate_unseen_faces(&mgraph, data_costs); unsigned int num_components = 0; std::vector<FaceInfo> face_infos(mgraph.num_nodes()); std::vector<std::vector<std::size_t> > components; // get components in the graph mgraph.get_subgraphs(0, &components); for (std::size_t i = 0; i < components.size(); ++i) { if (components.size() > 1000) num_components += 1; for (std::size_t j = 0; j < components[i].size(); ++j) { face_infos[components[i][j]] = {i, j}; } } #ifdef RESEARCH mrf::SOLVER_TYPE solver_type = mrf::GCO; #else mrf::SOLVER_TYPE solver_type = mrf::LBP; #endif /* Label 0 is undefined. */ const std::size_t num_labels = data_costs.rows() + 1; std::vector<mrf::Graph::Ptr> mrfs(components.size()); for (std::size_t i = 0; i < components.size(); ++i) { mrfs[i] = mrf::Graph::create(components[i].size(), num_labels, solver_type); } /* Set neighbors must be called prior to set_data_costs (LBP). */ set_neighbors(mgraph, face_infos, mrfs); set_data_costs(face_infos, data_costs, mrfs); bool multiple_components_simultaneously = false; #ifdef RESEARCH multiple_components_simultaneously = true; #endif #ifndef _OPENMP multiple_components_simultaneously = false; #endif if (multiple_components_simultaneously) { if (num_components > 0) { std::cout << "\tOptimizing " << num_components << " components simultaneously." << std::endl; } std::cout << "\tComp\tIter\tEnergy\t\tRuntime" << std::endl; } #ifdef RESEARCH #pragma omp parallel for schedule(dynamic) #endif for (std::size_t i = 0; i < components.size(); ++i) { switch (settings.smoothness_term) { case POTTS: mrfs[i]->set_smooth_cost(*potts); break; } bool verbose = mrfs[i]->num_sites() > 10000; util::WallTimer timer; mrf::ENERGY_TYPE const zero = mrf::ENERGY_TYPE(0); mrf::ENERGY_TYPE last_energy = zero; mrf::ENERGY_TYPE energy = mrfs[i]->compute_energy(); mrf::ENERGY_TYPE diff = last_energy - energy; unsigned int iter = 0; std::string const comp = util::string::get_filled(i, 4); if (verbose && !multiple_components_simultaneously) { std::cout << "\tComp\tIter\tEnergy\t\tRuntime" << std::endl; } while (diff != zero) { #pragma omp critical if (verbose) { std::cout << "\t" << comp << "\t" << iter << "\t" << energy << "\t" << timer.get_elapsed_sec() << std::endl; } last_energy = energy; ++iter; energy = mrfs[i]->optimize(1); diff = last_energy - energy; if (diff <= zero) break; } #pragma omp critical if (verbose) { std::cout << "\t" << comp << "\t" << iter << "\t" << energy << std::endl; if (diff == zero) { std::cout << "\t" << comp << "\t" << "Converged" << std::endl; } if (diff < zero) { std::cout << "\t" << comp << "\t" << "Increase of energy - stopping optimization" << std::endl; } } /* Extract resulting labeling from MRF. */ for (std::size_t j = 0; j < components[i].size(); ++j) { int label = mrfs[i]->what_label(static_cast<int>(j)); assert(0 <= label && static_cast<std::size_t>(label) < num_labels); graph->set_label(components[i][j], static_cast<std::size_t>(label)); } } }