FOJ1174 Dice Stacking

来源:互联网 发布:网络销售新三板靠谱吗 编辑:程序博客网 时间:2024/06/05 17:23
Problem 1174 Dice Stacking

Accept: 69 Submit: 129
Time 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

152 3 1 6 5 43 1 2 4 6 55 6 4 1 3 21 3 6 2 4 54 1 6 5 2 3

Sample Output

29

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;}


0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 嘴皮里面长泡怎么办 嘴巴里经常长泡怎么办 嘴唇上长透明泡怎么办 嘴唇上长很多泡怎么办 嘴巴里长白色泡怎么办 做了漂唇起泡了怎么办 漂唇之后起泡了怎么办 漂唇后起了水泡怎么办 嘴唇起泡,弄破了怎么办 九个月的宝宝上火了怎么办 8岁儿童嘴唇起泡怎么办 宝宝嘴皮上火起泡了怎么办 上嘴唇起泡肿了怎么办 上嘴唇突然肿了怎么办? 醒来上嘴唇肿了怎么办 嘴巴突然肿了怎么办呢 下嘴唇肿起来了怎么办 上嘴唇肿了起泡怎么办 上火下嘴唇肿了怎么办 上火嘴唇都肿了怎么办 嘴唇起泡后肿了怎么办 嘴唇上有白点颗粒状怎么办 嘴唇缺了一块红怎么办 人得钩端螺旋体怎么办 脖子上有鸡皮肤怎么办 不结婚老了以后怎么办 丁克族老了怎么办知乎 2个月宝宝咳嗽怎么办 干活累的手疼怎么办 脸上长白色的癣怎么办 全身起红斑很痒怎么办 宝宝脖子红烂了怎么办 背上长红斑很痒怎么办 身上起风疙瘩很痒怎么办 身上起小包很痒怎么办 浑身起红包很痒怎么办 手太粗糙怎么办小窍门 小腿长疙瘩很痒怎么办 腿过敏起红疙瘩怎么办 肚子上起红疙瘩很痒怎么办 小蚂蚁咬了肿了怎么办