CodeForces 156B Suspects(枚举)
2 seconds
256 megabytes
standard input
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?
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.
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.
1 1
+1
Truth
3 2
-1
-2
-3
Not defined
Not defined
Not defined
4 1
+2
-3
+4
-1
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(枚举)的更多相关文章
- CodeForces - 156B Suspects 逻辑 线性 想法 题
题意:有1~N,n(1e5)个嫌疑人,有m个人说真话,每个人的陈述都形如X是凶手,或X不是凶手.现在给出n,m及n个陈述(以+x/-X表示)要求输出每个人说的话是true ,false or notd ...
- Codeforces 156B Suspects——————【逻辑判断】
Suspects Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Submit St ...
- codeforces 1183F 离散化枚举 约数定理
codeforces1183F 有技巧的暴力 传送门:https://codeforces.com/contest/1183/problem/F 题意: 给你n个数,要你从中选出最多三个数,使得三个数 ...
- CodeForces 379D 暴力 枚举
D. New Year Letter time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- CodeForces 280B(枚举 + 单调栈应用)
题目链接 思路如下 这题恶心的枚举任意区间的 最大值及次最大值 ,正常的操作是,是很难实现的,但偏偏有个 单调栈这个动西,能够完成这个任务,跟单调队列相似,有单调 递增.递减的栈,这一题我们需要维护的 ...
- Codeforces 1154G(枚举)
我预处理\(1e7log(1e7)\)的因数被T掉了,就不敢往这个复杂度想了--无奈去看AC代码 结果怎么暴举gcd剪一剪小枝就接近3s卡过去了!vector有锅(确信 const int maxn ...
- Codeforces Round #103 (Div. 2) D. Missile Silos(spfa + 枚举边)
题目链接:http://codeforces.com/problemset/problem/144/D 思路:首先spfa求出中心点S到其余每个顶点的距离,统计各顶点到中心点的距离为L的点,然后就是要 ...
- 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 ...
- Codeforces Round #249 (Div. 2) D. Special Grid 枚举
题目链接: http://codeforces.com/contest/435/problem/D D. Special Grid time limit per test:4 secondsmemor ...
随机推荐
- 利用python进行泰坦尼克生存预测——数据探索分析
最近一直断断续续的做这个泰坦尼克生存预测模型的练习,这个kaggle的竞赛题,网上有很多人都分享过,而且都很成熟,也有些写的非常详细,我主要是在牛人们的基础上,按照数据挖掘流程梳理思路,然后通过练习每 ...
- Codeforces 474D Flowers 动态规划法
话说好久没写算法代码了,工作了有点忙的了.只是算法始终是我的挚爱,故此还是尽量抽时间和挚爱来个约会. Codeforces的题目是最适合练手的了,以下是一道不算难的动态规划法题目.先上题: D. Fl ...
- 简单的刚開始学习的人配置Android SDK+ADT+Eclipse
1.下载JDK.Android SDK和Eclipse(Eclipse 版本号最好新一些) 注意:下载的SDK最好和后面的ADT配套,否则Eclipse可能会报错. 如:SDK 21.0.1 相应 A ...
- php处理XML数据
把XML转换成对象直接调用里面的属性 <?php$note=<<<XML<note><to>Tove</to><from>Jan ...
- unity5, assert
assert可以实现“三步一岗五步一哨”可以说是保证代码正确性(安全编程)的最有力工具.在用c++写程序的时候assert语句总是要占整个程序的大部分篇幅. 但是转到unity c#,一开始没找到as ...
- [k8s]k8s-web-terminal配置使用 & etcdui etcd browser配置 & etcdkeeper3配置
安装kube-dns后,我想看看他是怎么个配置,于是我就找到了这个 参考: https://github.com/beyondblog/k8s-web-terminal cat >> /e ...
- 使用 OpCache 提升 PHP 性能
使用 OpCache 提升 PHP 性能 wdd2007wdd2007 .6k 1月29日 发布 推荐 推荐 收藏 收藏,.3k 浏览 OpCache 通过对 opcode 的缓存和优化来提升 PHP ...
- listView里面添加gridview
package com.example.cc.ecustapp.Adapter; import android.content.Context;import android.util.DisplayM ...
- STM32F10x_模拟I2C读写EEPROM
Ⅰ.写在前面 说到IIC,大家都应该不会陌生,我们初学单片机的时候或多或少都知道或了解过,甚至使用I2C控制过器件.但是,有多少人真正去深入理解,或者深入研究过I2C通信协议呢? 1.我们有必要学习I ...
- MySQL集群系列2:通过keepalived实现双主集群读写分离
在上一节基础上,通过添加keepalived实现读写分离. 首先关闭防火墙 安装keepalived keepalived 2台机器都要安装 rpm .el6.x86_64/ 注意上面要替换成你的内核 ...