結果
問題 | No.173 カードゲーム(Medium) |
ユーザー | LayCurse |
提出日時 | 2015-01-23 12:07:43 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 31 ms / 3,000 ms |
コード長 | 3,964 bytes |
コンパイル時間 | 1,640 ms |
コンパイル使用メモリ | 163,024 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-23 00:53:43 |
合計ジャッジ時間 | 2,702 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 5 ms
5,376 KB |
testcase_02 | AC | 27 ms
5,376 KB |
testcase_03 | AC | 27 ms
5,376 KB |
testcase_04 | AC | 27 ms
5,376 KB |
testcase_05 | AC | 23 ms
5,376 KB |
testcase_06 | AC | 23 ms
5,376 KB |
testcase_07 | AC | 20 ms
5,376 KB |
testcase_08 | AC | 20 ms
5,376 KB |
testcase_09 | AC | 31 ms
5,376 KB |
コンパイルメッセージ
main.cpp: In function ‘void reader(double*)’: main.cpp:15:29: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 15 | void reader(double *x){scanf("%lf",x);} | ~~~~~^~~~~~~~~ main.cpp: In function ‘double brute_dfs(int, int*, int*, double, int, int)’: main.cpp:95:35: warning: ‘pa[1]’ may be used uninitialized in this function [-Wmaybe-uninitialized] 95 | if(i==0) pp *= pa[0]; else pp *= pa[1]; | ~~~^~~~~~~~ main.cpp:96:35: warning: ‘pb[1]’ may be used uninitialized in this function [-Wmaybe-uninitialized] 96 | if(j==0) pp *= pb[0]; else pp *= pb[1]; | ~~~^~~~~~~~
ソースコード
#include<bits/stdc++.h> using namespace std; #define REP(i,a,b) for(i=a;i<b;i++) #define rep(i,n) REP(i,0,n) #define mygc(c) (c)=getchar_unlocked() #define mypc(c) putchar_unlocked(c) #define ll long long #define ull unsigned ll void reader(int *x){int k,m=0;*x=0;for(;;){mygc(k);if(k=='-'){m=1;break;}if('0'<=k&&k<='9'){*x=k-'0';break;}}for(;;){mygc(k);if(k<'0'||k>'9')break;*x=(*x)*10+k-'0';}if(m)(*x)=-(*x);} void reader(ll *x){int k,m=0;*x=0;for(;;){mygc(k);if(k=='-'){m=1;break;}if('0'<=k&&k<='9'){*x=k-'0';break;}}for(;;){mygc(k);if(k<'0'||k>'9')break;*x=(*x)*10+k-'0';}if(m)(*x)=-(*x);} void reader(double *x){scanf("%lf",x);} int reader(char c[]){int i,s=0;for(;;){mygc(i);if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF) break;}c[s++]=i;for(;;){mygc(i);if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF) break;c[s++]=i;}c[s]='\0';return s;} template <class T, class S> void reader(T *x, S *y){reader(x);reader(y);} template <class T, class S, class U> void reader(T *x, S *y, U *z){reader(x);reader(y);reader(z);} template <class T, class S, class U, class V> void reader(T *x, S *y, U *z, V *w){reader(x);reader(y);reader(z);reader(w);} void writer(int x, char c){int s=0,m=0;char f[10];if(x<0)m=1,x=-x;while(x)f[s++]=x%10,x/=10;if(!s)f[s++]=0;if(m)mypc('-');while(s--)mypc(f[s]+'0');mypc(c);} void writer(ll x, char c){int s=0,m=0;char f[20];if(x<0)m=1,x=-x;while(x)f[s++]=x%10,x/=10;if(!s)f[s++]=0;if(m)mypc('-');while(s--)mypc(f[s]+'0');mypc(c);} void writer(double x, char c){printf("%.15f",x);mypc(c);} void writer(const char c[]){int i;for(i=0;c[i]!='\0';i++)mypc(c[i]);} void writer(const char x[], char c){int i;for(i=0;x[i]!='\0';i++)mypc(x[i]);mypc(c);} template<class T> void writerLn(T x){writer(x,'\n');} template<class T, class S> void writerLn(T x, S y){writer(x,' ');writer(y,'\n');} template<class T, class S, class U> void writerLn(T x, S y, U z){writer(x,' ');writer(y,' ');writer(z,'\n');} template<class T> void writerArr(T x[], int n){int i;if(!n){mypc('\n');return;}rep(i,n-1)writer(x[i],' ');writer(x[n-1],'\n');} #define RAND (rand()/(RAND_MAX+1.0)) int N; double pA, pB; int A[30], B[30]; double monte(int tm){ int i, j, k, loop; int a[30], b[30], n; double all = 0, win = 0; int resA = 0, resB = 0; rep(loop, tm){ n = N; rep(i,n) a[i] = A[i], b[i] = B[i]; all++; resA = resB = 0; while(n){ if(n==1){ i = j = 0; } else { if(RAND < pA) i = 0; else i = RAND * (n-1) + 1; if(RAND < pB) j = 0; else j = RAND * (n-1) + 1; } if(a[i] > b[j]) resA += a[i]+b[j]; if(a[i] < b[j]) resB += a[i]+b[j]; n--; REP(k,i,n) a[k] = a[k+1]; REP(k,j,n) b[k] = b[k+1]; } if(resA > resB) win++; } return win / all; } double brute_dfs(int n, int a[], int b[], double p, int sA, int sB){ int i, j, k; int sa[30], sb[30]; double pa[2], pb[2], res = 0; double pp; if(n==0){ if(sA > sB) return p; return 0; } if(n==1) pa[0] = pb[0] = 1; if(n>=2){ pa[0] = pA; pb[0] = pB; pa[1] = (1-pA) / (n-1); pb[1] = (1-pB) / (n-1); } rep(i,n) rep(j,n){ rep(k,n) sa[k] = a[k], sb[k] = b[k]; REP(k,i,n-1) sa[k] = sa[k+1]; REP(k,j,n-1) sb[k] = sb[k+1]; pp = p; if(i==0) pp *= pa[0]; else pp *= pa[1]; if(j==0) pp *= pb[0]; else pp *= pb[1]; res += brute_dfs(n-1, sa, sb, pp, sA+((a[i]>b[j])?a[i]+b[j]:0), sB+((a[i]<b[j])?a[i]+b[j]:0)); } return res; } double brute(void){ int i, a[30], b[30]; double res; rep(i,N) a[i] = A[i], b[i] = B[i]; res = brute_dfs(N, a, b, 1, 0, 0); return res; } int main(){ int i, j, k; double res; reader(&N, &pA, &pB); rep(i,N) reader(A+i); rep(i,N) reader(B+i); sort(A,A+N); sort(B,B+N); REP(i,1,N) assert(A[i-1] != A[i]); REP(i,1,N) assert(A[i-1] != A[i]); rep(i,N) rep(j,N) assert(A[i] != B[j]); srand(time(NULL)); res = monte(20000); writerLn(res); // res = brute(); // writerLn(res); return 0; }