#include #include char strs[5][11]; int coins[5]; #define INDEX(A,B,C) ((A)*5*5+(B)*5+(C)) int combiA[125]; //5^3 000,001,...,444 int combiB[125]; int combiC[125]; char picA[5000]; char picB[5000]; char picC[5000]; void count_update(int a, int b, int c, int count[]){ int a0 = a/25, b0 = b/25, c0 = c/25; int a1 = (a%25)/5, b1 = (b%25)/5, c1 = (c%25)/5; int a2 = a%5, b2 = b%5, c2 = c%5; int plus = combiA[INDEX(a0,a1,a2)] * combiB[INDEX(b0,b1,b2)] * combiC[INDEX(c0,c1,c2)]; if(a0==b0 && b0==c0) count[a0]+=plus; if(a1==b1 && b1==c1) count[a1]+=plus; if(a2==b2 && b2==c2) count[a2]+=plus; if(a0==b1 && b1==c2) count[a0]+=plus; if(a2==b1 && b1==c0) count[a2]+=plus; } int numA, numB, numC; int main(){ for(int i = 0; i < 5; i++){ scanf("%s %d", strs[i], coins+i); } char tmp[11]; int * numX; char * picX; for(int x = 0; x < 3 ; x++){ if(x == 0){ numX = &numA; picX = picA; }else if(x == 1){ numX = &numB; picX = picB; }else /* x == 2 */{ numX = &numC; picX = picC; } scanf("%d",numX); for(int i = 0; i < *numX; i++){ scanf("%s", tmp); for(int j = 0; j < 5; j++){ if(strcmp(tmp,strs[j]) == 0){ picX[i] = j; break; } } } } /* for(int i = 0; i < numA; i++) printf("%d,", picA[i]); puts(""); for(int i = 0; i < numB; i++) printf("%d,", picB[i]); puts(""); for(int i = 0; i < numC; i++) printf("%d,", picC[i]); puts(""); for(int i = 0; i < 125; i++){combiA[i] = 0;} for(int i = 0; i < 125; i++){combiB[i] = 0;} for(int i = 0; i < 125; i++){combiC[i] = 0;} */ for(int i = 0; i <= numA-3 ; i++){ combiA[INDEX(picA[i],picA[i+1],picA[i+2])]++; //printf("(%d,%d,%d),%d\n",picA[i],picA[i+1],picA[i+2],INDEX(picA[i],picA[i+1],picA[i+2])); } combiA[INDEX(picA[numA-2],picA[numA-1],picA[0])]++; combiA[INDEX(picA[numA-1],picA[0],picA[1])]++; for(int i = 0; i <= numB-3 ; i++){ combiB[INDEX(picB[i],picB[i+1],picB[i+2])]++; } combiB[INDEX(picB[numB-2],picB[numB-1],picB[0])]++; combiB[INDEX(picB[numB-1],picB[0],picB[1])]++; for(int i = 0; i <= numC-3 ; i++){ combiC[INDEX(picC[i],picC[i+1],picC[i+2])]++; } combiC[INDEX(picC[numC-2],picC[numC-1],picC[0])]++; combiC[INDEX(picC[numC-1],picC[0],picC[1])]++; /* puts("combiA"); for(int i = 0; i < 125; i++){ printf("%d,",combiA[i]); if(i%10==9)puts(""); } puts("combiB"); for(int i = 0; i < 125; i++){ printf("%d,",combiB[i]); if(i%10==9)puts(""); } puts("combiC"); for(int i = 0; i < 125; i++){ printf("%d,",combiC[i]); if(i%10==9)puts(""); }*/ //それぞれの出目での儲けの和/全ての通り数 long total; long mouke; int count[5]; for(int a = 0; a < 125; a++){ for(int b = 0; b < 125; b++){ for(int c = 0; c < 125; c++){ //total += combiA[a]*combiB[b]*combiC[c]; for(int i = 0; i < 5; i++) count[i] = 0; count_update(a,b,c,count); for(int i = 0; i < 5; i++) mouke += count[i]*coins[i]; } } } printf("%.12f\n", (double)mouke/(numA*numB*numC)); for(int i = 0; i < 5; i++) count[i] = 0; //全部のリールの止まり方を試す for(int a = 0; a < 125; a++){ for(int b = 0; b < 125; b++){ for(int c = 0; c < 125; c++){ count_update(a,b,c,count); } } } for(int i = 0; i < 5; i++) printf("%d\n",count[i]); }