int f(int i, double mid, VI& w, int N, int sum) { double A = w[i]+sum*mid; double rest = sum*(1-mid); int ok=1; REP(j, N) { if(i==j) continue; if(A>w[j]) { rest -= A-w[j]; if(rest<0) { ok=0; break; } } } return ok; } int main() { int test_cases; cin>>test_cases; REP(ttt, test_cases) { int N; cin>>N; VI w(N); REP(i, N) cin>>w[i]; int sum = accumulate(ALL(w), 0); cout<<"Case #"<<ttt+1<<": "; REP(i, N) { if(i!=0) cout<<" "; double lo = 0, hi = 1; REP(loop, 100) { double mid = (lo+hi)/2; //cout<<mid<<" "<<A<<" "<<ok<<endl; int ok = f(i, mid, w, N, sum); if(ok) lo=mid; else hi=mid; } cout<<setprecision(8)<<hi*100; } cout<<endl; } return 0; }
(あとで)
#define INF 100000000 int main() { int test_cases; cin>>test_cases; REP(ttt, test_cases) { int L, H, W; cin>>L>>H>>W; VVI ce(H, VI(W)); VVI fl(H, VI(W)); REP(y, H) REP(x, W) cin>>ce[y][x]; REP(y, H) REP(x, W) cin>>fl[y][x]; VVI ti(H, VI(W, INF)); VVI he(H, VI(W)); VVI st(H, VI(W, 1)); st[0][0] = 0; ti[0][0] = 0; he[0][0] = L; VVI vis(H, VI(W)); priority_queue <pair <int, pair <int, int> > > q; //deque<PII> q; q.push(MP(0, MP(0,0))); // x, y int ok=0; while(q.size()) { int x = q.top().second.first; int y = q.top().second.second; //cout<<"pop "<<q.top().first<<" "<<x<<" "<<y<<endl; q.pop(); if(ti[y][x]==INF) continue; if(x==W-1 && y==H-1) {ok=1;break;} if(vis[y][x]) continue; vis[y][x]=1; int tdx[] = {1, 0, -1, 0}; int tdy[] = {0, 1, 0, -1}; REP(dir, 4) { if(dir==0 && x>=W-1) continue; // right if(dir==1 && y>=H-1) continue; // down if(dir==2 && 0>=x) continue; // left if(dir==3 && 0>=y) continue; // top int nx = x+tdx[dir]; int ny = y+tdy[dir]; int lvl = he[y][x]; if(fl[y][x]+50<=ce[ny][nx] && fl[ny][nx]+50<=ce[ny][nx] && fl[ny][nx]+50<=ce[y][x] ) { int wait = max(0, lvl-(ce[ny][nx]-50)); if(!st[y][x] && wait==0) { st[ny][nx] = 0; ti[ny][nx] = ti[y][x]; he[ny][nx] = he[y][x]; } else if(fl[y][x]+20<=lvl-wait) { if(ti[y][x]+wait+10 < ti[ny][nx]) { ti[ny][nx] = ti[y][x]+wait+10; he[ny][nx] = lvl-(wait+10); } } else { if(ti[y][x]+wait+100 < ti[ny][nx]) { ti[ny][nx] = ti[y][x]+wait+100; he[ny][nx] = lvl-(wait+100); } } //cout<<"push "<<ti[ny][nx]<<" "<<nx<<" "<<ny<<endl; q.push(MP(-ti[ny][nx], MP(nx, ny))); } } //cout<<"loop end"<<endl; } //cout<<ti<<endl; //cout<<he<<endl; //cout<<st<<endl; //if(!ok) cout<<"!!!!"<<endl; cout<<"Case #"<<ttt+1<<": "<<(double)ti[H-1][W-1]/10<<endl; } return 0; }
void pr(ll i, VI& w, int N) { int first=1; REP(j, N) { if((i>>j)&1) { if(!first) cout<<" "; cout<<w[j]; first=0; } } cout<<endl; } int main() { int test_cases; cin>>test_cases; REP(ttt, test_cases) { int N; cin>>N; VI w(N); REP(i, N) cin>>w[i]; map<ll, ll> ma; int sum = accumulate(ALL(w), 0); int ok=0; REP(i, ((ll)1)<<N) { int A = 0; REP(j, N) { if((i>>j)&1) A += w[j]; } if(ma.count(A)) { cout<<"Case #"<<ttt+1<<":"<<endl; pr(ma[A], w, N); pr(i, w, N); ok=1; break; } ma[A] = i; } if(!ok) cout<<"Case #"<<ttt+1<<": Impossible"<<endl; } return 0; }
ここからpython
import sys import datetime y,m,d = map(int, sys.stdin.readline().split("/")) d=datetime.date(y,m,d) while True: if d.year % d.month==0 and (d.year / d.month) % d.day==0: print "%04d/%02d/%02d" % (d.year, d.month, d.day) sys.exit(0) d = d + datetime.timedelta(1)
流れでpython :)
datetime 要らんしw
import sys import datetime N=int(sys.stdin.readline()) s = sys.stdin.readline().rstrip() if N==1: print 1 sys.exit(0) #print s tt = [ x+y for x in "ABXY" for y in "ABXY" ] #print tt ans = 10000 for L in tt: for R in tt: ans = min(ans, len(s.replace(L, "L").replace(R, "R"))) print ans
int main() { int test_cases; cin>>test_cases; REP(ttt, test_cases) { int A, B; cin>>A>>B; double ans = 100000000; double co = 1.0; REP(i, A+1) { // co is prod[0, i) int bs = A-i; double p = (bs*2+B-A+1)*co+(bs*2+B-A+1+B+1)*(1-co); // cout<<bs<<" "<<p<<endl; ans=min(ans, p); if(i<A) { double in; cin>>in; co *= in; } } ans=min(ans, B+2.0); // enter right away cout<<"Case #"<<ttt+1<<": "<<setprecision(10)<<ans<<endl; } return 0; }
int f(int N, vector<PII>& a, vector<PII>& b) { VI lvl(N); // sort(ALL(a)); sort(ALL(b)); int cur=0; int ok=1; int ans=0; REP(i, N) { REP(ai, N) { if(cur >= b[i].first) break; // find appropriate star1 int idx=-1, maxb=-1; REP(j, N) { if(cur >= a[j].first && lvl[j]==0 && maxb < a[j].second) { idx=j; maxb = a[j].second; } } if(idx!=-1) { cur++; lvl[idx]=1; // cout<<"use 1 in "<<a[ai].first<<" "<<b[i].first<<endl; ans++; } else break; } if(cur < b[i].first) { ok=0; break; } cur+=lvl[b[i].second]==1 ? 1 : 2; lvl[b[i].second]=2; } return ok?N+ans:-1; } int main() { int test_cases; cin>>test_cases; REP(ttt, test_cases) { int N; cin>>N; vector<PII> a(N), b(N); REP(i, N) { cin>>a[i].first>>b[i].first; a[i].second = b[i].first; b[i].second=i; } int F = f(N, a, b); // int Ref = ref(N, a, b); // if(F!=Ref) { // cout<<"DIFF Case #"<<ttt+1<<" "<<F<<" "<<Ref<<endl; // } if(F!=-1) cout<<"Case #"<<ttt+1<<": "<<F<<endl; else cout<<"Case #"<<ttt+1<<": Too Bad"<<endl; } return 0; }
class AntsMeet { public: int countAnts(vector <int> x, vector <int> y, string dir) { int N=x.size(); VI live(N, 1); REP(i, N) { x[i]*=2; y[i]*=2; } REP(t, 4000) { VI nlive(live); REP(i, N) { if(!live[i]) continue; if(dir[i]=='N') y[i]++; if(dir[i]=='S') y[i]--; if(dir[i]=='E') x[i]++; if(dir[i]=='W') x[i]--; } REP(i, N) REP(j, N) if(i!=j && x[i]==x[j] && y[i]==y[j] && live[i] && live[j]) nlive[i]=nlive[j]=0; live=nlive; } return accumulate(ALL(live), 0); } };
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; } };