当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

1332:Finding Liars

题目描述
There are n>=2 people labeled as 1, 2, ... , n such that each of them is either a truth-teller or a liar, and the number of liars is less than or equal to t for some t (<=n).
Each person i can test another person j in order to identify person j as truth-teller or liar by giving some question to person j. The outcome ai,j of the test applied by person i to person j is 1 (0) if person i identifies person j as a liar (truth-teller). The test outcome ai,j is reliable if and only if the testing person i is a truth-teller.
That is, the test outcome ai,j is unreliable if and only if the testing person i is a liar. The following table shows the value of the test outcome ai,j when person i tests person j.

i (tester)j (testee)/td>test outcome ai,j
truth-tellertruth-teller0
truth-tellerliar1
liartruth-teller0 or 1
liarliar0 or 1


Testing is performed circularly as follows: person 1 tests person 2, person 2 tests person 3,..., person n-1 tests
person n, and person n tests person 1. From the test outcomes, some persons are definitely liars, but some
others may or may not be liars. From n, t, and the test outcomes, determine the persons who are definitely liars.


For example, let n = 5, t = 2, and the test outcomes (a1,2, a2,3, a3,4, a4,5, a5,1) be (0, 1, 1, 0, 0). In the following
figure, each circle represents a person, and the label on the edge (i, j) represents the test outcome ai,j.



In this example, person 3 should be a liar because if not, person 4 is liar and persons 2 is liar, thus persons 1, 5,
and 4 become liars, which contradicts the condition that the number of liars does not exceed t = 2. Therefore
person 3 is determined as a definite liar. However, because both {person 3, person 4} and {person 3} can be
sets of liars, we can't determine that person 4 is a liar.


Given n (the number of persons), t (the maximum number of liars), and the set of test outcomes, write a
program to find all the persons who are definitely liars. It is assumed that the given set of outcomes is one that
results from some liars who are less than or equal to t.

输入解释
The input consists of T test cases. The number of test cases (T ) is given in the first line of the input file. Each test case consists of two lines. The first line has two integers. The first integer is n (2<=n<=1000), the number of persons, and the second integer is t (0<=t<=n), the maximum number of liars. The second line contains n 0 or 1's that represent a1,2, a2,3, a3,4, ..., a(n-1),n, an,1.
输出解释
Print exactly one line for each test case. The line should contain two integers. The first integer is the number of all the definite liars. The second integer is the smallest label of definite liars. In case that the number of definite liars is equal to 0, then the second integer should be 0.
输入样例
3
5 2
0 1 1 0 0
7 2
0 0 1 0 0 1 1
9 8
1 0 0 0 0 1 0 0 0
输出样例
1 3
2 4
0 0


该题目是Virtual Judge题目,来自 北京大学POJ

题目来源 Taejon 2002

源链接: POJ-1332

最后修改于 2020-10-29T06:01:11+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
1000 10000