当前位置:网站首页>(POJ - 2912) rochambau (weighted concurrent search + enumeration)
(POJ - 2912) rochambau (weighted concurrent search + enumeration)
2022-07-03 22:03:00 【AC__ dream】
Topic link :2912 -- Rochambeau
The question :n There is a play for a little partner to guess fists , Except for a clever guy , Others will only produce a single kind , give m The result of guessing boxing , Ask to find out the serial number of the clever little partner , And the output in the first few guesses can be determined .( Be careful <,>,= There may be spaces before and after )
analysis : Everyone can only have three choices , So this problem is more similar to that of the food chain , If you don't know about weighted search set, you can look at that question first , Attach the blog address here :POJ - 1182 The food chain ( Take the right and check the collection )_AC__dream The blog of -CSDN Blog a
First of all, it is certain that except for the smart little partner who may have conflicts with others , There will be no contradiction between others ( Because others can only make a single gesture , This information is crucial ), So we can enumerate smart friends , Remove the result of guessing about a little partner every time , If there are still contradictions, the little partner can't be the smart one , On the contrary, the partner may be a smart partner , After enumerating all the partners in this way , If the number of smart partners is 0, It shows that removing any small partner cannot eliminate the contradiction , Then there are at least two smart friends ( Pay attention to distinguish this sentence from “ One of these two may be a smart partner ”). If the number of smart partners may be greater than 1, It means that smart partners are random , Whoever it is . In addition to the above two cases , The rest is that smart friends are the only , Then how should we determine which sentence is judged ?
Because I said before , The result of a contradictory fist guessing must include smart partners , It may be assumed that the order of contradiction with smart partners is a1,a2,……, So when we judge that a smart partner and a2 When there is a contradiction between them, the number of sentences can be judged , In the initial enumeration process, remove a2, Then the contradiction must be with a1( Because the enumeration process is to remove a small partner , When there are contradictions, it can be judged that what is currently removed is not a smart little partner , Directly break), Otherwise, the contradiction must be with a2, So we only need to record the maximum value of each contradictory statement , In this way, we can get the position of the statement
Here is the code :
#include<cstdio>
#include<iostream>
#include<cstring>
#include<vector>
#include<algorithm>
#include<map>
#include<cmath>
#include<queue>
using namespace std;
const int N=3e3+10;
int fu[N],d[N],n,m;
int a[N],b[N];
char op[N];
void init()
{
for(int i=1;i<=n;i++)
fu[i]=i,d[i]=0;
}
int find(int x)
{
int t=fu[x];
if(x!=fu[x]) fu[x]=find(fu[x]);
d[x]=(d[t]+d[x])%3;
return fu[x];
}
void merge(int x,int y,int z)
{
int f1=find(x),f2=find(y);
fu[f2]=f1;
d[f2]=(d[x]+z-d[y]+6)%3;
}
int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
for(int i=1;i<=m;i++)
{
scanf("%d%c%d",&a[i],&op[i],&b[i]);
a[i]++;b[i]++;// Label from 1 Start
}
int ans=0;// Record the possible number of referees
int pos;// Record possible referees
int p=0;// Record where contradictions are found
for(int i=1;i<=n;i++)
{
init();
bool flag=true;// When the contradiction turns into false
for(int j=1;j<=m;j++)
{
if(a[j]==i||b[j]==i) continue;
if(op[j]=='<')
{
int f1=find(a[j]),f2=find(b[j]);
if(f1!=f2)
merge(a[j],b[j],1);
else if((d[a[j]]+1)%3==d[b[j]]) continue;
else// Find contradictions
{
p=max(p,j);
flag=false;
break;
}
}
else if(op[j]=='>')
{
int f1=find(a[j]),f2=find(b[j]);
if(f1!=f2)
merge(a[j],b[j],-1);
else if(d[a[j]]==(d[b[j]]+1)%3) continue;
else// Find contradictions
{
p=max(p,j);
flag=false;
break;
}
}
else
{
int f1=find(a[j]),f2=find(b[j]);
if(f1!=f2)
merge(a[j],b[j],0);
else if(d[a[j]]==d[b[j]]) continue;
else// Find contradictions
{
p=max(p,j);
flag=false;
break;
}
}
}
if(flag) pos=i,ans++;
if(ans>1) break;
}
if(ans>1) puts("Can not determine");
else if(!ans) puts("Impossible");
else printf("Player %d can be determined to be the judge after %d lines\n",pos-1,p);
}
return 0;
}边栏推荐
- Great gods, I want to send two broadcast streams: 1. Load basic data from MySQL and 2. Load changes in basic data from Kafka
- MySQL - index
- gslb(global server load balance)技术的一点理解
- DR882-Qualcomm-Atheros-QCA9882-2T2R-MIMO-802.11ac-Mini-PCIe-Wi-Fi-Module-5G-high-power
- Morning flowers and evening flowers
- Global and Chinese market of wireless hard disk 2022-2028: Research Report on technology, participants, trends, market size and share
- Report on the development status and investment planning trends of China's data center industry Ⓡ 2022 ~ 2028
- Advanced technology management - how to examine candidates in the interview and increase the entry probability
- regular expression
- Under the double reduction policy, research travel may become a big winner
猜你喜欢

MySQL——JDBC

On my first day at work, this API timeout optimization put me down!

UI automation test: selenium+po mode +pytest+allure integration

Après 90 ans, j'ai démissionné pour démarrer une entreprise et j'ai dit que j'allais détruire la base de données Cloud.

Redis concludes that the second pipeline publishes / subscribes to bloom filter redis as a database and caches RDB AOF redis configuration files

Tidb's initial experience of ticdc6.0

MySQL——idea连接MySQL

Kali2021.4a build PWN environment

2022 electrician (elementary) examination questions and electrician (elementary) registration examination

What is the difference between res.send() and res.end() in the node express framework
随机推荐
Teach you how to install aidlux (1 installation)
Kali2021.4a build PWN environment
Solve the problem that openocd fails to burn STM32 and cannot connect through SWD
Cognitive fallacy: what is dimensional curse
MySQL -- standardize database design
[vulnhub shooting range] impulse: lupinone
Yyds dry inventory hcie security Day12: concept of supplementary package filtering and security policy
Analysis report on the development prospect and investment strategy of global and Chinese modular automation systems Ⓟ 2022 ~ 2027
2022 free examination questions for safety management personnel of hazardous chemical business units and reexamination examination for safety management personnel of hazardous chemical business units
gslb(global server load balance)技術的一點理解
[dynamic planning] counting garlic customers: the log of garlic King (the longest increasing public subsequence)
js demo 计算本年度还剩下多少天
Tkinter Huarong Road 4x4 tutorial III
Farmersworld farmers world, no faith, how to talk about success?
JS notes (III)
TiDB 之 TiCDC6.0 初体验
使用dnSpy對無源碼EXE或DLL進行反編譯並且修改
What if the Flink SQL client exits and the table is emptied?
Après 90 ans, j'ai démissionné pour démarrer une entreprise et j'ai dit que j'allais détruire la base de données Cloud.
2022 safety officer-b certificate examination summary and safety officer-b certificate simulation test questions