【POJ2912】【加权并查集】【食物链变形】【只有一个就是只有他能nobug】

Rochambeau
Time Limit: 5000MS Memory Limit: 65536K
Total Submissions: 2280 Accepted: 813

Description

N children are playing Rochambeau (scissors-rock-cloth) game with you. One of them is the judge. The rest children are divided into three groups (it is possible that some group is empty). You don’t know who is the judge, or how the children are grouped. Then the children start playing Rochambeau game for M rounds. Each round two children are arbitrarily selected to play Rochambeau for one once, and you will be told the outcome while not knowing which gesture the children presented. It is known that the children in the same group would present the same gesture (hence, two children in the same group always get draw when playing) and different groups for different gestures. The judge would present gesture randomly each time, hence no one knows what gesture the judge would present. Can you guess who is the judge after after the game ends? If you can, after how many rounds can you find out the judge at the earliest?

Input

Input contains multiple test cases. Each test case starts with two integers N and M (1 ≤ N ≤ 500, 0 ≤ M ≤ 2,000) in one line, which are the number of children and the number of rounds. Following are M lines, each line contains two integers in [0, N) separated by one symbol. The two integers are the IDs of the two children selected to play Rochambeau for this round. The symbol may be “=”, “>” or “<”, referring to a draw, that first child wins and that second child wins respectively.

Output

There is only one line for each test case. If the judge can be found, print the ID of the judge, and the least number of rounds after which the judge can be uniquely determined. If the judge can not be found, or the outcomes of the M rounds of game are inconsistent, print the corresponding message.

Sample Input

3 3
0<1
1<2
2<0
3 5
0<1
0>1
1<2
1>2
0<2
4 4
0<1
0>1
2<3
2>3
1 0

Sample Output

Can not determine
Player 1 can be determined to be the judge after 4 lines
Impossible
Player 0 can be determined to be the judge after 0 lines

Source

Baidu Star 2006 Preliminary 
Chen, Shixi (xreborner) living in http://fairyair.yeah.net/

[Submit]   [Go Back]   [Status]   [Discuss]




#include <iostream>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
using namespace std;
    
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define mp push_back

int n,m;
char ch;
struct Rnode
{
	int x,y,op;
}node[2010];

int F[510];
int val[510];
int Find(int x)
{
	if(F[x] == -1) return x;
	int t = Find(F[x]);
	val[x] = (val[x] + val[F[x]]) % 3;
	return F[x] = t;
}

void merge(int x,int y,int v)
{
	int fx = Find(x);
	int fy = Find(y);
	F[fy] = fx;
	val[fy] = (3-val[y] + val[x] + v) % 3;
}
int main()
{
    while(scanf("%d%d",&n,&m) != EOF)
	{
		if(n == 1)
		{
			printf("Player 0 can be determined to be the judge after 0 lines\n");
			continue;
		}	
		for(int i=0;i<m;i++)
		{
			int u,v;
			scanf("%d%c%d",&node[i].x,&ch,&node[i].y);
			if(ch == '=') node[i].op = 0;
			else if(ch == '<') node[i].op = 2;
			else node[i].op = 1;
		}
		int nobugs = 0;
		int time;
		int id;
		int maxn = 1;
		for(int i=0;i<n;i++)
		{
			if(nobugs >= 2) break;
			memset(F,-1,sizeof(F));
			memset(val,0,sizeof(val));
			bool ok = true;
			for(int j=0;j<m;j++)
			{
				Rnode cur = node[j];
				if(cur.x == i || cur.y == i) continue;
				if(Find(cur.x) == Find(cur.y))
				{
					int x = cur.x;
					int y = cur.y;
					if((val[x] + cur.op) % 3 == val[y]) 
					{

					}
					else
					{
					   ok = false;
					   maxn = max(maxn,j+1);
					   break;
					}

				}
				else
				{
					merge(cur.x,cur.y,cur.op);
				}
			}
			if(ok) 
			{
				nobugs ++;
				id = i;
			}
		}
		if(nobugs >= 2)
		{
			printf("Can not determine\n");
		}
		else if(nobugs == 1)
		{
			printf("Player %d can be determined to be the judge after %d lines\n",id,maxn);
		}
		else
		{
			printf("Impossible\n");
		}

	}
    return 0;
}






  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,这个问题属于技术问题。以下是一个简单的Python模拟登录POJ提交代码并抓取评测结果的代码示例: ```python import requests # 登录POJ,获取cookie def login(username, password): s = requests.Session() login_url = "http://poj.org/login" login_data = { "user_id1": username, "password1": password, "B1": "login", "url": "/" } s.post(login_url, data=login_data) return s # 提交代码 def submit_code(s, problem_id, language, source_code): submit_url = "http://poj.org/submit" submit_data = { "problem_id": problem_id, "language": language, "source": source_code } s.post(submit_url, data=submit_data) # 获取评测结果 def get_result(s, run_id): status_url = "http://poj.org/status" params = { "user_id": "", "result": "", "language": "", "top": run_id } r = s.get(status_url, params=params) table_start = r.text.find("<table cellpadding=0 cellspacing=0 border=0 width=100%>") table_end = r.text.find("</table>", table_start) table_html = r.text[table_start:table_end + 8] return table_html # 使用示例 username = "your_username" password = "your_password" problem_id = "1000" language = "G++" source_code = """ #include <iostream> using namespace std; int main() { int a, b; cin >> a >> b; cout << a + b << endl; return 0; } """ s = login(username, password) submit_code(s, problem_id, language, source_code) table_html = get_result(s, "12345678") # 替换成实际提交的run id print(table_html) ``` 其中,`login`函数模拟登录POJ并返回一个`Session`对象,`submit_code`函数提交代码,`get_result`函数获取评测结果。你可以根据实际需要修改代码中的`username`、`password`、`problem_id`、`language`和`source_code`等参数,并替换`get_result`函数中的`run_id`。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值