50分求调, 悬赏一关
查看原帖
50分求调, 悬赏一关
1130462
180700553dd楼主2024/8/16 10:01

见标题(代码在下面)

#include <iostream>
#include <cstring>
using namespace std;
const int N = 105;
int n;
struct cube{
	int fr/*前面一格最高骰子的编号, 后面同理*/, ba, on/*上面骰子的编号*/, un, le, ri;
	int h;//这个骰子的高度 
	int top, front;//骰子上面的数字和前面的 
}cubes[N];
int cnt = 0;//骰子的编号 
int head = 0;
int touzi[10][10][10] = {{{}, {3, 4, 5}, {5, 2, 4}, {2, 5, 3}, {4, 3, 2}, {}},
						  {{4, 3, 6}, {}, {1, 6, 4}, {6, 1, 3}, {}, {3, 4, 1}},
						  {{2, 5, 6}, {6, 1, 5}, {}, {}, {1, 6, 2}, {5, 2, 1}},
						  {{5, 2, 6}, {1, 6, 5}, {}, {}, {6, 1, 2}, {2, 5, 1}},
						  {{3, 4, 6}, {}, {6, 1, 4}, {1, 6, 3}, {}, {4, 3, 1}},
						  {{}, {4, 3, 5}, {2, 5, 4}, {5, 2, 3}, {3, 4, 2}, {}}

 };//顺序是l, r, b 
int insert(int id, int t, int f, int blow){
	int l, r, b;
	l = touzi[t - 1][f - 1][0], r = touzi[t - 1][f - 1][1], b = touzi[t - 1][f - 1][2];
	int h1 = cubes[cubes[blow].le].h, h2 = cubes[cubes[blow].ri].h, h3 = cubes[cubes[blow].fr].h, h4 = cubes[cubes[blow].ba].h;
	int h = cubes[blow].h;
	if(l == 6 && h1 < h){
		cubes[blow].le = insert(id, r, f, cubes[blow].le);
		cubes[cubes[blow].le].ri = blow;
		return blow;
	}
	else if(r == 6 && h2 < h){
		cubes[blow].ri = insert(id, l, f, cubes[blow].ri);
		cubes[cubes[blow].ri].le = blow;
		return blow;
	}else if(f == 6 && h3 < h){
		cubes[blow].fr = insert(id, b, t, cubes[blow].fr);
		cubes[cubes[blow].fr].ba = blow;
		return blow;
	}else if(b == 6 && h4 < h){
		cubes[blow].ba = insert(id, f, 7 - t, cubes[blow].ba);
		cubes[cubes[blow].ba].fr = blow;
		return blow;
	}else if(l == 5 && h1 < h){
		cubes[blow].le = insert(id, r, f, cubes[blow].le);
		cubes[cubes[blow].le].ri = blow;
		return blow;
	}
	else if(r == 5 && h2 < h){
		cubes[blow].ri = insert(id, l, f, cubes[blow].ri);
		cubes[cubes[blow].ri].le = blow;
		return blow;
	}else if(f == 5 && h3 < h){
		cubes[blow].fr = insert(id, b, t, cubes[blow].fr);
		cubes[cubes[blow].fr].ba = blow;
		return blow;
	}else if(b == 5 && h4 < h){
		cubes[blow].ba = insert(id, f, 7 - t, cubes[blow].ba);
		cubes[cubes[blow].ba].fr = blow;
		return blow;
	}else if(l == 4 && h1 < h){
		cubes[blow].le = insert(id, r, f, cubes[blow].le);
		cubes[cubes[blow].le].ri = blow;
		return blow;
	}
	else if(r == 4 && h2 < h){
		cubes[blow].ri = insert(id, l, f, cubes[blow].ri);
		cubes[cubes[blow].ri].le = blow;
		return blow;
	}else if(f == 4 && h3 < h){
		cubes[blow].fr = insert(id, b, t, cubes[blow].fr);
		cubes[cubes[blow].fr].ba = blow;
		return blow;
	}else if(b == 4 && h4 < h){
		cubes[blow].ba = insert(id, f, 7 - t, cubes[blow].ba);
		cubes[cubes[blow].ba].fr = blow;
		return blow;
	}else{//不能翻滚就结束 
		if(blow == head){
			head = id;
		}
		cubes[id].h = cubes[blow].h + 1;
		cubes[id].front = f;
		cubes[id].top = t;
		cubes[blow].on = id;
		cubes[id].le = cubes[blow].le;
		cubes[id].ri = cubes[blow].ri;
		cubes[id].fr = cubes[blow].fr;
		cubes[id].ba = cubes[blow].ba;
		return id; 
	}
}
int c[10];
int main(){
	while(cin >> n){
		memset(c, 0, sizeof(c));
		for(int i = 1;i <= cnt;i++){
			cubes[i].ba = cubes[i].fr = cubes[i].front = cubes[i].h
			= cubes[i].le = cubes[i].on = cubes[i].ri = cubes[i].top = cubes[i].un = 0;
		}
		cnt = 0;
		head = 0;
		for(int i = 1;i <= n;i++){
			int t, f;
			cin >> t >> f;
			insert(++cnt, t, f, head);
		}
		for(int i = 1;i <= cnt;i++){
			if(cubes[i].on == 0) c[cubes[i].top]++;
		}
		for(int i = 1;i <= 6;i++) cout << c[i] << ' ';
		cout << '\n';
	}
	return 0;
}
2024/8/16 10:01
加载中...