uva 253

涂色立方体匹配问题, 关键就是利用对立面不变的原理

一开始用multimap来存储每一对对立面, 本来以为这样可以把c1和c2的各对对立面排好序直接按顺序匹配了, 结果改了好多次都是WA

后来发现map只按键值排序, 有可能遇到键值相同的, 顺序就不一定了, 

所以还是只能分别将一对对立面分别与另一个立方体的三个对立面去匹配, 直到找到对应的为止

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <cstring> 
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <list>
using namespace std;
const int MAXN = 20;
const int SIZE = 6;
typedef long long LL;


/*
uva 253 
关键 : 	1.原理: 无论怎么旋转, 各个面的对立面都是不变的 
		2.注意必须对于每一个对立面必须分别检查三次, 因为有三种放置的可能  
*/
char c1[MAXN]={0},c2[MAXN]={0};
bool checked[MAXN];

int check(int a,int b){
	for(int i=0; i<3; i++){
		if( !checked[i] && !checked[5-i] && c2[a]==c1[i] && c2[b]==c1[5-i] ){
			checked[i] = checked[5-i] = true;
			return 1;
		}
	}
	return 0;
}

int main(){
	while( ~scanf("%c%c%c%c%c%c%c%c%c%c%c%c",&c1[0],&c1[1],&c1[2],&c1[3],&c1[4],&c1[5],&c2[0],&c2[1],&c2[2],&c2[3],&c2[4],&c2[5]) ){
		getchar();
		memset(checked,0,sizeof(checked));
		char c1_a,c1_b,c2_a,c2_b;
		for(int i=0; i<3; i++){
			if( c1[i]>c1[5-i] ) swap(c1[i],c1[5-i]);
			if( c2[i]>c2[5-i] ) swap(c2[i],c2[5-i]);
		}
		int result = 0;
		for(int i=0; i<3; i++){
			result += checked(i,5-i);
		}
		if( result<3 ){
			cout << "FALSE" << endl; 
		}else{
			cout << "TRUE"  << endl;
		}
	}
	
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值