CF156B - Suspects

CF156B - Suspects(枚举)

As Sherlock Holmes was investigating a crime, he identified n suspects. He knows for sure that exactly one of them committed the crime. To find out which one did it, the detective lines up the suspects and numbered them from 1 to n. After that, he asked each one: “Which one committed the crime?”. Suspect number i answered either “The crime was committed by suspect number ai”, or “Suspect number ai didn’t commit the crime”. Also, the suspect could say so about himself (ai = i).

Sherlock Holmes understood for sure that exactly m answers were the truth and all other answers were a lie. Now help him understand this: which suspect lied and which one told the truth?

Input
The first line contains two integers n and m (1 ≤ n ≤ 105, 0 ≤ m ≤ n) — the total number of suspects and the number of suspects who told the truth. Next n lines contain the suspects’ answers. The i-th line contains either “+ai” (without the quotes), if the suspect number i says that the crime was committed by suspect number ai, or “-ai” (without the quotes), if the suspect number i says that the suspect number ai didn’t commit the crime (ai is an integer, 1 ≤ ai ≤ n).

It is guaranteed that at least one suspect exists, such that if he committed the crime, then exactly m people told the truth.

Output
Print n lines. Line number i should contain “Truth” if suspect number i has told the truth for sure. Print “Lie” if the suspect number i lied for sure and print “Not defined” if he could lie and could tell the truth, too, depending on who committed the crime.

Examples
Input
1 1
+1
Output
Truth
Input
3 2
-1
-2
-3
Output
Not defined
Not defined
Not defined
Input
4 1
+2
-3
+4
-1
Output
Lie
Not defined
Lie
Not defined
Note
The first sample has the single person and he confesses to the crime, and Sherlock Holmes knows that one person is telling the truth. That means that this person is telling the truth.

In the second sample there are three suspects and each one denies his guilt. Sherlock Holmes knows that only two of them are telling the truth. Any one of them can be the criminal, so we don’t know for any of them, whether this person is telling the truth or not.

In the third sample the second and the fourth suspect defend the first and the third one. But only one is telling the truth, thus, the first or the third one is the criminal. Both of them can be criminals, so the second and the fourth one can either be lying or telling the truth. The first and the third one are lying for sure as they are blaming the second and the fourth one.
思路:枚举n个人是罪犯的情况看是否能让真话数量为n,首先如果没有一个人是罪犯那真话数量就是负数的数量,我们统计下来,然后如果有一个人是罪犯,那真话数量就在原来基础上减掉说他不是罪犯的在加上说他是罪犯的,所以可以维护一个suspect数组方便加减操作,最后根据可能成真情况数量和可能为罪犯的人来判断每个人说的话的真假。
具体代码:

#include<iostream>
using namespace std;
const int N=100005;
int a[N],suspect[N],may[N],tot=0,no=0;
int main()
{
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        int tmp;
        cin>>tmp;
        a[i]=tmp;
        if(tmp>0)
        {
            suspect[tmp]++;//是罪犯
        }
        else
        {
            suspect[-tmp]--;//不是罪犯
            no++;
        }
    }
    for(int i=1;i<=n;i++)
    {
        if(no+suspect[i]==m)//枚举n个人是罪犯看真话是不是m
        {
            tot++;//可能成真情况+1
            may[i]=1;//第i个人可能是罪犯
        }
    }
    for(int i=1;i<=n;i++)
    {
        if(a[i]>0)
        {
            if(!may[a[i]])puts("Lie");
            else if(tot==1)puts("Truth");
            else puts("Not defined");
        }
        else 
        {
            if(!may[-a[i]])puts("Truth");
            else if(tot==1)puts("Lie");
            else puts("Not defined");
        }
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值