我太傻逼了打了13.5K
思路很简单,代码很难
#include<bits/stdc++.h> using namespace std; #define ll long long struct moo{ ll opt1;//第一个 ll xiaoyu,xiaoyudengyu,dayu,dayudengyu; ll opt2;//第二个 ll val1;//第一个数 ll val2;//第二个数 ll wenhao;//有无问号 }node[110]; ll n; ll mit[10],spd[10],san[10],kno[10]; double f[110][10][10][10][10],ans1[110],ans2[110],ans3[110],ans4[110],dice[30][75]; ll needpan(ll x){ if((!node[x].xiaoyu)&&(!node[x].dayu)&&(!node[x].xiaoyudengyu)&&(!node[x].dayudengyu)) return 0; return 1; } char ch1[110],ch2[110],ch3[110],ch4[110]; ll work(char c){ if(c=='i') return 1; if(c=='p') return 2; if(c=='a') return 3; if(c=='n') return 4; } void cal(ll i,ll j1,ll j2,ll j3,ll j4,ll opt,ll val,double gailv){ // printf("**************opt=%lld ",opt); if(opt==1){ if(j1+val<=0) return ; ll jj=j1+val; if(jj>8) jj=8; f[i+1][jj][j2][j3][j4]+=gailv*f[i][j1][j2][j3][j4]; } else if(opt==2){ if(j2+val<=0) return ; ll jj=j2+val; if(jj>8) jj=8; f[i+1][j1][jj][j3][j4]+=gailv*f[i][j1][j2][j3][j4]; } else if(opt==3){ if(j3+val<=0){ // printf("**** "); return ; } ll jj=j3+val; if(jj>8) jj=8; f[i+1][j1][j2][jj][j4]+=gailv*f[i][j1][j2][j3][j4]; } else{ if(j4+val<=0){ // printf("****** "); return ; } ll jj=j4+val; if(jj>8) jj=8; f[i+1][j1][j2][j3][jj]+=gailv*f[i][j1][j2][j3][j4]; // printf("f[%lld][%lld][%lld][%lld][%lld]=%lf ",i+1,j1,j2,j3,jj,f[i+1][j1][j2][j3][jj]); } } int main(){ ll ita,itb,itc,itd,a; scanf("%lld",&a); while(a){ mit[++mit[0]]=a%10; a/=10; } scanf("%lld",&ita); scanf("%lld",&a); while(a){ spd[++spd[0]]=a%10; a/=10; } scanf("%lld",&itb); scanf("%lld",&a); while(a){ san[++san[0]]=a%10; a/=10; } scanf("%lld",&itc); scanf("%lld",&a); while(a){ kno[++kno[0]]=a%10; a/=10; } scanf("%lld",&itd); scanf("%lld",&a); for(ll i=1;i<=a;i++){ scanf("%s",ch1+1); node[i].opt1=work(ch1[2]); scanf("%s",ch2+1); if(ch2[1]=='+'||ch2[1]=='-'){ ll x=0; ll it=2,f=1; if(ch2[1]=='-') f=-1; while(isdigit(ch2[it])){ x=x*10+ch2[it]-'0'; it++; } if(ch2[it]=='?'){ node[i].wenhao=1; } node[i].val1=x*f; } else { if(ch2[1]=='<'&&ch2[2]=='='){ node[i].xiaoyudengyu=1; } else if(ch2[1]=='<'){ node[i].xiaoyu=1; } else if(ch2[1]=='>'&&ch2[2]=='='){ node[i].dayudengyu=1; } else node[i].dayu=1; scanf("%lld",&node[i].val1); scanf("%s",ch3+1); node[i].opt2=work(ch3[2]); scanf("%s",ch2+1); ll x=0; ll it=2,f=1; if(ch2[1]=='-') f=-1; while(isdigit(ch2[it])){ x=x*10+ch2[it]-'0'; it++; } if(ch2[it]=='?'){ node[i].wenhao=1; } node[i].val2=x*f; } } // for(ll i=1;i<=a;i++){ // printf("opt1=%lld opt2=%lld val1=%lld val2=%lld wenhao=%lld <%lld <=%lld >%lld >=%lld ",node[i].opt1,node[i].opt2,node[i].val1,node[i].val2,node[i].wenhao,node[i].xiaoyu,node[i].xiaoyudengyu,node[i].dayu,node[i].dayudengyu); // } f[0][ita][itb][itc][itd]=100; dice[0][0]=1.0; for(ll i=0;i<=16;i++){ for(ll j=0;j<=32;j++){ dice[i+1][j+1]+=dice[i][j]*1.0/3.0; dice[i+1][j+2]+=dice[i][j]*1.0/3.0; dice[i+1][j]+=dice[i][j]*1.0/3.0; } } // printf("ita=%lld itb=%lld itc=%lld itd=%lld************ ",ita,itb,itc,itd); // printf("**** "); for(ll i=0;i<a;i++){ for(ll j1=1;j1<=8;j1++) for(ll j2=1;j2<=8;j2++) for(ll j3=1;j3<=8;j3++) for(ll j4=1;j4<=8;j4++){ if(f[i][j1][j2][j3][j4]){ if(!needpan(i+1)){ if(node[i+1].wenhao){ ll cnt=abs(node[i+1].val1); ll opt,opt1; if(node[i+1].val1<0) opt=-1; else opt=1; double delt=1; opt1=node[i+1].opt1; for(ll j=0;j<=32;j++){ if(!dice[cnt][j]) continue ; ll val=opt*j; cal(i,j1,j2,j3,j4,opt1,val,dice[cnt][j]); } } else { ll opt=node[i+1].opt1,val=node[i+1].val1; cal(i,j1,j2,j3,j4,opt,val,1.0); } } else {//void cal(ll i,ll j1,ll j2,ll j3,ll j4,ll opt,ll val,double gailv){ ll opt1=node[i+1].opt1,opt2=node[i+1].opt2; ll val1=node[i+1].val1,val2=fabs(node[i+1].val2); ll opt; if(node[i+1].val2<0) opt=-1; else opt=1; if(node[i+1].xiaoyu){//< if(opt1==1){ ll cnt1=mit[8-j1+1]; for(ll j=0;j<=32;j++){ if(j>=val1) f[i+1][j1][j2][j3][j4]+=dice[cnt1][j]*f[i][j1][j2][j3][j4]; else { if(node[i+1].wenhao){ for(ll q=0;q<=32;q++){ cal(i,j1,j2,j3,j4,opt2,opt*q,dice[cnt1][j]*dice[val2][q]); } } else { cal(i,j1,j2,j3,j4,opt2,opt*val2,dice[cnt1][j]); } } } } if(opt1==2){ ll cnt1=spd[8-j2+1]; for(ll j=0;j<=32;j++){ if(j>=val1) f[i+1][j1][j2][j3][j4]+=dice[cnt1][j]*f[i][j1][j2][j3][j4]; else { if(node[i+1].wenhao){ for(ll q=0;q<=32;q++){ cal(i,j1,j2,j3,j4,opt2,opt*q,dice[cnt1][j]*dice[val2][q]); } } else { cal(i,j1,j2,j3,j4,opt2,opt*val2,dice[cnt1][j]); } } } } if(opt1==3){ ll cnt1=san[8-j3+1]; for(ll j=0;j<=32;j++){ if(j>=val1) f[i+1][j1][j2][j3][j4]+=dice[cnt1][j]*f[i][j1][j2][j3][j4]; else { if(node[i+1].wenhao){ for(ll q=0;q<=32;q++){ // printf("%lf cnt1=%lld val2=%lld dice ",dice[cnt1][j]*dice[val2][q],cnt1,val2); cal(i,j1,j2,j3,j4,opt2,opt*q,dice[cnt1][j]*dice[val2][q]); // printf("f=%lf ",f[i+1][j1][j2][j3+opt*val2][j4]); } } else { cal(i,j1,j2,j3,j4,opt2,opt*val2,dice[cnt1][j]); } } } } if(opt1==4){ ll cnt1=kno[8-j4+1]; for(ll j=0;j<=32;j++){ if(j>=val1) f[i+1][j1][j2][j3][j4]+=dice[cnt1][j]*f[i][j1][j2][j3][j4]; else { if(node[i+1].wenhao){ for(ll q=0;q<=32;q++){ cal(i,j1,j2,j3,j4,opt2,opt*q,dice[cnt1][j]*dice[val2][q]); } } else { cal(i,j1,j2,j3,j4,opt2,opt*val2,dice[cnt1][j]); } } } } } else if(node[i+1].dayu){ if(opt1==1){ ll cnt1=mit[8-j1+1]; for(ll j=0;j<=32;j++){ if(j<=val1) f[i+1][j1][j2][j3][j4]+=dice[cnt1][j]*f[i][j1][j2][j3][j4]; else { if(node[i+1].wenhao){ for(ll q=0;q<=32;q++){ cal(i,j1,j2,j3,j4,opt2,opt*q,dice[cnt1][j]*dice[val2][q]); } } else { cal(i,j1,j2,j3,j4,opt2,opt*val2,dice[cnt1][j]); } } } } if(opt1==2){ ll cnt1=spd[8-j2+1]; for(ll j=0;j<=32;j++){ if(j<=val1) f[i+1][j1][j2][j3][j4]+=dice[cnt1][j]*f[i][j1][j2][j3][j4]; else { if(node[i+1].wenhao){ for(ll q=0;q<=32;q++){ cal(i,j1,j2,j3,j4,opt2,opt*q,dice[cnt1][j]*dice[val2][q]); } } else { cal(i,j1,j2,j3,j4,opt2,opt*val2,dice[cnt1][j]); } } } } if(opt1==3){ ll cnt1=san[8-j3+1]; for(ll j=0;j<=32;j++){ if(j<=val1) f[i+1][j1][j2][j3][j4]+=dice[cnt1][j]*f[i][j1][j2][j3][j4]; else { if(node[i+1].wenhao){ for(ll q=0;q<=32;q++){ cal(i,j1,j2,j3,j4,opt2,opt*q,dice[cnt1][j]*dice[val2][q]); } } else { cal(i,j1,j2,j3,j4,opt2,opt*val2,dice[cnt1][j]); } } } } if(opt1==4){ ll cnt1=kno[8-j4+1]; for(ll j=0;j<=32;j++){ if(j<=val1) f[i+1][j1][j2][j3][j4]+=dice[cnt1][j]*f[i][j1][j2][j3][j4]; else { if(node[i+1].wenhao){ for(ll q=0;q<=32;q++){ cal(i,j1,j2,j3,j4,opt2,opt*q,dice[cnt1][j]*dice[val2][q]); } } else { cal(i,j1,j2,j3,j4,opt2,opt*val2,dice[cnt1][j]); } } } } } else if(node[i+1].dayudengyu){ if(opt1==1){ ll cnt1=mit[8-j1+1]; for(ll j=0;j<=32;j++){ if(j<val1) f[i+1][j1][j2][j3][j4]+=dice[cnt1][j]*f[i][j1][j2][j3][j4]; else { if(node[i+1].wenhao){ for(ll q=0;q<=32;q++){ cal(i,j1,j2,j3,j4,opt2,opt*q,dice[cnt1][j]*dice[val2][q]); } } else { cal(i,j1,j2,j3,j4,opt2,opt*val2,dice[cnt1][j]); } } } } if(opt1==2){ ll cnt1=spd[8-j2+1]; for(ll j=0;j<=32;j++){ if(j<val1) f[i+1][j1][j2][j3][j4]+=dice[cnt1][j]*f[i][j1][j2][j3][j4]; else { if(node[i+1].wenhao){ for(ll q=0;q<=32;q++){ cal(i,j1,j2,j3,j4,opt2,opt*q,dice[cnt1][j]*dice[val2][q]); } } else { cal(i,j1,j2,j3,j4,opt2,opt*val2,dice[cnt1][j]); } } } } if(opt1==3){ ll cnt1=san[8-j3+1]; for(ll j=0;j<=32;j++){ if(j<val1) f[i+1][j1][j2][j3][j4]+=dice[cnt1][j]*f[i][j1][j2][j3][j4]; else { if(node[i+1].wenhao){ for(ll q=0;q<=32;q++){ cal(i,j1,j2,j3,j4,opt2,opt*q,dice[cnt1][j]*dice[val2][q]); } } else { cal(i,j1,j2,j3,j4,opt2,opt*val2,dice[cnt1][j]); } } } } if(opt1==4){ ll cnt1=kno[8-j4+1]; for(ll j=0;j<=32;j++){ if(j<val1) f[i+1][j1][j2][j3][j4]+=dice[cnt1][j]*f[i][j1][j2][j3][j4]; else { if(node[i+1].wenhao){ for(ll q=0;q<=32;q++){ cal(i,j1,j2,j3,j4,opt2,opt*q,dice[cnt1][j]*dice[val2][q]); } } else { cal(i,j1,j2,j3,j4,opt2,opt*val2,dice[cnt1][j]); } } } } } else { if(opt1==1){ ll cnt1=mit[8-j1+1]; for(ll j=0;j<=32;j++){ if(j>val1) f[i+1][j1][j2][j3][j4]+=dice[cnt1][j]*f[i][j1][j2][j3][j4]; else { if(node[i+1].wenhao){ for(ll q=0;q<=32;q++){ cal(i,j1,j2,j3,j4,opt2,opt*q,dice[cnt1][j]*dice[val2][q]); } } else { cal(i,j1,j2,j3,j4,opt2,opt*val2,dice[cnt1][j]); } } } } if(opt1==2){ ll cnt1=spd[8-j2+1]; for(ll j=0;j<=32;j++){ if(j>val1) f[i+1][j1][j2][j3][j4]+=dice[cnt1][j]*f[i][j1][j2][j3][j4]; else { if(node[i+1].wenhao){ for(ll q=0;q<=32;q++){ cal(i,j1,j2,j3,j4,opt2,opt*q,dice[cnt1][j]*dice[val2][q]); } } else { cal(i,j1,j2,j3,j4,opt2,opt*val2,dice[cnt1][j]); } } } } if(opt1==3){ ll cnt1=san[8-j3+1]; for(ll j=0;j<=32;j++){ if(j>val1) f[i+1][j1][j2][j3][j4]+=dice[cnt1][j]*f[i][j1][j2][j3][j4]; else { if(node[i+1].wenhao){ for(ll q=0;q<=32;q++){ cal(i,j1,j2,j3,j4,opt2,opt*q,dice[cnt1][j]*dice[val2][q]); } } else { cal(i,j1,j2,j3,j4,opt2,opt*val2,dice[cnt1][j]); } } } } if(opt1==4){ ll cnt1=kno[8-j4+1]; for(ll j=0;j<=32;j++){ if(j>val1) f[i+1][j1][j2][j3][j4]+=dice[cnt1][j]*f[i][j1][j2][j3][j4]; else { if(node[i+1].wenhao){ for(ll q=0;q<=32;q++){ cal(i,j1,j2,j3,j4,opt2,opt*q,dice[cnt1][j]*dice[val2][q]); } } else { cal(i,j1,j2,j3,j4,opt2,opt*val2,dice[cnt1][j]); } } } } } } } } } double ans=0; for(ll j1=1;j1<=8;j1++){ for(ll j2=1;j2<=8;j2++){ for(ll j3=1;j3<=8;j3++){ for(ll j4=1;j4<=8;j4++){ if(f[a][j1][j2][j3][j4]){ // printf("f[%lld][%lld][%lld][%lld][%lld]=%lf ",a,j1,j2,j3,j4,f[a][j1][j2][j3][j4]); ans1[mit[8-j1+1]]+=f[a][j1][j2][j3][j4]; ans2[spd[8-j2+1]]+=f[a][j1][j2][j3][j4]; ans3[san[8-j3+1]]+=f[a][j1][j2][j3][j4]; ans4[kno[8-j4+1]]+=f[a][j1][j2][j3][j4]; } } } } } ans=0; for(ll i=1;i<=8;i++) ans+=ans1[i]; printf("%.2lf ",fabs(100-ans)); for(ll i=1;i<=8;i++) printf("%.2lf ",ans1[i]); puts(""); for(ll i=1;i<=8;i++) printf("%.2lf ",ans2[i]); puts(""); for(ll i=1;i<=8;i++) printf("%.2lf ",ans3[i]); puts(""); for(ll i=1;i<=8;i++) printf("%.2lf ",ans4[i]); puts(""); }