Time Limit:1s | Memory limit:32M |
Accepted Submit:27 | Total Submit:36 |
Chun-Soo is playing a dice stacking game. Six faces of a die are squares of the same size; each face of a die has a number from 1 to 6. But, they are not standard dice because the sum of the numbers in the opposite faces may not always be 7. Input The first line of the input contains a single integer t (1 <= t <= 11), the number of test cases, followed by the input data for each test case. The first line for each test case contains an integer n (1 <= n <= 10,000), the number of dice. In the next lines, each line contains six integers for a die, by the order A, B, C, D, E, F, as in the following figure. There is a single space between two numbers. The number of dice is less than or equal to 10,000. It is possible for two dice to be the same. Output There should be one line per test case which contains the maximum sum of the numbers in one side. Sample Input 1 5 2 3 1 6 5 4 3 1 2 4 6 5 5 6 4 1 3 2 1 3 6 2 4 5 4 1 6 5 2 3 Sample Output 29 Hint To get the maximum sum for the above input, you should pile up the dice as follows: Original: Iran 2004 |
模拟.....................一次AC,RP爆发的说
又是一个很好玩的题目
- #include <stdio.h>
- typedef struct dice
- {
- int num[6];
- }Dice[10000];
- int max_num(dice *d,int i,int index)
- {int mn=0;
- if(index==0||index==5)
- {
- if(d[i].num[1]>mn) mn=d[i].num[1];
- if(d[i].num[2]>mn) mn=d[i].num[2];
- if(d[i].num[3]>mn) mn=d[i].num[3];
- if(d[i].num[4]>mn) mn=d[i].num[4];
- return mn;
- }
- if(index==1||index==3)
- {
- if(d[i].num[0]>mn) mn=d[i].num[0];
- if(d[i].num[2]>mn) mn=d[i].num[2];
- if(d[i].num[5]>mn) mn=d[i].num[5];
- if(d[i].num[4]>mn) mn=d[i].num[4];
- return mn;
- }
- if(index==2||index==4)
- {
- if(d[i].num[1]>mn) mn=d[i].num[1];
- if(d[i].num[0]>mn) mn=d[i].num[0];
- if(d[i].num[3]>mn) mn=d[i].num[3];
- if(d[i].num[5]>mn) mn=d[i].num[5];
- return mn;
- }
- }
- int find_fit_index(dice *d,int i,int val)
- {
- int j;
- for(j=0;j<6;j++)
- if(d[i].num[j]==val) return j;
- }
- int val_next(dice *d,int i,int num_index)
- {
- if(num_index==0) return d[i].num[5];
- if(num_index==5) return d[i].num[0];
- if(num_index==1) return d[i].num[3];
- if(num_index==3) return d[i].num[1];
- if(num_index==2) return d[i].num[4];
- if(num_index==4) return d[i].num[2];
- }
- int main()
- {
- Dice D;
- int n,t,i,msum,sum,j,val;
- scanf("%d",&t);
- while(t--)
- {
- scanf("%d",&n);
- msum=0;
- for(i=0;i<n;i++)
- scanf("%d%d%d%d%d%d",&D[i].num[0],&D[i].num[1],&D[i].num[2],&D[i].num[3],&D[i].num[4],&D[i].num[5]);
- for(i=0;i<6;i++)
- {
- sum=max_num(D,0,i);
- val=D[0].num[i];
- for(j=1;j<n;j++)
- {
- sum+=max_num(D,j,find_fit_index(D,j,val));
- val=val_next(D,j,find_fit_index(D,j,val));
- }
- msum=msum>sum?msum:sum;
- }
- printf("%d/n",msum);
- }
- return 0;
- }