int main() { int test_cases; cin>>test_cases; REP(ttt, test_cases) { int N, S, P; cin>>N>>S>>P; VI T(N); REP(i, N) cin>>T[i]; sort(ALLR(T)); //cout<<T<<endl; int ans = 0; REP(i, N) { if((T[i]+2)/3 >= P) ans++; else if(S>0 && T[i]>=2 && (T[i]+4)/3 >= P) { ans++; S--; } } cout<<"Case #"<<ttt+1<<": "<<ans<<endl; } return 0; }
↓あとで
int main() { int test_cases; cin>>test_cases; REP(ttt, test_cases) { int A, B; cin>>A>>B; int sp=1; VI tb; VI tb2; while(B>sp*10) { sp*=10; tb.PB(sp); } REP(i, tb.size()) tb2.PB(sp*10/tb[i]); int ans=0; for(int i=A;i<=B;i++) { //cout<<"i "<<i<<endl; set<int> used; REP(j, tb.size()) { int b = i/tb[j] + (i%tb[j])*tb2[j]; if(i<b && A<=b && b<=B && /* ADDED */ used.insert(b).second) { ans++; //cout<<b<<endl; } } } cout<<"Case #"<<ttt+1<<": "<<ans<<endl; } return 0; }
int main() { int test_cases; cin>>test_cases; REP(ttt, test_cases) { int H,W,D; cin>>H>>W>>D; //cout<<H<<" "<<W<<" "<<D<<endl; int ox=0, oy=0; REP(h, H) { string s; cin>>s; REP(i, s.size()) if(s[i]=='X') {ox=i; oy=h;} } ox--;oy--; //cout<<ox<<" "<<oy<<endl; int ww = 100/(W-2)+1; int hh = 100/(H-2)+1; int ans = 0; vector<pair<int, PII> > l; for(int x=-ww;x<=ww;x++) { for(int y=-hh;y<=hh;y++) { int MX = x*(W-2)+(x%2==0 ? ox : W-2-ox-1)-ox; int MY = y*(H-2)+(y%2==0 ? oy : H-2-oy-1)-oy; int d = MX*MX+MY*MY; //if(d!=0 && d<=D*D) cout<<d<<" "<<x<<" "<<y<<" "<<MX<<" "<<MY<<endl; if(d!=0 && d<=D*D) l.PB(MP(d, MP(MX, MY))); } } //map<int, int> dh; sort(ALL(l)); vector<PII> used; REP(i, l.size()) { int d = l[i].first; int MX=l[i].second.first; int MY=l[i].second.second; int ok=1; //cout<<"try "<<d<<" "<<MX<<" "<<MY<<endl; REP(j, used.size()) { int ux = used[j].first; int uy = used[j].second; if(MX*ux<0) continue; if(MY*uy<0) continue; if(ux==0) { if(MX!=0) continue; else {ok=0;break;} } if(uy==0) { if(MY!=0) continue; else {ok=0;break;} } int ug = GCD(ux, uy); int mg = GCD(MX, MY); if(ux/ug==MX/mg && uy/ug==MY/mg) {ok=0;break;} } if(ok) { //cout<<"X "<<d<<" "<<MX<<" "<<MY<<endl; //cout<<MX<<"\t"<<MY<<(MX==0 ? MY*10000000 : (double)MY/MX+(MX>0?1000:-1000))<<endl; //cout<<MX<<"\t"<<MY<<endl; ans++; used.PB(l[i].second); //dh[d]++; } } //vector<double> aa; //FOR(e, used) aa.PB(e->first==0 ? (double)e->second*1000000 : (double)e->second/e->first+(e->first>0?1000:-1000)); //sort(ALL(aa)); //REP(i, aa.size()-1) if(abs(aa[i]-aa[i+1]) < 0.00001) cout<<"ERROR"<<aa[i]<<" "<<aa[i+1]<<endl; //cout<<dh<<endl; cout<<"Case #"<<ttt+1<<": "<<ans<<endl; } return 0; }
class PasswordXGrid { public: int minSum(vector <string> H, vector <string> V) { int N=H.size()-1; int M=H[0].size(); VVI m(N+1, VI(M+1)); cout<<M<<" "<<N<<endl; REP(y, N+1) { REP(x, M+1) { if(x-1>=0) m[y][x] = max(m[y][x], m[y][x-1]+H[y][x-1]-'0'); if(y-1>=0) m[y][x] = max(m[y][x], m[y-1][x]+V[y-1][x]-'0'); } } //cout<<m<<endl; return m[N][M]; } };
class PasswordXGuessing { public: long long howMany(vector <string> G) { int N=G.size(); int X=G[0].size(); ll ans=0; //cout<<endl; REP(wr, X) { VI can(X*10, 1); REP(j, X) { if(j==wr) { can[j*10+G[0][j]-'0']=0; } else { REP(z, 10) if(z!=G[0][j]-'0') can[j*10+z]=0; } } //cout<<can<<endl; int ok=1; for(int i=1;i<N;i++) { //cout<<i<<endl; int x=0; VI w(X); REP(j, X) { if(can[j*10+G[i][j]-'0']) { if(j!=wr) w[j]=1; } else { x++; w[j]=1; } } //cout<<i<<endl; if(x>1) {ok=0;break;} if(x==1) { REP(j, X) if(w[j]==0) REP(zz, 10) if(zz!=G[i][j]-'0') can[j*10+zz]=0; } if(x==0) { REP(j, X) if(w[j]==0) can[j*10+G[i][j]-'0']=0; } if(!ok) break; } if(!ok) continue; ll lans=1; REP(j, X) { ll a=0; REP(z, 10) a+=can[j*10+z]; lans *= a; } //cout<<can<<endl; //cout<<"+ "<<lans<<endl; ans += lans; } return ans; } };