【CF】110 Div.1 B. Suspects
这题目乍眼一看还以为是2-sat。其实很水的,O(n)就解了。枚举每个人,假设其作为凶手。观察是否满足条件。
然后再对满足的数目分类讨论,进行求解。
/* 156B */
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <deque>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <climits>
#include <cctype>
#include <cassert>
#include <functional>
#include <iterator>
#include <iomanip>
using namespace std;
//#pragma comment(linker,"/STACK:102400000,1024000") #define sti set<int>
#define stpii set<pair<int, int> >
#define mpii map<int,int>
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define rep(i, a, n) for (int i=a;i<n;++i)
#define per(i, a, n) for (int i=n-1;i>=a;--i)
#define clr clear
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define lson l, mid, rt<<1
#define rson mid+1, r, rt<<1|1 const int maxn = 1e5+;
int pos[maxn], neg[maxn];
vi P[maxn];
vi N[maxn];
int ans[maxn];
int st[maxn];
char s[][] = {
"Not defined",
"Truth",
"Lie"
}; int main() {
ios::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif int n, m, x;
int pn = , nn = ; scanf("%d %d", &n, &m);
rep(i, , n+) {
scanf("%d", &x);
if (x > ) {
++pos[x];
P[x].pb(i);
++pn;
} else {
x = -x;
++neg[x];
N[x].pb(i);
++nn;
}
} int tmp;
vi vc; rep(i, , n+) {
// i is murder
tmp = pos[i] + nn - neg[i];
if (tmp == m)
vc.pb(i);
} int sz = SZ(vc);
if (sz == ) {
x = vc[];
rep(i, , n+)
st[i] = -;
st[x] = ;
} else {
rep(i, , n+)
st[i] = -;
rep(i, , sz)
st[vc[i]] = ;
}
rep(i, , n+) {
sz = SZ(P[i]);
if (sz && st[i]) {
x = st[i]> ? :;
rep(j, , sz)
ans[P[i][j]] = x;
}
sz = SZ(N[i]);
if (sz && st[i]) {
x = st[i]< ? :;
rep(j, , sz)
ans[N[i][j]] = x;
}
} rep(i, , n+)
puts(s[ans[i]]); #ifndef ONLINE_JUDGE
printf("time = %d.\n", (int)clock());
#endif return ;
}
【CF】110 Div.1 B. Suspects的更多相关文章
- 【CF】121 Div.1 C. Fools and Roads
题意是给定一棵树.同时,给定如下k个查询: 给出任意两点u,v,对u到v的路径所经过的边进行加计数. k个查询后,分别输出各边的计数之和. 思路利用LCA,对cnt[u]++, cnt[v]++,并对 ...
- 【CF】310 Div.1 C. Case of Chocolate
线段树的简单题目,做一个离散化,O(lgn)可以找到id.RE了一晚上,额,后来找到了原因. /* 555C */ #include <iostream> #include <str ...
- 【CF】222 Div.1 B Preparing for the Contest
这样类似的题目不少,很多都是一堆优化条件求最优解,这个题的策略就是二分+贪心.对时间二分, 对费用采用贪心. /* 377B */ #include <iostream> #include ...
- 【CF】207 Div.1 B.Xenia and Hamming
这题目一看很牛逼,其实非常easy.求求最小公倍数,最大公约数,均摊复杂度其实就是O(n). /* 356B */ #include <iostream> #include <str ...
- 【CF】142 Div.1 B. Planes
SPFA.注意状态转移条件,ans的求解需要在bfs中间求解.因为只要到了地点n,则无需等待其他tourist.还是蛮简单的,注意细节. /* 229B */ #include <iostrea ...
- 【CF】196 Div.2 D. Book of Evil
显然这个图是一课树,看着题目首先联想到LCA(肯定是可以解的).但是看了一下数据大小,应该会TLE.然后,忽然想到一个前面做过的题目,大概是在一定条件下树中某结点旋转成为根后查询最长路径.结果灵感就来 ...
- 【CF】223 Div.1 C Sereja and Brackets
水线段树. /* 380C */ #include <iostream> #include <string> #include <map> #include < ...
- 【CF】259 Div.1 B Little Pony and Harmony Chest
还蛮有趣的一道状态DP的题目. /* 435B */ #include <iostream> #include <string> #include <map> #i ...
- 【CF】174 Div.1 B Cow Program
思路是树形DP+状态压缩.其实仅有2个状态,奇数次来到x或者偶数次来到x.(因为对x的更新不同).同时开辟visit数组,解决环.注意,一旦遇到环结果就是-1.DP数组存放第奇数/偶数次来到x时,对y ...
随机推荐
- jsonp调用webapi和mvc
webapi代码如下: public string Get(int id) { var callback = HttpContext.Current.Request["callback&qu ...
- java新手笔记2 数据类型
1.注释 /** doc注释 * 类说明信息 */ //声明类 文件名与类名一致 public class World {//类定界符 //声明方法 main方法 public static void ...
- iTerm 使用expect实现自动远程登录,登录跳板机
#!/usr/bin/expect set timeout 10 spawn ssh -p [lindex $argv 0] [lindex $argv 1]@[lindex $argv 2] exp ...
- Scala - error: not found: value SortedMap
先 IMPORT!!!! scala> import scala.collection._import scala.collection._ scala> SortedMap(" ...
- 负载均衡集群中的session解决方案
前言 在我们给Web站点使用负载均衡之后,必须面临的一个重要问题就是Session的处理办法,无论是PHP.Python.Ruby还是Java,只要使用服务器保存Session,在做负载均衡时都需要考 ...
- 记录创建企业Wiki的几个开源项目
很多著名的企业Wiki都是开源产品,如Foswiki(基于Perl),TWiki(基于Perl)等,另外有Mindtouch(基于PHP, C#),Confluence(基于Java)等.维基道的Wi ...
- linux-信号。
信号 信号是在软件层次上对中断机制的一种模拟,在原理上,一个进程收到一个信号与处理器收到一个中断请求可以说是一样的. 信号是异步的,一个进程不必通过任何操作来等待信号的到达,事实上,进程也不知道信号到 ...
- jquery 之效果
// jquery 之效果 .css()既可以获取值,如 .css('fontSize'), 又可以设置内置属性,既可用驼峰式,也可以用连字符版,如 .css('background-color', ...
- thinkPHP add、save无法添加、修改不起作用
案例:数据库新添加一字段,修改值不成功.解决方案:将Runtime/Data/_fields/下面的字段缓存删除,或者直接删除整个Runtime文件也是可以的分析:由于Thinkphp,采用字段缓存机 ...
- 发测试邮件或垃圾邮件node脚本
npm install nodemailer 执行后,指定目录下会出现node_modules模块,再相同目录下,创建main.js,js代码如下: var nodemailer = require( ...