当前位置:网站首页>K - rochambau (joint search, enumeration)
K - rochambau (joint search, enumeration)
2022-06-30 15:00:00 【Rabbit doesn't like radish】
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
The question :
Learn from the boss blog
#include <cstdio>
#include <cmath>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <stack>
using namespace std;
using namespace std;
const int maxn=100006;
int pre[10005],rank[10005];
int n,m;
struct node{
int v,u,op;
}a[22222];
int find(int x)
{
if(pre[x]==x)
return x;
int t=pre[x];
pre[x]=find(t);
rank[x]=(rank[x]+rank[t])%3;
return pre[x];
}
void unit()
{
for(int i=0;i<=n;i++)
{
pre[i]=i;
rank[i]=0;// I am the same as myself
}
}
bool judge(int v,int u,int op)
{
int fx=find(v);
int fy=find(u);
if(fx==fy)
{
return ((rank[v]-op+3)%3!=rank[u]);
}
else
{
pre[fx]=fy;
rank[fx]=(rank[u]+op-rank[v]+3)%3;
return 0;
}
}
int main()
{
while(cin>>n>>m)
{
char c;
for(int i=1;i<=m;i++)// from 1 Start , There are no rows 0
{
cin>>a[i].v>>c>>a[i].u;
if(c=='=')
a[i].op=0;
if(c=='>')
a[i].op=2;
if(c=='<')
a[i].op=1;
}
int line=0;// Determine the subscript of the referee
int num=0;// Number of referees found
int temp;// The referee's subscript
for(int i=0;i<n;i++)
{
unit();
int flag=1;
for(int j=1;j<=m;j++)
{
int v=a[j].v,u=a[j].u,op=a[j].op;
if(a[j].v==i||a[j].u==i)// enumeration , Suppose the referee
continue;
if(judge(v,u,op))// There are contradictions , That is, the assumption is not true ,i Not the referee .
{
flag=0;
line=max(line,j);
break;
}
}
if(flag)// Suppose it is true .i It's the referee
{
temp=i;
num++;
}
}
if(num==0)// No referee
{
cout<<"Impossible"<<endl;
}
else if(num>1)// There are multiple referees
cout<<"Can not determine"<<endl;
else
cout<<"Player "<<temp<<" can be determined to be the judge after "<<line<<" lines"<<endl;
}
return 0;
}
边栏推荐
- An error is reported when installing dataspherestudio doc: invalid default value for 'update_ time‘
- V3 02——What‘s new in Chrome extensions
- Computer screenshot how to cut the mouse in
- DefCamp Capture the Flag (D-CTF) 2021-22 web
- Win10 one click Reset win10 to solve all system bugs without deleting any files and Applications
- CCF access control system (Full Score code + problem solving idea) 201412-1
- Is pioneer futures safe? What are the procedures for opening futures accounts? How to reduce the futures commission?
- Matlab two-dimensional array example (extract data)
- Text matching - [naacl 2022] GPL
- Implement a long-click list pop-up box on apiccloud
猜你喜欢

PS dynamic drawing

【BUUCTF】 Have Fun

CCF adjacent number pairs (Full Score code + problem solving ideas + skill summary) 201409-1

Determine the number of digits of an integer in MATLAB (one line of code)
![[buuctf] [actf2020 freshman competition]exec1](/img/af/22051a5feb3c1f6d7201a483bde127.jpg)
[buuctf] [actf2020 freshman competition]exec1

Win10 one click Reset win10 to solve all system bugs without deleting any files and Applications

Matlab judge palindrome number (only numbers)

After the MySQL service on the local computer is started and stopped, some services will automatically stop when they are not used by other services or programs

Shangpinhui knowledge points of large e-commerce projects

V3 03_ Getting started
随机推荐
1107 social clusters (30 points)
1019 general palindromic number (20 points)
The kth largest element in the sorted array
Sorting by character frequency
2021-07-14 mybaitsplus
CCF command line options (Full Score code + problem solving ideas + skill summary) March 3, 2014
Double pointer circular linked list
Average and maximum values of MATLAB matrix
1031 Hello world for u (20 points)
V3 01_ Welcome
CCF elimination games (Full Score code + problem solving ideas + skill summary) February 2, 2015
先锋期货安全么?现在期货开户都是哪些流程?期货手续费怎么降低?
中信期货开户麻烦吗安全吗,期货开户手续费是多少,能优惠吗
2021-08-05 leetcode notes
Machine learning feature selection
Matlab construction operation example
Location of dichotomy
立式加工中心调试的步骤
1025 pat ranking (25 points)
1151 LCA in a binary tree (30 points)