FOJ1174 Dice Stacking
来源:互联网 发布:网络销售新三板靠谱吗 编辑:程序博客网 时间:2024/06/05 17:23
Accept: 69 Submit: 129Time Limit: 1000 mSec Memory Limit : 32768 KB
Problem Description
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.
The dice game is to stack several dice up in the order Die 1, Die 2, Die 3, from the base keeping the following rule: For each pair of consecutive dice, the number on the bottom of the top die must match the number on the top of the bottom die. In other words, the two faces that are together must have the same number. We are free to place the bottom die as we wish, so Die 1 can be set freely.
A long rectangular pillar which has 4 sides is created. We are trying to make one side have the maximum sum. (Note that after we rotate a die to fix the top face and bottom face, we can still rotate the die by 90, 180, or 270 degrees.) Write a program to find the maximum sum that one side can have.
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
Sample Output
Source
Iran 2004#include<stdio.h>#include<string.h>#include<math.h>#include<iostream>#include<algorithm>using namespace std;const int N=10010;int h[N][6],id[N][7],a[7]={5,3,4,1,2,0},judge[7];int main(){ int t,n,i,j,k; scanf("%d",&t); while(t--){ scanf("%d",&n); for(i=1;i<=n;i++){ for(j=0;j<6;j++){ scanf("%d",&h[i][j]); id[i][h[i][j]]=j; } } int ans=0; for(i=0;i<6;i++){ memset(judge,0,sizeof(judge)); int num=0; int tnum1=h[1][i]; int tnum2=h[1][a[i]]; judge[tnum1]=1; judge[tnum2]=1; for(j=6;j>0;j--){ if(!judge[j]){ num+=j; break; } } for(j=2;j<=n;j++){ int tid=id[j][tnum2]; tnum1=tnum2; tnum2=h[j][a[tid]]; memset(judge,0,sizeof(judge)); judge[tnum1]=1; judge[tnum2]=1; for(k=6;k>0;k--){ if(!judge[k]){ num+=k;break; } } } if(num>ans)ans=num; } printf("%d\n",ans); } return 0;}
- FOJ1174 Dice Stacking
- FOJ 1174 Dice Stacking
- pku1972 Dice Stacking
- POJ 1972 Dice Stacking 笔记
- Dice
- Stacking
- sicily1128.DICE
- 1128. DICE
- Dice Throwing
- poj4014 Dice
- Dice (bfs)
- HDU5012 Dice
- hdu5012 Dice
- Dice Possibility
- pku_1128_Frame Stacking
- Cube Stacking
- Stacking Boxes
- Cube Stacking
- 关于android3.0以后引入fragment碎片的小问题
- 增加网站名次的3个办法第一
- 求出现重现次数最多的字母,如有多个重复的则都求出来
- hdu 1002 Java 大数 加法
- (3) 服务器更新为Debian系统
- FOJ1174 Dice Stacking
- Lua中对于UTF-8字符串的处理
- 我这傻逼的一天 ------腾讯面试
- Ubuntu下在Eclipse IDE for C/C++ Developers中如何运行C语言的GTK程序?(已解决)
- 如何提高意志力&如何坚持每天学习
- 【JAVA环境】CentOS6下安装Java jdk1.7.0_10
- HUD 5056 Boring count
- c++
- ClickOnce部署