Codeforces Tutorial

B. Suspects

Problem Analysis

小时候最怕这种推理题了(笑哭)
用\(accuse_i\)表示认为第\(i\)个人是罪犯的人数
用\(defend_i\)表示认为第\(i\)个人不是罪犯的人数
用\(neg\)表示认为某个人不是罪犯的人数
\[ accuse_i=\sum_{k=1}^{n}a_k==+i \]
\[ defend_i=\sum_{k=1}^{n}a_k==-i \]
\[ neg=\sum_{k=1}^{n}a_k \lt 0 \]

假设\(i\)是罪犯,\(honest\)表示说实话的人,那么:
\[ honest=accuse_i+neg-defend_i \]

Acepted Code

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<istream>
#include<cassert>
#include<set>
#define DEBUG(x) cout<<#x<<" = "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<" = "<<x<<" , "\
<<#y<<" = "<<y<<endl
using namespace std;
typedef long long ll;
const int MAXN=1e5+10;
int n,m;
int neg=0;
int a[MAXN];
int accuse[MAXN];
int defend[MAXN];
int crimer[MAXN];
int cnt=0;
int main()
{
//    freopen("in.txt","r",stdin);scanf("%d%d",&n,&m);for(int ii=1;ii<=n ;ii++ ){int t;scanf("%d",&t);a[ii]=t;if(t>0)accuse[t]++;else defend[-t]++,neg++;}for(int ii=1;ii<=n ;ii++ ){int honest=accuse[ii]+neg-defend[ii];if(honest==m){crimer[ii]=1;cnt++;}}for(int ii=1;ii<=n ;ii++ ){int t=a[ii];if(t>0){if(crimer[t]){if(cnt>1)printf("Not defined\n");else printf("Truth\n");}else printf("Lie\n");}else {t=-t;if(crimer[t]){if(cnt>1)printf("Not defined\n");else printf("Lie\n");}else printf("Truth\n");}}
}

Wrong Answer Cases

What I Learn

针对不确定情况,在这里是Not defined,采取的策略是获取所有的可能的结果。

Reference

https://blog.csdn.net/lxc779760807/article/details/48299753

转载于:https://www.cnblogs.com/MalcolmMeng/p/10969636.html

Codeforces 156B. Suspects相关推荐

  1. CodeForces 375D Tree and Queries

    传送门:https://codeforces.com/problemset/problem/375/D 题意: 给你一颗有根树,树上每个节点都有其对应的颜色,有m次询问,每次问你以点v为父节点的子树内 ...

  2. 「日常训练」Bad Luck Island(Codeforces Round 301 Div.2 D)

    题意与分析(CodeForces 540D) 是一道概率dp题. 不过我没把它当dp做... 我就是凭着概率的直觉写的,还好这题不算难. 这题的重点在于考虑概率:他们喜相逢的概率是多少?考虑超几何分布 ...

  3. 【codeforces 812C】Sagheer and Nubian Market

    [题目链接]:http://codeforces.com/contest/812/problem/C [题意] 给你n个物品; 你可以选购k个物品;则 每个物品有一个基础价值; 然后还有一个附加价值; ...

  4. CodeForces 获得数据

    针对程序的输出可以看见 CodeForces :当输入.输出超过一定字符,会隐藏内容 所以:分若干个程序进行输入数据的获取 1. 1 for (i=1;i<=q;i++) 2 { 3 scanf ...

  5. codeforces水题100道 第二十七题 Codeforces Round #172 (Div. 2) A. Word Capitalization (strings)...

    题目链接:http://www.codeforces.com/problemset/problem/281/A 题意:将一个英文字母的首字母变成大写,然后输出. C++代码: #include < ...

  6. CodeForces 595A

    题目链接: http://codeforces.com/problemset/problem/595/A 题意: 一栋楼,有n层,每层有m户,每户有2个窗户,问这栋楼还有多少户没有睡觉(只要一个窗户灯 ...

  7. codeforces A. Jeff and Digits 解题报告

    题目链接:http://codeforces.com/problemset/problem/352/A 题目意思:给定一个只有0或5组成的序列,你要重新编排这个序列(当然你可以不取尽这些数字),使得这 ...

  8. Codeforces Round #506 (Div. 3)

    Codeforces Round #506 (Div. 3) 实习期间事不多,对div3 面向题解和数据编程了一波 A. Many Equal Substrings 题目链接 A题就是找后缀和前缀重合 ...

  9. Codeforces Round #417:E. FountainsSagheer and Apple Tree(树上博弈)

    Codeforces Round #417:E. FountainsSagheer and Apple Tree(树上博弈) 标签: codeforces 2017-06-02 11:41 29人阅读 ...

最新文章

  1. oracle 更改ip
  2. 依赖类型dependency type在maven中的作用
  3. 网络管理:3分钟排障秘技,一招胜过十年功 | 文末有彩蛋
  4. 大数据集群启停shell脚本:hadoop(hdfs、yarn)、hbase集群启停
  5. 技术帖:砖混、砖木、钢混、板楼、塔楼、框架、框架剪力墙等概念之区别优劣...
  6. Vue $nextTick
  7. vb 垂直滚动条定位
  8. 说说C#的async和await
  9. WhoIsOnline ;) - 解读CNForum源码中在线用户统计
  10. 自动填充固定行数的 GridView (转)
  11. IMPORTANT: You may need to close and restart your shell after running ‘conda init‘.
  12. Pascal VOC 2012数据集下载(速度很快)
  13. C语言程序100例之C#版-029
  14. Unity2019配置ARCore环境
  15. IE新功能:十大特色IE插件(转)
  16. c语言tc环境下while多大,求救,wintc环境下,写了程序,调试不出来,先谢谢了...
  17. 1193: [HNOI2006]马步距离
  18. ansible部署和基本的操作
  19. 给大家介绍一下地推的认知
  20. mysql cascade 查询_Python全栈 MySQL 数据库 (SQL查询、备份、恢复、授权)

热门文章

  1. Instagram大爆炸:坚守专注简洁的乔布斯法则
  2. install soft
  3. 零时科技 || Victor the Fortune攻击事件分析
  4. 从未过时的的电阻色环法
  5. 项目记录: 3DOF+实时渲染 之 虚拟视点合成
  6. (4.6.25)Android动态更换应用Icon之玩转桌面图标
  7. 写码如写诗,Android代码规范有多重要?附阿里《Android代码规范指南》PDF
  8. C++ 指针p1 p2,p1-p2 与*p1-*p2的区别
  9. 火爆的小程序商城,你了解它的这6大优点吗?
  10. java对接支付宝小程序支付