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

poj 上过了,同样的代码贴九度oj死活过不了。

Posted by zyzbdyldysl at 2014-05-20 21:38:55 on Problem 1029
#include<iostream>
#include<memory.h>
#include<vector>
#include<set>
using namespace std;
struct formula
{
	set <int> left;
	set <int> right;
	char op;
	int num;
};
int main()
{
	int n = 0, k = 0;
	while (cin >> n >> k)
	{
		int answer = 0;
		int coins[1001];
		memset(coins, 0, sizeof(coins));
		formula form[101];
		for (int i = 0; i < k; i++)
		{
			int nn = 0, temp;
			char op;
			cin >> nn;
			form[i].num = nn;
			for (int j = 0; j < 2 * nn; j++)
			{
				cin >> temp;
				if (j < nn)
				{
					form[i].left.insert(temp);
				}
				else
				{
					form[i].right.insert(temp);
				}
			}
			cin >> op;
			form[i].op = op;
		}
		for (int i = 0; i < k; i++)
		{
			if (form[i].op == '>')
			{
				for (int j = 1; j <= n; j++)
				{
					if (form[i].left.count(j) != 0 && coins[j] != 1)
					{
						if (coins[j] != 2)coins[j] = 3;
						else coins[j] = 4;
					}
					else if (form[i].right.count(j) != 0 && coins[j] != 1)
					{
						if (coins[j] != 3)coins[j] = 2;
						else coins[j] = 4;
					}
					else
					{
						coins[j] = 1;
					}
				}
			}
			else if (form[i].op == '<')
			{
				for (int j = 1; j <= n; j++)
				{
					if (form[i].left.count(j) != 0 && coins[j] != 1)
					{
						if (coins[j] != 3)coins[j] = 2;
						else coins[j] = 4;
					}
					else if (form[i].right.count(j) != 0 && coins[j] != 1)
					{
						if (coins[j] != 2)coins[j] = 3;
						else coins[j] = 4;
					}
					else
					{
						coins[j] = 1;
					}
				}
			}
			else
			{
				for (int j = 1; j <= n; j++)
				{
					if (form[i].left.count(j) != 0 || form[i].right.count(j) != 0)
					{
						coins[j] = 1;
					}
				}
			}
		}
		bool flag = true;
		for (int i = 1; flag && i <= n; i++)
		{
			if (coins[i] == 2 || coins[i] == 3 || coins[i] == 0)
			{
				if (answer == 0) answer = i;
				else flag = false;
			}
		}
		if (flag) cout << answer << endl;
		else if (answer == 0)
		{

		}
		else cout << "0" << endl;
	}
}

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