当前位置:网站首页>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;
}
边栏推荐
- JS array sorting method summary
- Maximum area of islands searched
- 1025 pat ranking (25 points)
- Basic requirements for tool use in NC machining of vertical machining center
- How to realize selective screen recording for EV screen recording
- Detailed explanation of settimeout() and setinterval()
- 这种零件该怎么编程加工?
- Determine the number of digits of an integer in MATLAB (one line of code)
- [buuctf] [actf2020 freshman competition]include
- [untitled]
猜你喜欢
![[buuctf] [geek challenge 2019] secret file](/img/00/23bebd013eb4035555c0057725e3c4.jpg)
[buuctf] [geek challenge 2019] secret file

Not satisfied with markdown native code block style? Try this beautify code screenshot tool~~

Shangpinhui knowledge points of large e-commerce projects

1 figure to explain the difference and connection between nodejs and JS

PS tip: the video frame to Layer command cannot be completed because dynamiclink is not available

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

CCF Z-scan (full mark code + problem solving ideas) 201412-2

Learn about data kinship JSON format design from sqlflow JSON format

PS dynamic drawing

How to use Alibaba Vector Icon
随机推荐
CCF command line options (Full Score code + problem solving ideas + skill summary) March 3, 2014
How to realize selective screen recording for EV screen recording
Matlab to find prime pairs within 100
Determine the number of digits of an integer in MATLAB (one line of code)
ES6 notes
CCF Z-scan (full mark code + problem solving ideas) 201412-2
The difference between queue and stack
[buuctf] [actf2020 freshman competition]exec1
分布式--OpenResty+lua+Redis
Solve the problem that codeblocks20.03 on win11 cannot run for the first time
Binary rotation array (2)
Working principle and fault treatment of cutting cylinder in CNC machining center
[extensive reading of papers] a delicious recipe analysis framework for exploring multi modal recipes with variable attributes
Maximum area of islands searched
V3 02——What‘s new in Chrome extensions
1151 LCA in a binary tree (30 points)
Greedy two-dimensional array sorting
Repair of incorrect deletion of win10 boot entry
August 24, 2021 deque queue and stack
Finding the root of an integer by dichotomy