Suspects

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

Submit Status

Description

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 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 i lied for sure and print "Not defined" if he could lie and could tell the truth, too, depending on who committed the crime.

Sample Input

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

Hint

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表示嫌疑人说的话,+c[i]表示第i个人说c[i]是犯人,-c[i]表示第i个人说c[i]不是犯人。m表示这n个人中有m个人说真话。现在让你判断每个人说的是真话还是假话,或者不确定。

解题思路:如果我们假设第i个人是犯人,那么我们通过O(n)的复杂度可以得出说真话的人的个数mi,那么如果mi==m,那么把这个人放入犯人数组。最后如果犯人数组中只有一个犯人,那么我们可以准确判断每个人说话的真假性。如果犯人数组中人数很多,那么如果c[i] > 0,且c[i]在犯人数组中,那么不确定,如果c[i]不在犯人数组中,那么这个人必然说假话;如果c[i]<0,且|c[i]|这个人在犯人数组中,那么也是不确定,如果|c[i]|不在犯人数组中,那么这个人必然说真话。 现在问题是如果每次用O(n)得出mi,那么复杂度将是O(n^2)。我们可以首先统计出总的说别人不是犯人的个数nosupn,以及说i是犯人的人数issuspect[i]和说i不是犯人的人数nosuspect[i],那么mi = issuspect[i] + nosupn - nosuspect[i]。 这复杂度为O(1)。

#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<math.h>
#include<string>
#include<iostream>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#include<set>
using namespace std;
typedef long long LL;
#define mid (L+R)/2
#define lson rt*2,L,mid
#define rson rt*2+1,mid+1,R
#pragma comment(linker, "/STACK:102400000,102400000")
const int maxn = 1e5 + 300;
const int INF = 0x3f3f3f3f;
typedef long long LL;
typedef unsigned long long ULL;
int a[maxn];
int issuspect[maxn], nosuspect[maxn];
int iscrimer[maxn], crimer[maxn];
int main(){
int n, m;
while(scanf("%d%d",&n,&m)!=EOF){
int nosupn = 0;
for(int i = 1; i <= n; i++){
scanf("%d",&a[i]);
if(a[i] > 0){
issuspect[a[i]]++;
}else{
nosuspect[-a[i]]++;
nosupn++;
}
}
int saytrue = 0;
int cn = 0;
for(int i = 1; i <= n; i++){
saytrue = issuspect[i] + nosupn - nosuspect[i];
if(saytrue == m){
crimer[cn] = i; cn++;
iscrimer[i] = 1;
}
}
if(cn == 1){
for(int i = 1; i <= n; i++){
if(a[i] > 0){
if(iscrimer[a[i]]){
puts("Truth");
}else{
puts("Lie");
}
}else{
if(iscrimer[-a[i]]){
puts("Lie");
}else{
puts("Truth");
}
}
}
}else{
for(int i = 1; i <= n; i++){
if(a[i] > 0){
if(iscrimer[a[i]]){
puts("Not defined");
}else{
puts("Lie");
}
}else{
if(iscrimer[-a[i]]){
puts("Not defined");
}else{
puts("Truth");
}
}
}
}
}
return 0;
}

  

Codeforces 156B Suspects——————【逻辑判断】的更多相关文章

  1. CodeForces 156B Suspects(枚举)

    B. Suspects time limit per test 2 seconds memory limit per test 256 megabytes input standard input o ...

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

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

  3. Codeforces Round #110 (Div. 2)

    Codeforces Round #110 (Div. 2) C. Message 题意 给两个长度不超过2000的字符串\(s,u\),仅由小写字母构成. 找出\(s\)的一个子串\(t\),通过3 ...

  4. Codeforces Round #330 (Div. 2)D. Max and Bike 二分 物理

    D. Max and Bike Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/595/probl ...

  5. Codeforces Round #298 (Div. 2) A. Exam 构造

    A. Exam Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/534/problem/A Des ...

  6. Codeforces Round #298 (Div. 2) A、B、C题

    题目链接:Codeforces Round #298 (Div. 2) A. Exam An exam for n students will take place in a long and nar ...

  7. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  8. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  9. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

随机推荐

  1. sampling method

    sampling method 背景 在贝叶斯框架下,利用后验分布对参数进行估计,也即 其中 (1)是参数的先验分布. (2)是似然分布,数据集的生成联合概率 (3)是参数的后验分布. 通常分布很复杂 ...

  2. PMBOK项目管理PMI主义\IPMA概述

    PMP(Project Management Professional)指项目管理专业人士资格认证,是美国项目管理协会(Project Management Institute,PMI)在全球180多 ...

  3. [SIP00]SIP 概念总结

    SIP ---------------------------   Session Initiation Protocol ---------------------------   create, ...

  4. 高德地图之c#后台获取一个或多个起点到单个终点的直线距离

    首先我们需要一个控制台添加一个新Key(可使用服务选择Web服务,测试的时候IP白名单先不填); 直线距离是通过后台get方式请求API服务地址http://restapi.amap.com/v3/d ...

  5. git subrepo

    此文已由作者张磊授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 前言 目前对 git 仓库拆分的已有实现之一,并没有合并到 git 发行版中.项目的地址是 https://g ...

  6. 如何在linux上安装使用virt-manager

    环境是centos6.5-64位操作系统. 1.准备yum源: 将CentOS6-Base-163.repo 下载到目标主机的/etc/yum.repos.d/目录. cd /etc/yum.repo ...

  7. 洛谷P2495 [SDOI2011]消耗战(虚树)

    题面 传送门 题解 为啥一直莫名其妙\(90\)分啊--重构了一下代码才\(A\)掉-- 先考虑直接\(dp\)怎么做 树形\(dp\)的时候,记一下断开某个节点的最小值,就是从根节点到它的路径上最短 ...

  8. NFS共享服务

    一.网络文件系统共享服务 NFS( Network File System,网络文件系统 )是一种基于TCP/IP传输的网络文件系统协议,最初由SUN公司开发,通过使用NFS协议,客户机可以像访问本地 ...

  9. React Native 一些事

    ReactJS 是否准备好 有时候我们常常需要监听 ReactJS 的的加载情况. 比如说,当获取一条推送,应用还没有起来,通过点击推送启动应用后,而推送中包含一些我们感兴趣的字段需要处理,我们如果直 ...

  10. docker 创建容器的时候的坑

    其实这个题目的话,对于我后面陈述的问题发生的本身并没有太多的联系,但是因为是在docker创建容器的操作之内发生的,所以记录以下 因为网上有些文章有些作者喜欢使用git的命令窗体,说实在的,公司里面用 ...