POJ1029枚举 ——3

POJ1029枚举

#include
#include 
using namespace std;
int main(){
	int N, K;
	cin >> N >> K;
	int weight[1001] = {0};
	int left[101] , right[101];
	memset(left, 0, sizeof(left));
	memset(right, 0, sizeof(right));
	char s[101] = {0};
	int num[101] = {0};
	int coins[101][2001] = {0};
	int flag = 0;
	int flag2 = 0;
	int flag3 = 0;
	int ans[1001] = {0};
	int ii = 0;
	
	for(int i = 0; i < K; i++){
		cin >> num[i];
		for(int j = 0; j < 2*num[i]; j++){
			cin >> coins[i][j];
			//left[i] += coins[j];
		}
		cin >> s[i];
	}
	//输入
	for(int i = 0; i < N; i++){
		weight[i+1] = 1;//假设此枚硬币为重
		for(int j = 0; j < K; j++){
			for(int k = 0; k < num[j]; k++){
				left[j] += weight[coins[j][k]]; 
	//左端重量
			}
			for(int l = num[j]; l < 2*num[j]; l++){
				right[j] += weight[coins[j][l]];
	//右端重量			
			}	
			if((s[j] == '=' && right[j] == left[j]) || (s[j] == '<' && left[j] < right[j]) || (s[j] == '>' && left[j] > right[j]))
				flag++;//若符合输入描述,标记
			memset(right, 0, sizeof(right));
			memset(left, 0, sizeof(left));
		}
		
		if(flag == K){	
			ans[ii] = i+1;
			ii++;
	//若全部符合 计入答案		
		}
		flag = 0;
		weight[i+1] = 0;
		
		
		weight[i+1] = -1;
		for(int j = 0; j < K; j++){
			for(int k = 0; k < num[j]; k++){
				left[j] += weight[coins[j][k]]; 
				
			}
			for(int l = num[j]; l < 2*num[j]; l++){
				right[j] += weight[coins[j][l]];
				
			}
			
			if((s[j] == '=' && right[j] == left[j]) || (s[j] == '<' && left[j] < right[j]) || (s[j] == '>' && left[j] > right[j]))
				flag++;
			memset(right, 0, sizeof(right));
			memset(left, 0, sizeof(left));
		}
		
		if(flag == K ){
			
			ans[ii] = i+1;
			ii++;	
		}
//由于审题疏忽刚开始忘记了硬币可以是轻的。。。。。。
		flag = 0;
		weight[i+1] = 0;
	}

	
	
	for(int i = 0; i < ii; i++){
		if(ans[i] != ans[0]){
			cout << '0' << endl;
			flag2 = 1;
			break;
		}
	}
	if(flag2 == 0)
		cout << ans[0] << endl;
//若答案中有不同值说明无法找出	
}

你可能感兴趣的:(POJ1029枚举 ——3)