【FOJ】Problem 1174 Dice Stacking

Problem 1174 Dice Stacking.

题意

  • die - 模具
    dice - 骰子
  • 垒骰子,相贴的两面数值相等
  • 输入:
    测试数据组数 t (1 <= t <= 11)
    骰子数量n (1 <= n <= 10,000),n个骰子对应的面值
  • 输出:
    数字最大的那一面的数字和

思路

  • 对每个骰子,底面固定后顶面也固定,只要取他们侧面的最大面值累加即可
  • 第一个骰子的底面有6种可能,对每个底面求出该情况下的最大侧面值
  • 结果取这6个最大值中值最大的那个

代码

#include<cstdio>
using namespace std;

int dice[10000][10];
int t, n;

int op(int x){
	switch(x){
		case 0:	return 5;
		case 1: return 3;
		case 2: return 4;
		case 3: return 1;
		case 4: return 2;
		case 5: return 0;
	}
}

int maxside(int arr[], int bottom, int top){
	int max = 0;
	for(int i=0; i<6; i++){
		if(i!=bottom && i!=top)
			if(arr[i]>max)
				max = arr[i];
	}
	return max;
}

int find(int arr[], int x){
	for(int i=0; i<6; i++){
		if(arr[i]==x)
			return i;
	}
}

int main(){
	int sum, maximum, bottom, top;
	scanf("%d", &t);
	while(t--){
		maximum = 0;
		scanf("%d", &n);
		for(int i=0; i<n; i++)
			for(int j=0; j<6; j++)
				scanf("%d", &dice[i][j]);
		for(int i=0; i<6; i++){
			sum = 0;
			bottom = i;
			for(int j=0; j<n; j++){
				top = op(bottom);
				sum += maxside(dice[j], bottom, top);
				if(j<n-1)
					bottom = find(dice[j+1], dice[j][top]);
			}
			if(sum>maximum)
				maximum = sum;
		}
		printf("%d\n", maximum);
	}
	return 0;
}
发布了28 篇原创文章 · 获赞 0 · 访问量 315

猜你喜欢

转载自blog.csdn.net/qq_44531167/article/details/105334324