Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

打的累死人

Posted by KatrineYang at 2016-08-27 11:44:09 on Problem 1290
#include <iostream>
#include <stdio.h>
#include <vector>
using namespace std;

char cube[7][3][3];
vector<int> moves;

void init(){
	moves.clear();
	for(int i = 0; i < 3; i++)
		for(int j = 0; j < 3; j++)
			cin >> cube[5][i][j];
	for(int i = 0; i < 3; i++)
		for(int j = 1; j < 5; j++)
			for(int k = 0; k < 3; k++)
				cin >> cube[j][i][k];
	for(int i = 0; i < 3; i++)
		for(int j = 0; j < 3; j++)
			cin >> cube[6][i][j];
	while(1){
		int move;
		cin >> move;
		if(move == 0) break;
		moves.push_back(move);
	}
}

void swap(char &c1, char &c2, char &c3, char &c4){
	char temp = c1;
	c1 = c4;
	c4 = c3;
	c3 = c2;
	c2 = temp;
}

void Move(int move){
	if(move == 1){
		swap(cube[1][0][0], cube[1][0][2], cube[1][2][2], cube[1][2][0]);
		swap(cube[1][0][1], cube[1][1][2], cube[1][2][1], cube[1][1][0]);
		swap(cube[5][0][0], cube[2][0][0], cube[6][0][0], cube[4][2][2]);
		swap(cube[5][1][0], cube[2][1][0], cube[6][1][0], cube[4][1][2]);
		swap(cube[5][2][0], cube[2][2][0], cube[6][2][0], cube[4][0][2]);
	}
	else if(move == 2){
		swap(cube[2][0][0], cube[2][0][2], cube[2][2][2], cube[2][2][0]);
		swap(cube[2][0][1], cube[2][1][2], cube[2][2][1], cube[2][1][0]);
		swap(cube[1][0][2], cube[5][2][2], cube[3][2][0], cube[6][0][0]);
		swap(cube[1][1][2], cube[5][2][1], cube[3][1][0], cube[6][0][1]);
		swap(cube[1][2][2], cube[5][2][0], cube[3][0][0], cube[6][0][2]);
	}
	else if(move == 3){
		swap(cube[3][0][0], cube[3][0][2], cube[3][2][2], cube[3][2][0]);
		swap(cube[3][0][1], cube[3][1][2], cube[3][2][1], cube[3][1][0]);
		swap(cube[2][2][2], cube[5][2][2], cube[4][0][0], cube[6][2][2]);
		swap(cube[2][1][2], cube[5][1][2], cube[4][1][0], cube[6][1][2]);
		swap(cube[2][0][2], cube[5][0][2], cube[4][2][0], cube[6][0][2]);
	}
	else if(move == 4){
		swap(cube[4][0][0], cube[4][0][2], cube[4][2][2], cube[4][2][0]);
		swap(cube[4][0][1], cube[4][1][2], cube[4][2][1], cube[4][1][0]);
		swap(cube[3][2][2], cube[5][0][2], cube[1][0][0], cube[6][2][0]);
		swap(cube[3][1][2], cube[5][0][1], cube[1][1][0], cube[6][2][1]);
		swap(cube[3][0][2], cube[5][0][0], cube[1][2][0], cube[6][2][2]);
	}
	else if(move == 5){
		swap(cube[5][0][0], cube[5][0][2], cube[5][2][2], cube[5][2][0]);
		swap(cube[5][0][1], cube[5][1][2], cube[5][2][1], cube[5][1][0]);
		swap(cube[1][0][0], cube[4][0][0], cube[3][0][0], cube[2][0][0]);
		swap(cube[1][0][1], cube[4][0][1], cube[3][0][1], cube[2][0][1]);
		swap(cube[1][0][2], cube[4][0][2], cube[3][0][2], cube[2][0][2]);
	}
	else if(move == 6){
		swap(cube[6][0][0], cube[6][0][2], cube[6][2][2], cube[6][2][0]);
		swap(cube[6][0][1], cube[6][1][2], cube[6][2][1], cube[6][1][0]);
		swap(cube[1][2][0], cube[2][2][0], cube[3][2][0], cube[4][2][0]);
		swap(cube[1][2][1], cube[2][2][1], cube[3][2][1], cube[4][2][1]);
		swap(cube[1][2][2], cube[2][2][2], cube[3][2][2], cube[4][2][2]);
	}
	else{
		for(int i = 0; i < 3; i++) Move(-move);
	}
}

int main() {
	int cases;
	cin >> cases;
	for(int ii = 0; ii < cases; ii++){
		init();
		int sz = moves.size();
		for(int i = 0; i < sz; i++){
			Move(moves[i]);
		}
		bool win = 1;
		for(int i = 1; i < 7; i++){
			char coal = cube[i][0][0];
			for(int j = 0; j < 3; j++){
				for(int k = 0; k < 3; k++){
					if(cube[i][j][k] != coal){
						win = 0;
						goto done;
					}
				}
			}
		}
		done:
		if(win) printf("Yes, grandpa!\n");
		else printf("No, you are wrong!\n");
	}
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator