is to change a string into a three-way pressure, then divided into the first 5 bits, the last 5-bit statistics,
Then direct statistics F[i][j][k] represents, after 5 innings pressure for K, the first 5 innings than and J-state than lost 5 innings how many people
Complexity is O (t*30000*25*m) m relatively small, also up to dozens of, will be over
#include <cstdio>#include<cstring>#include<algorithm>#include<iostream>#include<cstdlib>#include<vector>#include<cmath>#include<queue>#include<map>#include<string>using namespaceStd;typedefLong LongLL;Const intn=3e4+5;Const intm=243;Const intinf=0x3f3f3f3f;int Get(intXinty) { intret=0; for(intk=0;k<5;++k) { intdig0=x%3, dig1=y%3; if(dig0== (dig1+1)%3)++ret; X/=3, y/=3; } returnret;} Vector<int> win[6][m],lose[6][m];intt,cas,n,a[n][ One],ret[n][ One],f[6][m][m];Charch[ the];intMain () { for(intI=0; i<m;++i) { for(intj=0; j<m;++j) {win[Get(I,J)] [I].push_back (j); lose[Get(I,J)] [J].push_back (i); }} scanf ("%d",&T); while(t--) {scanf ("%d",&N); for(intI=0; i<n;++i) {scanf ("%s", CH); for(intj=0;j<Ten;++j) {if(ch[j]=='R') a[i][j]=0; Else if(ch[j]=='P') a[i][j]=1; Elsea[i][j]=2; }} memset (F,0,sizeof(f)); memset (ret,0,sizeof(ret)); for(intI=0; i<n;++i) {intmask0=0, mask1=0; for(intj=0;j<5; ++j) mask0=mask0*3+A[i][j]; for(intj=5;j<Ten; ++j) mask1=mask1*3+A[i][j]; for(intj=0; j<=5;++j) { for(intk=0; K<lose[j][mask0].size (); + +k) {intt=Lose[j][mask0][k]; ++F[j][t][mask1]; } } } for(intI=0; i<n;++i) { intmask0=0, mask1=0; for(intj=0;j<5; ++j) mask0=mask0*3+A[i][j]; for(intj=5;j<Ten; ++j) mask1=mask1*3+A[i][j]; for(ints0=0; s0<=5;++S0) for(ints1=0; s1<=5;++S1) { for(intk=0; K<win[s1][mask1].size (); + +k) { intt=Win[s1][mask1][k]; Ret[i][s0+s1]+=F[s0][mask0][t]; } } --ret[i][0]; } printf ("Case #%d:\n",++CAs); for(intI=0; i<n;++i) { for(intj=0;j<Ten;++j) printf ("%d", Ret[i][j]); printf ("%d\n", ret[i][Ten]); } } return 0;}
View Code
Sdut 3568 Rock Paper Scissors-like pressure statistics