B. Suspects
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard 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 aididn'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 isays 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 ilied
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 枚举i是罪犯,然后看哪些人说了真话,人数等于m说明这个人可能是罪犯
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include <math.h>
#include <stdio.h> using namespace std;
#define MAX 100000
int n,m;
int a[MAX+5];
int b[MAX+5];
int f[MAX+5];
int tag[MAX+5];
int main()
{
scanf("%d%d",&n,&m);
int x;
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
int sum=0;
for(int i=1;i<=n;i++)
{
scanf("%d",&f[i]);
if(f[i]>0)
{
a[f[i]]++;
}
else
{
b[-f[i]]++;
sum++;
}
}
memset(tag,0,sizeof(tag));
int k=0;
for(int i=1;i<=n;i++)
{
if(a[i]+sum-b[i]==m)
{
tag[i]=1;
k++;
}
}
for(int i=1;i<=n;i++)
{
if(f[i]>0)
{
if(tag[f[i]]&&k==1)
printf("Truth\n");
else if(!tag[f[i]])
printf("Lie\n");
else
printf("Not defined\n");
}
else
{
if(!tag[-f[i]])
printf("Truth\n");
else if(tag[-f[i]]&&k==1)
printf("Lie\n");
else
printf("Not defined\n");
}
}
return 0;
}

CodeForces 156B Suspects(枚举)的更多相关文章

  1. CodeForces - 156B Suspects 逻辑 线性 想法 题

    题意:有1~N,n(1e5)个嫌疑人,有m个人说真话,每个人的陈述都形如X是凶手,或X不是凶手.现在给出n,m及n个陈述(以+x/-X表示)要求输出每个人说的话是true ,false or notd ...

  2. Codeforces 156B Suspects——————【逻辑判断】

    Suspects Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit St ...

  3. codeforces 1183F 离散化枚举 约数定理

    codeforces1183F 有技巧的暴力 传送门:https://codeforces.com/contest/1183/problem/F 题意: 给你n个数,要你从中选出最多三个数,使得三个数 ...

  4. CodeForces 379D 暴力 枚举

    D. New Year Letter time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  5. CodeForces 280B(枚举 + 单调栈应用)

    题目链接 思路如下 这题恶心的枚举任意区间的 最大值及次最大值 ,正常的操作是,是很难实现的,但偏偏有个 单调栈这个动西,能够完成这个任务,跟单调队列相似,有单调 递增.递减的栈,这一题我们需要维护的 ...

  6. Codeforces 1154G(枚举)

    我预处理\(1e7log(1e7)\)的因数被T掉了,就不敢往这个复杂度想了--无奈去看AC代码 结果怎么暴举gcd剪一剪小枝就接近3s卡过去了!vector有锅(确信 const int maxn ...

  7. Codeforces Round #103 (Div. 2) D. Missile Silos(spfa + 枚举边)

    题目链接:http://codeforces.com/problemset/problem/144/D 思路:首先spfa求出中心点S到其余每个顶点的距离,统计各顶点到中心点的距离为L的点,然后就是要 ...

  8. Codeforces Round #379 (Div. 2) C. Anton and Making Potions 枚举+二分

    C. Anton and Making Potions 题目连接: http://codeforces.com/contest/734/problem/C Description Anton is p ...

  9. Codeforces Round #249 (Div. 2) D. Special Grid 枚举

    题目链接: http://codeforces.com/contest/435/problem/D D. Special Grid time limit per test:4 secondsmemor ...

随机推荐

  1. C#光盘刻录

    一.背景介绍 最近公司一个老项目需要添加导出数据到光盘的功能.开始对这功能添加有点抵触的.光盘?都啥年代了. 光盘一种即将淘汰的存储媒介.就像当年的随身听,Mp3,Mp4一样,即将退出历史舞台.领导让 ...

  2. c语言中有bool型变量吗?

    C语言里面是没有bool(布尔)类型的,C++里面才有,这就是说,在C++里面使用bool类型是没有问题的. bool类型有只有两个值:true =1 .false=0. 但是,C99标准里面,又定义 ...

  3. linux 批量替换内容

    sed -i "s/被替换的内容/替换的内容/g" `grep "被替换的内容" -rl 目录` -r = 搜索下级目录

  4. SQL 查询结果为 XML

    --原始数据 SELECT  OrderNO,CreateDate,Username,Address FROM   Whir_Order_OrderInfo --1.AUTO模式 SELECT  Or ...

  5. 王立平-- Swift

    Swift是供iOS和OS X应用编程的新编程语言,基于C和Objective-C.而却没有C的一些兼容约束.Swift採用了安全的编程模式和加入现代的功能来是的编程更加简单.灵活和有趣. 界面则基于 ...

  6. 3. Digit Counts【medium】

    Count the number of k's between 0 and n. k can be 0 - 9.   Example if n = 12, k = 1 in [0, 1, 2, 3, ...

  7. Linux下出现Read-only file system的解决办法

    正常运行中的网站,忽然间出现session目录不可写,连接服务器一看,任何关于写硬盘的命令都不能用,提示Read-only file system,使用一条命令即可搞定此问题: mount -o re ...

  8. PHP学习笔记(4)GD库画五角星

         <?php //加header头,不然浏览器乱码 header("content-type: image/png"); //创建画布资源 $img = imagec ...

  9. 跟着百度学PHP[14]-PDO之Mysql的事务处理1

    事务处理:在实际案例当中干一件事的mysql语句(好比转账,小一同学转账100,小二同学收账,在mysql当中小一就要减去转账的钱,小二就要增加100快)倘若该语句执行过程中有任何一条的sql语句出错 ...

  10. 转载:JMeter压力测试入门教程[图文]

    JMeter压力测试入门教程[图文] Apache JMeter是Apache组织开发的基于Java的压力测试工具.用于对软件做压力测试,它最初被设计用于Web应用测试但后来扩展到其他测试领域. 它可 ...