void stableMatching (int n, VVI& maleRank, VVI& femaleRank, VI& wife) { // a male m prefers w to w' if maleRank[m][w] < maleRank[m][w'] // returns male-optimal matching VI freeMen; VVPI fq(n); VI husband(n, -1); for (int m = 0; m < n; ++m) { for (int w = 0; w < n; ++w) { fq[m].push_back(make_pair(maleRank[m][w], w)); } sort(all(fq[m]), greater<PI>()); freeMen.push_back(m); } while (!freeMen.empty()) { int m = freeMen.back(), w = fq[m].back().y; fq[m].pop_back(); if (husband[w] == -1) { husband[w] = m; freeMen.pop_back(); } else if (femaleRank[w][m] < femaleRank[w][husband[w]]) { freeMen.pop_back(); freeMen.push_back(husband[w]); husband[w] = m; } } wife = VI(n); for (int w = 0; w < n; ++w) { wife[husband[w]] = w; } }
bool solve(int n, int k) { if (k == 1) return true; if (k > MAXK) return false; if (fact[k] > n) return false; VI v; int N = n; for (VI::iterator it = primes.begin(); it != primes.end() && (*it) * (*it) <= N; ++it) if (N % *it == 0) { v.push_back(0); while (N % *it == 0) { ++v.back(); N /= *it; } } if (N > 1) v.push_back(1); sort(v.begin(), v.end()); reverse(v.begin(), v.end()); k -= (int) v.size() + 1; for (VI::iterator it = v.begin(); it != v.end(); ++it) *it -= 1; while (!v.empty() && v.back() == 0) { v.pop_back(); } if (k <= 0) return true; if (DBG + 0) { cerr << "BEGIN!!!!!\n"; for (VI::iterator it = v.begin(); it != v.end(); ++it) cerr << *it << " -- "; cerr << endl; cerr << k << endl; } VI w(v.size(), 1); bool found = walk1(v, w, 0, k/*,set<VI>()*/); if (!found) { if (v.size() >= 3 && v[2] >= 3) { v[0] -= 1; v[1] -= 1; v[2] -= 1; found = walk1(v, w, 0, k - 1/*,set<VI>()*/); } } return found; }
pii minimum_odd() { pii ret(-1,-1); if(!ones.empty()){ ret = pii(1,ones.back()); ones.pop_back(); } else if(!odd.empty()) { ret = odd.top(); odd.pop(); } return ret; }
void go(VI as, int le, int ri) { assert((int)as.size()==ri-le+1); if(as.empty()) return; sort(all(as)); int x=as.front(); int cnt=0; VI s1, s2; for(int y: as) { if(y==x) continue; if(g[y][x]) ++cnt, s1.PB(y); else s2.PB(y); } ans[x]=le+cnt; go(s1, le, le+(int)s1.size()-1); go(s2, ri-(int)s2.size()+1, ri); }
void DFS(){ visited.resize(k,0); REP(v,k) if (!visited[v]){ visited[v] = 1; printf("%d 0\n",v+1); stack.PB(v); while (!(stack.empty())){ int u = stack.back(); stack.pop_back(); for(auto ngb : sol[u]) if (!visited[ngb]){ visited[ngb] = 1; printf("%d %d\n",ngb+1,u+1); stack.PB(ngb); } } } }
int main() { int n, bmi; double w, h; char c1, c2; VI num; while(cin >> n >> c1 >> w >> c2 >> h) { bmi = w / (h*h); if(bmi >= 25) num.PB(n); } if(num.empty()) cout << "該当なし" << endl; else { VI::iterator it = num.begin(); while(it != num.end()) { cout << *it << endl; it++; } } }
int dfs(int p, int fa, int lay) { ++lay_cnt[lay]; VI ss; f[p] = fa; for (int i = 0 ; i < mp[p].size() ; ++i) { int id = mp[p][i]; if (id == fa) continue; ss.push_back(dep[id] = dfs(id, p, lay+1)); if (ub[id]) ub[p] = 1; } if (ss.empty()) return 0; if (ss.size() == 1) { ub[p] = 1; return ss[0] + 1; } assert(ss.size() == 2); if (ss[0] == ss[1]) {return 1 + ss[0];} ub[p] = 1; return 1 + max(ss[0], ss[1]); }
int main(){ //freopen("in.txt","r",stdin); freopen("d.in","r",stdin); freopen("d.out","w",stdout); int n; cin>>n; int ai; map<int,int> mp; for(int i = 0; i < n; ++i){ scanf("%d",&ai); if(mp.find(ai) == mp.end()) mp[ai] = 1; else { int t = mp[ai]; mp[ai] = t+1; } } for(map<int,int>::iterator it = mp.begin();it!=mp.end();++it){ push(it->second,it->first); } /* if(odd.size() == 1 && even.size() == 1){ pii p = even.top(); int L = p.first/2; cout<<L; for(int i = 0; i < L; ++i){ printf("\n%d %d %d %d",p.second,p.second,odd[0].second,odd[0].second); } return 0; } */ while(!ones.empty()||!odd.empty()||!even.empty()){ if(odd.empty() && even.empty()) fail(); if(ones.empty() && odd.empty()){ vector<pii> b; Vpii_from_Q(b,even); int mx = b.back().second; for(int i = 0; i < b.size() -1 ; ++i){ for(int j = 0 ; j< b[i].second/2; ++j) ans_push(b[i].second,b[i].second,mx,mx); } break; } if(odd.size() == 1 && ones.empty() && odd.top().first == max_qnt){ if(!even.empty()){ vector<pii> b; int max_elem = odd.top().second; Vpii_from_Q(b,even); int mx = b.back().first; for(int i = 0; i < b.size(); ++i){ for(int j = 0 ; j< b[i].second/2; ++j) ans_push(b[i].second,b[i].second,max_elem,max_elem); } } break; } int a,b,c,d; pii min_p = minimum(); pii min_odd = minimum_odd(); a = b = min_p.second; c = min_odd.second; push(min_p.first - 2,min_p.second); push(min_odd.first + 1,min_odd.second); min_odd = minimum_odd(); d = min_odd.second; if(min_odd.first == -1) { vector<pii> b; Vpii_from_Q(b,even); if(!b.empty()){ for(int i = 0;i<b.size()-1;++i) push(b[i].first,b[i].second); push(b.back().first + 1,b.back().second); d = b.back().second; } } push(min_odd.first+1,min_odd.second); ans_push(a,b,c,d); } int L = ans[0].size(); cout<<L; for(int i = 0; i <L; ++i) printf("\n%d %d %d %d",ans[0][i],ans[1][i],ans[2][i],ans[3][i]); return 0; }