And query set exercises --- poj 2912

Source: Internet
Author: User

The integration and maintenance of collections are the same as those of the food chain.

However, there is an additional referee. Note that N <= 500, so you can enumerate the referee and determine whether there is a conflict. (Ignore the referee)

If there is a conflict, this person is not a referee.

The only difficulty is to output the rows of judgments.

I thought it was the last line of the referee.

Later, we found that the maximum value of the conflict should appear for the first time when we enumerated other people. (Think about it)

This solves the problem.

[Code]


[Cpp]
# Include <iostream>
# Include <cstring>
# Include <string>
# Include <cstdio>
# Include <algorithm>
Using namespace std;
 
Const int N = 505, M = 2005;
 
Int fa [N], r [N], x [M], y [M], z [M];
Int n, m, k, kk, ans;
 
Int find (int x)
{
If (fa [x] = x) return x;
Int t = fa [x];
Fa [x] = find (fa [x]);
R [x] = (r [x] + r [t]) % 3;
Return fa [x];
}
 
Int main ()
{
Int I, j, fx, fy;
Bool ff;
Char c;
 
Freopen ("in", "r", stdin );
While (scanf ("% d", & n, & m )! = EOF)
{
For (I = 1; I <= m; I ++)
{
Scanf ("% d % c % d", & x [I], & c, & y [I]);
If (c = '<') z [I] = 2;
Else if (c = '>') z [I] = 1;
Else z [I] = 0;
}
Ans = k = kk = 0;
For (j = 0; j <n; j ++)
{
Ff = true;
For (I = 0; I <n; I ++)
{
Fa [I] = I;
R [I] = 0;
}
For (I = 1; I <= m; I ++)
{
If (x [I] = j | y [I] = j) continue;
Fx = find (x [I]); fy = find (y [I]);
If (fx! = Fy)
{
Fa [fy] = fx;
R [fy] = (r [x [I]-r [y [I]-z [I] + 6) % 3;
}
Else if (r [x [I]-r [y [I] + 3) % 3! = Z [I])
{
Ff = false;
Kk = max (kk, I );
Break;
}
}
If (ff)
{
Ans ++; k = j;
If (ans> 1) break;
}
}
If (ans = 0) printf ("Impossible \ n ");
Else if (ans> 1) printf ("Can not determine \ n ");
Else printf ("Player % d can be determined to be the judge after % d lines \ n", k, kk );
}
}


Author: ascii991

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.