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#指南,重温基础,展望远方!(1)C#语言介绍

    1.C#(读作“See Sharp”)是一种简单易用的新式编程语言,不仅面向对象,还类型安全. C# 源于 C 语言系列,C.C++.Java 和 JavaScript 程序员很快就可以上手使用. 2 ...

  2. php对xml文件的增删改查

    源文件<?xml version="1.0" encoding="utf-8"?><root>  <endTime>2016 ...

  3. Windows下Python添加MySQLdb扩展模块

    [更新 2012-09-16] 这里可以下载已经打包好的EXE文件,http://sourceforge.net/projects/mysql-python/(国内需穿越才可访问) DBank备份下载 ...

  4. 智能指针tr1::shared_ptr、boost::shared_ptr使用

    对于tr1::shared_ptr在安装vs同一时候会自带安装,可是版本号较低的不存在.而boost作为tr1的实现品,包括 "Algorithms Broken Compiler Work ...

  5. JS检查浏览器类型和版本号

    先取得Navigator对象的userAgent属性的小写信息,之后依据正則表達式推断赋值. var Sys = {}; var ua = navigator.userAgent.toLowerCas ...

  6. 413. Reverse Integer【easy】

    Reverse digits of an integer. Returns 0 when the reversed integer overflows (signed 32-bit integer). ...

  7. iOS 小数点精度问题处理

    实际开发中有时候经常会需要去处理小数点精度问题,如果是整数保留整数,如果有小数则保留不为0的的小数,最大2位小数 eg: 2.013 ---> 2.01 2.0 ---> 2 2.10 - ...

  8. 玩黑客学校CTF

    关卡很简单就不细说.不懂的百度 第一关: 源码: 解密得出为JO 第二关: 很明白,表单问题. </script> <div style = "text-align: ce ...

  9. POJ 2472 106 miles to Chicago

    最短路问题变形. 题意是给你一些道路,和路过时不被抓的概率. 要求找一条到达目的地时不被抓的最大概率概率. 初始 dis[]设为 1 .其余为 0 .找最大就可以. #include<cstdi ...

  10. Iptables详解+实例

    Iptabels是与Linux内核集成的包过滤防火墙系统,几乎所有的linux发行版本都会包含Iptables的功能.如果 Linux 系统连接到因特网或 LAN.服务器或连接 LAN 和因特网的代理 ...