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-05-27 19:01:28 on Problem 1029
//============================================================================
// Name        : main1029.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;

class weight{
public:
	int num;
	int* left;
	int* right;
	int bal;//-1: zuo<you 0: zuo==you 1: zuo>you
	void gx();
	/*
	~weight(){
		delete [] left;
		delete [] right;
	}
	*/
};

int B(char c){
	if(c == '=') return 0;
	if(c == '<') return -1;
	if(c == '>') return 1;
	return 0;
}


int state[1000] = {0};//零表示有可能为假币。
int Num, wnum;

void weight::gx(){
	switch(bal){
	 case 0:
		 for(int i = 0; i < num; i++){
			 state[left[i]-1] = 1;
			 state[right[i]-1] = 1;
		 }
		 break;
	 case -1:
	 case 1:
		 int* temp = new int[Num];
		 for(int i = 0; i < Num; i++)temp[i] = 0;
		 for(int i = 0; i < num; i++){
			 temp[left[i]-1] = 1;
			 temp[right[i]-1] = 1;
		 }
		 for(int i = 0; i < Num; i++){
			 if(temp[i] == 0) state[i] = 1;
		 }
		 delete [] temp;
	}
}

int main() {
	weight ws[100];
	cin >> Num >> wnum;
	for(int i = 0; i < wnum; i++){
		cin >> ws[i].num;
		ws[i].left = new int[ws[i].num];
		ws[i].right = new int[ws[i].num];
		for(int j = 0; j < ws[i].num; j++){
			cin >> ws[i].left[j];
		}
		for(int j = 0; j < ws[i].num; j++){
			cin >> ws[i].right[j];
		}
		char c;
		cin >> c;
		ws[i].bal = B(c);
		ws[i].gx();
	}

	int jia = -1;
	bool only = true;
	for(int i = 0; i < Num; i++){
		if(state[i] != 0) continue;
		int bl = 0;
		int j;
		for(j = 0; j < wnum; j++){
			if(ws[j].bal == 0) continue;
			bool inL = false, inR = false;
			for(int k = 0; k < ws[j].num; k++){
				if(i == ws[j].left[k] - 1){
					inL = true;
					break;
				}
				if(i == ws[j].right[k] - 1){
					inR = true;
					break;
				}
			}
			int tempBl;
			if(inL) tempBl = ws[j].bal;
			if(inR) tempBl = -ws[j].bal;
			if(bl != 0 && tempBl != bl) break;
			bl = tempBl;
		}
		if(j != wnum) continue;
		int tempJia = i;
		if(jia != -1 && tempJia != jia){
			only = false;
			break;
		}
		jia = tempJia;
	}

	if(!only || jia == -1){
		cout << 0 << endl;
	}
	else{
		cout << (jia+1) << endl;
	}

	//cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
	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