浙江省省赛2016同步赛C题_Defuse the Bomb

题目链接点击打开链接

这道题是一个模拟题,按照题目的意思,进行操作变换,保证过程不出错即可!!我是用一个结构体来保存值和位置的!!!

#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <vector>
#include <cmath>
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
using namespace std;
const int maxn = 55555;
int sum[maxn << 2];
struct node
{
	int button, label;
}node1[10];
int main(void)
{
	//freopen("in.txt", "r", stdin);
	int T;

	scanf("%d", &T);
	while (T--)                                                        //枚举暴力每一种情况
	{
		int d, b[5];
		int ans_p, ans_v;
		int i, j;
		for (i = 1; i <= 5; i++)
		{
			scanf("%d", &d);
			for (j = 1; j <= 4; j++)
				scanf("%d", &b[j]);
			//scanf("%d%d%d%d%d",&d,&b1,&b2,&b3,&b4);
			if (i == 1)
			{
				if (d == 1)
				{
					node1[1].button = 2;
					node1[1].label = b[2];
					printf("%d %d\n", 2, b[2]);
				}
				else if (d == 2)
				{
					node1[1].button = 2;
					node1[1].label = b[2];
					printf("%d %d\n", 2, b[2]);
				}
				else if (d == 3)
				{
					node1[1].button = 3;                                //记录值和按钮位置
					node1[1].label = b[3];
					printf("%d %d\n", 3, b[3]);
				}
				else if (d == 4)
				{
					node1[1].button = 4;
					node1[1].label = b[4];
					printf("%d %d\n", 4, b[4]);
				}
			}
			else if (i == 2)                                                                        //每一种情况,我都考虑到
			{

				if (d == 1)
				{
					node1[2].label = 4;
					int w;
					for (w = 1; w <= 4; w++)
					{
						if (b[w] == 4)
							break;
					}
					node1[2].button = w;
					printf("%d %d\n", w, 4);
				}
				else if (d == 2)
				{
					
					node1[2].button = node1[1].button;
					node1[2].label = b[node1[1].button];
					printf("%d %d\n", node1[2].button, node1[2].label);
				}
				else if (d == 3)
				{
					node1[2].label = b[1];
					node1[2].button = 1;
					printf("%d %d\n", 1, b[1]);
				}
				else if (d == 4)
				{
					//node1[2].label = node1[1].label;
					node1[2].button = node1[1].button;
					node1[2].label = b[node1[2].button];
					printf("%d %d\n", node1[2].button, node1[2].label);
				}
			}
			else if (i == 3)
			{
				if (d == 1)
				{
					node1[3].label = node1[2].label;
					//node1[3].button = node1[2].button;
					int w;
					for (w = 1; w <= 4; w++)
					{
						if (b[w] == node1[3].label)
							break;
					}
					node1[3].button = w;
					printf("%d %d\n", node1[3].button, node1[3].label);
				}
				else if (d == 2)
				{
					node1[3].label = node1[1].label;
					int w;
					for (w = 1; w <= 4; w++)
					{
						if (b[w] == node1[3].label)
							break;
					}
					node1[3].button = w;
					printf("%d %d\n", node1[3].button, node1[3].label);
				}
				else if (d == 3)
				{
					node1[3].button = 3;
					node1[3].label = b[3];
					printf("%d %d\n", node1[3].button, node1[3].label);
				}
				else if (d == 4)
				{
					node1[3].label = 4;
					int w;
					for (w = 1; w <= 4; w++)
					{
						if (b[w] == 4)
							break;
					}
					node1[3].button = w;
					printf("%d %d\n", w, 4);
				}
			}
			else if (i == 4)
			{
				if (d == 1)
				{
					node1[4].button = node1[1].button;
					node1[4].label = b[node1[4].button];
				}
				else if (d == 2)
				{
					node1[4].button = 1;
					node1[4].label = b[1];
				}
				else if (d == 3)
				{
					node1[4].button = node1[2].button;
					node1[4].label = b[node1[4].button];
				}
				else if (d == 4)
				{
					node1[4].button = node1[2].button;
					node1[4].label = b[node1[4].button];
				}
				printf("%d %d\n", node1[4].button, node1[4].label);
			}
			else
			{
				if (d == 1)
				{
					//node1[5].button = node1[1].button;
					node1[5].label = node1[1].label;
					int w;
					for (w = 1; w <= 4; w++)
					{
						if (b[w] == node1[5].label)
							break;
					}
					node1[5].button = w;
				}
				else if (d == 2)
				{
					//node1[5].button = node1[2].button;
					node1[5].label = node1[2].label;
					int w;
					for (w = 1; w <= 4; w++)
					{
						if (b[w] == node1[5].label)
							break;
					}
					node1[5].button = w;
				}
				else if (d == 3)
				{
					//node1[5].button = node1[4].button;
					node1[5].label = node1[4].label;
					int w;
					for (w = 1; w <= 4; w++)
					{
						if (b[w] == node1[5].label)
							break;
					}
					node1[5].button = w;
				}
				else if (d == 4)
				{
					node1[5].label = node1[3].label;
					int w;
					for (w = 1; w <= 4; w++)
					{
						if (b[w] == node1[5].label)
							break;
					}
					node1[5].button = w;
				}
				printf("%d %d\n", node1[5].button, node1[5].label);
			}
		}
	}
	return 0;
}

你可能感兴趣的:(浙江省省赛2016同步赛C题_Defuse the Bomb)