void input() { D.clear(); h.clear(); cin >> N; REP(i, N){ cin >> d[i] >> n[i] >> w[i] >> e[i] >> s[i] >> dd[i] >> dp[i] >> ds[i]; w[i] += 1000; e[i] += 1000; }
void buildBCC () { idx = VI(n, -1), low = VI(n); cutVertices.clear(); bridges.clear(); st.clear(); components.clear(); totalComponents++; for (int i = 0; i < n; i++) if (idx[i] == -1) { DFS(make_pair(i, -1), 0); } }
int differentOutcomes( vector <string> board ) { h = SZ(board); LL res = 1; REP(i, SZ(board[0])){ b.clear(); p.clear(); MSET(dp, -1); REP(j, h){ if(board[j][i] == 'U') b.PB(0), p.PB(j+1); if(board[j][i] == 'D') b.PB(1), p.PB(j+1); } mul(res, rec(0, 0)); }
int removeThem(vector<int> a, int K) { k=K; n=a.size(); a0.clear(); a1.clear(); a2.clear(); a3.clear(); for(int i=0;i<a.size();++i) { if(a[i]%4==0)a0.pb(a[i]); if(a[i]%4==1)a1.pb(a[i]); if(a[i]%4==2)a2.pb(a[i]); if(a[i]%4==3)a3.pb(a[i]); } sort(a0.rbegin(),a0.rend()); sort(a1.rbegin(),a1.rend()); sort(a2.rbegin(),a2.rend()); sort(a3.rbegin(),a3.rend()); B[0][0]=a0[0]; for(int i=1;i<a0.size();++i) { B[0][i]=B[0][i-1]+a0[i]; } B[1][0]=a1[0]; for(int i=1;i<a1.size();++i) { B[1][i]=B[1][i-1]+a1[i]; } B[2][0]=a2[0]; for(int i=1;i<a2.size();++i) { B[2][i]=B[2][i-1]+a2[i]; } B[3][0]=a3[0]; for(int i=1;i<a3.size();++i) { B[3][i]=B[3][i-1]+a3[i]; } fill(dp,-1); return f(0,0,0,0); }
int main() { freopen("Text/EUROPEAN.txt","r",stdin); int cases; int ti; VI ans; scanf("%d",&cases); int i; for(int t=1;t<=cases;++t) { ct=0; MSET(fl,0); fs=111; scanf("%d",&n); for(i=0;i<n;++i) { scanf("%d",&ti); tarr[i]=ti; } ans.clear(); finn.clear(); ans.PB(0); sort(tarr,tarr+n); solve(ans); printf("Scenario #%d\n",t); printf("%d:",finn.size()); for(i=0;i<finn.size();++i) { printf(" %d",finn[i]); } printf("\n\n"); } return 0; }
int main() { int first=1,m,i,j,len,dlen; char cmd[15],oj,tc; while(1) { if(first) first=0; else scanf("%c%c",&tc,&tc); if(gets(a)==NULL) break; pos.clear();ans=0; gets(a); gets(b); len = strlen(b); alen = strlen(a); dlen = alen - len + 1; //findallsub(); for(i=0;i<dlen;i++) { for(j=0;;j++) { if(b[j]=='\0') { pos.push_back(i); ans++; break; } if(b[j]!=a[i+j]) break; } } // show(); //------------- scanf("%d",&m); while(m--) { //printf("i=%d\n",m); scanf("%s",cmd); //printf("%s\n",cmd); if(ans==0) { if(strcmp(cmd,"Query")==0) printf("0\n"); continue; } if(strcmp(cmd,"Query")==0) printf("%d\n",ans); else { scanf("%c%c",&tc,&oj); if(strcmp(cmd,"Push_back")==0) update(oj,len); else update(oj,-1); len++; // show(); } } } return 0; }
bool EulerU(VI &ce) { int v=-1; ce.clear(); VI l, st(SIZE(g), 0), of(SIZE(g)+1, 0); REP(x, SIZE(g)) { of[x+1] = of[x] + (st[x] = SIZE(g[x])); if ((st[x] & 1) || (v == -1 && st[x])) v = x; }
inline int solve(int testnum) { int n; scanf("%d",&n); VI a; a.clear(); REP(i,n) { int v; scanf("%d",&v); a.PB(v); }
void buildSCC () { index = 0, totalComponents = 0; idx = VI(n, -1), low = VI(n), componentOf = VI(n), inStack = VB(n, false); st.clear(); for (int i = 0; i < n; i++) if (idx[i] == -1) { DFS(i); } }
void build () { idx = VI(n, -1), low = VI(n); cutVertices.clear(); bridges.clear(); for (int i = 0; i < n; i++) if (idx[i] == -1) { DFS(make_pair(i, -1), 0); } }
int main(int argc, char *argv[]) { int TC, px, py; double ans; scanf("%d",&TC); while(TC-- > 0) { scanf("%d%d",&S,&P); X.clear(); Y.clear(); for(int i = 0; i < P; ++i) { scanf("%d%d",&px,&py); X.push_back(px); Y.push_back(py); } ans=binary_search(); printf("%.2lf\n",ans); } return 0; }
int getMoves( vector <string> board, int R, int C ) { r = R; c = C; szr = SZ(board); szc = SZ(board[0]); B.clear(); REP(i, szr){ int tmp = 0; REP(j, szc) if(board[i][j] == 'X') tmp += (1<<j); B.PB(tmp); }
// 強連結成分の数をついでに返す。 // 強連結成分の1番末尾の番号(cmp[]に入ってる)は、k-1なので注意。 int scc(){ MSET(used, false); vs.clear(); int k = 0; REP(v, V) if(!used[v]) dfs(v); MSET(used, false); for(int i = SZ(vs) - 1; i >= 0; i--) if(!used[vs[i]]) rdfs(vs[i], k++); return k; }
int getMin(string lamps) { s.clear(); for(int i=0;i<(int)lamps.length();++i)s.pb(lamps[i]=='Y'); fill(dp,-1); int ans=f(0,s[0],0,0); return ans; }
int main() { int T; scanf("%d",&T); for(int kase = 1;kase <= T;kase++) { numy.clear(); numz.clear(); scanf("%d",&n); for(int i = 0;i < n;i++) { getPoint(x1[i],y1[i],z1[i]); getPoint(x2[i],y2[i],z2[i]); numz.PB(z1[i]); numz.PB(z2[i]); numy.PB(y1[i]); numy.PB(y2[i]); } sort(numz.begin(),numz.end()); sort(numy.begin(),numy.end()); numz.erase(unique(numz.begin(),numz.end()),numz.end()); numy.erase(unique(numy.begin(),numy.end()),numy.end()); printf("Case %d: ",kase); cout << solve() << endl; } return 0; }
void solve() { prevv[0]=0; if(max_flow()<k) { printf("Impossible\n"); return; } //assert(e>=MAXM); int ti; int f=0; for(int i=tst;i<tst+ct;++i) { ans.clear(); ti=prevv[i]; while(ti!=-1) { ans.PB(ti); if(ti==prevv[ti] || !ti) { break; } ti=prevv[ti]; } if(ans.size()==0) { continue; } reverse(ans.begin(),ans.end()); if(ans[0]==0) { ++f; printf("1 "); for(int j=2;j<ans.size();j+=2) { printf("%d ",(ans[j]-MAXK)/2); } printf("2\n"); if(f==k) { break; } } } }
//lastrow = row for the last column void getPath(const VVI &parent, int lastrow, VI &path) { int nc = parent.size(); path.clear(); path.push_back(lastrow); if(nc > 1){ for(int c = nc - 2; c >= 0; c--){ //decide row for column c int r = parent[c+1][path.back()]; path.push_back(r); } } }
int main(void) { int N, x; while(sfi(N) && N) { rep(i, N) sfi(x), A.pb(x); printf("%llu\n",MaxArea()); A.clear(); } return (0); }
int main() { Esieve(); //cerr<<"SIEVE IS DONE"<<endl; VI factors; while(1) { factors.clear(); scanf("%d",&n); if(!n)break; cout<<n<<" = "; PrintFactors(n); } }
double eat( vector <int> prerequisite ) { p = prerequisite; int n = SZ(p); REP(i, 55) G[i].clear(); r.clear(); REP(i, n){ if(p[i] >= 0) G[p[i]].push_back(i); else r.push_back(i); } double res = 0.0; REP(i, SZ(r)) res += dfs(r[i], 1); return res; }
int main(){ int t; scanf("%d", &t); MEM(dp, -1); /** 只需在一开始初始化即可.当然必须确保dp的值唯一确定一个区间 **/ while(t --){ LL n; scanf("%I64d", &n); dig.clear(); while(n){ dig.push_back(n%10); n /= 10; } printf("%I64d\n", dfs(dig.size()-1, 0, 0, 1)); } return 0; }
vector <int> reconstruct(string signature) { VI res; res.clear(); res.push_back(1); int mxptr = 0; REP(i, SZ(signature)){ if(signature[i] == 'I') { res.push_back(i+2); mxptr = SZ(res) - 1; } else{ FOR(j, mxptr, SZ(res)) res[j]++; res.push_back(res[SZ(res)-1] - 1); } } return res; }
/// Calc diagonal matrix Lambda void CalcLambda(const VVI RM, VI & LM) { if (RM.size() == 0) { cerr << "Size of relation matrix!" << endl; exit(-1); } LM.clear(); unsigned int i, j; int sum = 0; for (i = 0; i < RM.size(); ++i) { sum = 0; for (j = 0; j < RM[i].size(); ++j) { sum += RM[i][j]; } LM.push_back(sum); } }
bool can(int prefLength,VI& result,bool return_result = false){ result.clear(); vector<Hash> hashes; int n = 1; for(int sn = 0; sn<n;++sn){ HashComputer<mod1> curHash1; HashComputer<mod2> curHash2; for(int i = 0; i < prefLength; ++i){ curHash1.add(a[sn][i]); curHash2.add(a[sn][i]); } hashes.push_back(Hash(make_pair(curHash1.value,curHash2.value),sn,0)); for(int i = prefLength; i < a[sn].size(); ++i){ curHash1.shift(a[sn][i-prefLength],a[sn][i],prefLength); curHash2.shift(a[sn][i-prefLength],a[sn][i],prefLength); hashes.push_back(Hash(make_pair(curHash1.value,curHash2.value),sn,i-prefLength+1)); } } sort(hashes.begin(),hashes.end()); //hashes.resize(unique(hashes.begin(),hashes.end(),EqualString())-hashes.begin()); VVI results; for(int i = k-1; i < hashes.size();++i) if(hashes[i].equals(hashes[i-k+1])){ if(return_result == true){ results.push_back(VI()); int k = results.size()-1; for(int j = i-n+1; j <=i;++j) results[k].push_back(hashes[j].pos); } else return true; } if(return_result == true){ result = *min_element(results.begin(),results.end()); return true; } return false; }
int main(){ //std::ios_base::sync_with_stdio(0); #ifdef CFw while(1){ #endif //FI;FO; int t, z = 0, l, i, n, len; v.clear(); M.clear(); si(t); rep(l,t){ si(n); if(!M[n]){ v.pb(n); M[n] = 1; } } si(n); while(n--){ si(t); z = bsl(t,v.size()); if(z == -1) ps("X"); else pi(v[z]); ps(" "); z = bsu(t,v.size()); if(z == -1) ps("X"); else pi(v[z]); NL; } #ifdef CFw NL; }
bool tSAT(int n) { for(int i = 0; i<n; i++){C[i] = 0;V[i] = false;} tord.clear(); for(int i =0; i<n; i++) if(V[i]==false) dfs(i); int cn = 0; reverse(tord.begin(),tord.end()); for(auto x : tord) if(C[x]==0) { cn++; dfs(x,cn); } for(int i = 0; i<n; i++){E[i].clear();rE[i].clear();} for(int i = 0; i<n; i+=2) if(C[i]==C[i+1])return false; return true; }
int main(){ #ifdef LOCAL freopen("/Users/apple/input.txt", "r", stdin); // freopen("/Users/apple/out.txt", "w", stdout); #endif while(si(n) != EOF) { mem(sum, 0); ans = -1; st.clear(); mp.clear(); rep(i, n) { si(a[i]); if(!mp[a[i]]) { mp[a[i]] = 1; st.pb(a[i]); } sum[a[i]] += 1; } int len = st.size(); rep(i, len) if(sum[st[i]] * 2 > n) ans = st[i]; printf("%d\n", ans); }
bool C(int x){ for(int i=0;i<4*N;i++){ G[i].clear(); rG[i].clear(); } rec.clear(); CLR(topo,0); for(int i=0;i<N;i++){ add_edge(key1[i],key2[i]+2*N); add_edge(key2[i],key1[i]+2*N); } for(int i=0;i<x;i++){ add_edge( door1[i]+2*N,door2[i]); add_edge( door2[i]+2*N,door1[i]); } int d = scc(); for(int i=0;i<2*N;i++){ if( topo[i] == topo[i+2*N]){ return 0; } } return 1; }
PIL go(ll cb=cINF) { // cost_bound if(!SPFA()) return MP(0,0); pe.clear(); int fl=INF; for(int v=n-1;v!=0;) { for(int id:e[v]) { int u=eg[id].to; const E& t=eg[id^1]; if(t.ca>0 && MP(d[u].F+t.cost,d[u].S+1)==d[v]) { fl=min(fl, t.ca); v=u; pe.PB(id^1); break; } } } if(d[n-1].F>0) fl=min(1ll*fl, cb/d[n-1].F); for(int id:pe) { eg[id].ca-=fl; eg[id^1].ca+=fl; } return MP(fl, 1ll*fl*d[n-1].F); }
void solve() { int ret=0; for(int i=1;i<=n;++i) { for(int j=i;j<=n;++j) { nums.clear(); nums.PB(DUMMY); summ[0]=0; reqa[0]=summ[0]-a; reqb[0]=summ[0]-b-1; nums.PB(summ[0]); nums.PB(reqa[0]); nums.PB(reqb[0]); for(int k=1;k<=m;++k) { summ[k]=summ[k-1]+arr[j][k]-arr[i-1][k]; reqa[k]=summ[k]-a; reqb[k]=summ[k]-b-1; nums.PB(summ[k]); nums.PB(reqa[k]); nums.PB(reqb[k]); } sort(nums.begin()+1,nums.end()); it=unique(nums.begin()+1,nums.end()); nums.resize(distance(nums.begin(),it)); nums_len=nums.size(); int ti; MSET(bitt,0); it=lower_bound(nums.begin()+1,nums.end(),summ[0]); ti=it-nums.begin(); //printf("Nums Len\t%d\n",nums_len); update(ti); for(int k=1;k<=m;++k) { //printf("DD\n"); int en=lower_bound(nums.begin()+1,nums.end(),reqa[k])-nums.begin(); int st=lower_bound(nums.begin()+1,nums.end(),reqb[k])-nums.begin(); ret+=query(en)-query(st); it=lower_bound(nums.begin()+1,nums.end(),summ[k]); ti=it-nums.begin(); update(ti); } } } printf("%d\n",ret); }