我是靠谱客的博主 大胆向日葵,最近开发中收集的这篇文章主要介绍codeforces 156B Suspects 暴力,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

Suspects

time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
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个嫌疑人,其中一个是凶手,他去调查每个人,知道这之中的m个人说的是真话,输入中ai若为正数,则为第i个人说ai是凶手,若为负数,则为第i个人说ai不是凶手,问你其中的哪些人说谎,那些人不是说谎,哪些人的话不能确定。

解题思路:暴力讨论第i个人是凶手的时候,有多少个人说的是真话,若说真话的人等于m,则i为凶手的可能性存在,若只有这一种情况符合,则i必定为凶手,我们即可知道一些人说的话是真是假,或者如果不等于m,则我们可以知道他肯定不是凶手,所以我们也可以知道一些人说的话是真是假,最后输出即可。

#include<cstdio>
#define maxn 100005
int n,m,a[maxn],b[maxn],c[maxn],sum,k,d[maxn];
int main(){
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        if(a[i]>0)  b[a[i]]++;
        else{
            c[-a[i]]++;
            sum++;
        }
    }
    for(int i=1;i<=n;i++){
        if(b[i]+sum-c[i]==m){
            d[i]=1;
            k++;
        }
    }

    for(int i=1;i<=n;i++){
        if(a[i]>0){
            if(d[a[i]]==1&&k==1)    printf("Truthn");
            else if(d[a[i]]==0) printf("Lien");
            else printf("Not definedn");
        }
        else{
            if(d[-a[i]]==1&&k==1)   printf("Lien");
            else if(d[-a[i]]==0)    printf("Truthn");
            else printf("Not definedn");
        }
    }
    return 0;
}

最后

以上就是大胆向日葵为你收集整理的codeforces 156B Suspects 暴力的全部内容,希望文章能够帮你解决codeforces 156B Suspects 暴力所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(40)

评论列表共有 0 条评论

立即
投稿
返回
顶部