int main() { int T; cin>>T; //cout<<T<<endl; REP(t, T) { int N; cin>>N; string sc[N]; double WP[N]; double OWP[N]; double OOWP[N]; CLR(WP); CLR(OWP); CLR(OOWP); REP(i, N){ cin>>sc[i]; } REP(i, N) { { int win=0, all=0; REP(j, N) { if(sc[i][j]!='.') { win += sc[i][j]=='1'; all++; } } WP[i] = (double)win/all; } { int _all=0; REP(j, N) { if(sc[i][j]!='.') { _all++; // calc wp of j except i int win=0, all=0; REP(k, N) { if(k==i) continue; if(sc[j][k]!='.') { win += sc[j][k]=='1'; all++; } } OWP[i] += (double)win/all; } } OWP[i] /= (double)_all; } } cout<<"Case #"<<t+1<<":"<<endl; REP(i, N) { int all=0; REP(j, N) { if(sc[i][j]!='.') { OOWP[i] += OWP[j]; all++; } } OOWP[i] /= all; double RPI = 0.25 * WP[i] + 0.50 * OWP[i] + 0.25 * OOWP[i]; cout<<RPI<<endl; } cout<<endl; } return 0; }
(以下、long long に修正後のソース)
int gcd ( int a, int b ) { if(a<b) { int tmp=a; a=b; b=tmp; } int c; while ( a != 0 ) { c = a; a = b%a; b = c; } return b; } int main() { int T; cin>>T; //cout<<T<<endl; REP(t, T) { int ans = 1; int pd, pg, d=100, g=100, v; ll n; cin>>n>>pd>>pg; //cout<<n<<pd<<pg; v = gcd(d, pd); pd/=v; d/=v; v = gcd(g, pg); pg/=v; g/=v; //cout<<pd<<" "<<d<<" "<<pg<<" "<<g<<" "<<endl; //if(g<d) //{ // int a=d/g + 1; // g*=a; pg*=a; //} if((pd!=d&&pg==g)||(pd>0&&pg==0) || d>n) { cout<<"Case #"<<t+1<<": Broken"<<endl;; continue; } //cout<<pd<<" "<<d<<" "<<pg<<" "<<g<<" "<<endl; cout<<"Case #"<<t+1<<": Possible"<<endl;; } return 0; }
int main() { int T; cin>>T; //cout<<T<<endl; REP(t, T) { int N, M; cin>>N>>M; string D[N]; string L[M]; REP(i, N) cin>>D[i]; REP(i, M) cin>>L[i]; //REP(i, N) cout<<D[i]<<endl; //REP(i, M) cout<<L[i]<<endl; cout<<"Case #"<<t+1<<":"; REP(Li, M) { int lose[N]; CLR(lose); REP(di, N) { // choose D[di] //cout<<"choose "<<D[di]<<endl; int ng[N]; int nng=0; CLR(ng); REP(i, N) { if(D[di].SZ != D[i].SZ) {ng[i]=1;nng++;} } if(nng==N-1) continue; // begin guess REP(li, 26) { int contains=0; REP(i, N) { if(ng[i]) continue; if(D[i].find(L[Li][li])!=D[i].npos) { contains=1; break; } } if(contains) { char guess = L[Li][li]; //cout<<"guess "<<guess<<endl; int revealed=0; REP(p, D[di].SZ) { if(D[di][p]==guess) {revealed=1;break;} } if(!revealed) lose[di]++; REP(i, N) { if(ng[i]) continue; REP(p, D[i].SZ) { if(D[di][p]==guess && D[i][p]!=guess || D[di][p]!=guess && D[i][p]==guess) {ng[i]=1;nng++;break;} } } if(nng==N-1) break; } } } int max = -1; int maxi = -1; REP(i, N) { //cout<<lose[i]<<endl; if(max<lose[i]) {max=lose[i];maxi=i;} } cout<<" "<<D[maxi]; } cout<<endl; } return 0; }