当前位置:网站首页>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;
}
边栏推荐
- 1131: genetic correlation
- Matlab calculates the factorial sum of the first n numbers (easy to understand)
- 这种零件该怎么编程加工?
- Shift operator (detailed)
- K high frequency elements before sorting
- CCF access control system (Full Score code + problem solving idea) 201412-1
- [buuctf] [actf2020 freshman competition]exec1
- 立式加工中心的数控加工对刀具使用基本要求
- Searching for single element in dichotomy
- How many questions can you answer for the interview of Mechanical Engineer?
猜你喜欢
[email protected][])"/>NoViableAltException([email protected][])

How to get palindrome number in MATLAB (using fliplr function)

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

【BUUCTF】 Have Fun

Shangpinhui knowledge points of large e-commerce projects

PS cutting height 1px, Y-axis tiling background image problem

How does hbuilder display in columns?

ES6 notes

CCF adjacent number pairs (Full Score code + problem solving ideas + skill summary) 201409-1
![[buuctf] [actf2020 freshman competition]exec1](/img/af/22051a5feb3c1f6d7201a483bde127.jpg)
[buuctf] [actf2020 freshman competition]exec1
随机推荐
Quick sort (C language)
左旋梯形螺纹的编程
Determine the number of digits of an integer in MATLAB (one line of code)
Detailed explanation of settimeout() and setinterval()
Three ways and differences of defining functions in JS
Clear the route cache in Vue
Component communication mode
Repair of incorrect deletion of win10 boot entry
jsPlumb. Deleteeveryconnection is not a function & jsplumb clear canvas jsplumb delete all nodes and all connections
2021-05-12
How to realize selective screen recording for EV screen recording
Greedy two-dimensional array sorting
[extensive reading of papers] sentimental analysis of online reviews with a hierarchical attention network
Using member variables and member functions of a class
1137: encrypted medical record
Why do high precision CNC machining centers have errors? You should pay attention to these four reasons!
Double pointer palindrome string
Is pioneer futures safe? What are the procedures for opening futures accounts? How to reduce the futures commission?
Shift operator (detailed)
Maximum area of islands searched