結果
問題 | No.425 ジャンケンの必勝法 |
ユーザー |
![]() |
提出日時 | 2016-09-22 07:57:06 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,829 bytes |
コンパイル時間 | 1,955 ms |
コンパイル使用メモリ | 182,192 KB |
実行使用メモリ | 10,624 KB |
最終ジャッジ日時 | 2024-11-17 13:07:17 |
合計ジャッジ時間 | 17,813 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 WA * 4 |
other | WA * 13 TLE * 5 |
ソースコード
#include<bits/stdc++.h>using namespace std;struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);cout<<fixed<<setprecision(20);}}init;typedef double D;typedef vector<D> VD;typedef vector<VD> VVD;D vecmul(const VD a,const VD b){D res=0;int size=a.size();for(int i=0;i<size;i++)res+=a[i]*b[i];return res;}VD matmul(const VVD a,const VD b){int sz=a.size();VD res(sz,0.0);for(int i=0;i<sz;i++)for(int j=0;j<sz;j++)res[i]+=a[i][j]*b[j];return res;}VVD matmul(const VVD a,const VVD b){int sz=a.size();VVD res(sz,VD(sz,0.0));for(int i=0;i<sz;i++)for(int j=0;j<sz;j++)for(int k=0;k<sz;k++)res[i][j]+=a[i][k]*b[k][j];return res;}VD nxt(D p){D a=3/(1-p);D b=-a*(p/2);return {a,b,b-1};}VD prv(D p){D a=2/p;D b=-a*((1-p)/3);return {a,b,b-1};}const D eps=1e-9;int main(){D p,q,a,b,c,d,s,p1,p0,ps,res;cin>>p>>q;//q==0だけ場合分けif(q==0){res=(p+2)/(4-p);}else{//p1=a*p0+bを求める{VD x={3,1,0};VD y={-1,0,1};D t=q;while(t<1){D nt=min(t+q,1.0);VVD mat={nxt(t),{1.0,0.0,0.0},{0.0,0.0,1.0}};x=matmul(mat,x);y=matmul(mat,y);t=nt;}a=x[0];b=y[0];}//p0=c*p1+dを求める{VD x={2,1,0};VD y={-1,0,1};D t=1-q;while(t>0){D nt=max(t-q,0.0);VVD mat={prv(t),{1.0,0.0,0.0},{0.0,0.0,1.0}};x=matmul(mat,x);y=matmul(mat,y);t=nt;}c=x[0];d=y[0];}cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;//p0とp1がa,b,c,dから求まるp1=(a*d+b)/(1-a*c);p0=(c*p1+d);cout<<"p0="<<p0<<endl;cout<<"p1="<<p1<<endl;s=p;while(s-q>0)s-=q;{VVD m={{1.0,0.0,0.0},{0.0,1.0,0.0},{0.0,0.0,1.0}};D ss=s;while(ss<1){D nss=min(ss+q,1.0);m=matmul({nxt(ss),{1.0,0.0,0.0},{0.0,0.0,1.0}},m);ss=nss;}ps=(p1-m[0][1]*p0-m[0][2])/m[0][0];}cout<<"ps="<<ps<<endl;{VVD m={{1.0,0.0,0.0},{0.0,1.0,0.0},{0.0,0.0,1.0}};D ss=s;while(ss<p){D nss=min(ss+q,1.0);m=matmul({nxt(ss),{1.0,0.0,0.0},{0.0,0.0,1.0}},m);ss=nss;}res=m[0][0]*ps+m[0][1]*p0+m[0][2];}}cout<<1.0/3+res/3.0<<endl;return 0;}