当前位置:网站首页>(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;
}边栏推荐
- Getting started with DOM
- Report on the current situation and development trend of ethoxylated sodium alkyl sulfate industry in the world and China Ⓞ 2022 ~ 2027
- 鹏城杯 WEB_WP
- Report on the development status and investment planning trends of China's data center industry Ⓡ 2022 ~ 2028
- Leetcode problem solving - 235 Nearest common ancestor of binary search tree
- China's TPMS industry demand forecast and future development trend analysis report Ⓐ 2022 ~ 2028
- Analysis report on the development prospect and investment strategy of global and Chinese modular automation systems Ⓟ 2022 ~ 2027
- DOM light switch case
- DR-NAS26-Qualcomm-Atheros-AR9582-2T-2R-MIMO-802.11-N-5GHz-high-power-Mini-PCIe-Wi-Fi-Module
- Global and Chinese market of AC induction motors 2022-2028: Research Report on technology, participants, trends, market size and share
猜你喜欢

Electronic tube: Literature Research on basic characteristics of 6j1

Covariance
![[SRS] build a specified version of SRS](/img/01/0d2d762e01b304220b8924d20277e3.jpg)
[SRS] build a specified version of SRS

Functions and differences between static and Const

Station B, dark horse programmer, employee management system, access conflict related (there is an unhandled exception at 0x00007ff633a4c54d (in employee management system.Exe): 0xc0000005: read locat

No matter how hot the metauniverse is, it cannot be separated from data

常用sql集合

A little understanding of GSLB (global server load balance) technology

QFileDialog

UC Berkeley proposes a multitask framework slip
随机推荐
Cognitive fallacy: what is Fredkin's paradox
Luogu deep foundation part 1 Introduction to language Chapter 7 functions and structures
Sed、Awk
Morning flowers and evening flowers
90 後,辭職創業,說要卷死雲數據庫
常用sql集合
No matter how hot the metauniverse is, it cannot be separated from data
What indicators should be paid attention to in current limit monitoring?
The 14th five year plan for the construction of Chinese Enterprise Universities and the feasibility study report on investment Ⓓ 2022 ~ 2028
English topic assignment (28)
Electronic tube: Literature Research on basic characteristics of 6j1
Décompiler et modifier un exe ou une DLL non source en utilisant dnspy
DR882-Qualcomm-Atheros-QCA9882-2T2R-MIMO-802.11ac-Mini-PCIe-Wi-Fi-Module-5G-high-power
Common SQL sets
Conditional statements of shell programming
The White House held an open source security summit, attended by many technology giants
Supply and demand situation and market scale calculation report of China's portable energy storage power PES industry Ⓛ 2022 ~ 2028
Global and Chinese market of AC induction motors 2022-2028: Research Report on technology, participants, trends, market size and share
MySQL——idea连接MySQL
鹏城杯 WEB_WP