hdu 4274 Spy's Work(水题)
Spy's Work
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1266 Accepted Submission(s): 388
To get some information about ICPC, I have learned a lot about it. ICPC has N staffs now (numbered from 1 to N, and boss is 1), and anybody has at most one superior. To increase the efficiency of the whole company, the company contains N departments and the
ith department is led by the ith staff. All subordinates of the ith staff are also belong to the ith department.
Last week, we hire a spy stealing into ICPC to get some information about salaries of staffs. Not getting the detail about each one, the spy only gets some information about some departments: the sum of the salaries of staff s working for the ith department
is less than (more than or equal to) w. Although the some inaccurate information, we can also get some important intelligence from it.
Now I only concerned about whether the spy is telling a lie to us, that is to say, there will be some conflicts in the information. So I invite you, the talented programmer, to help me check the correction of the information. Pay attention, my dear friend,
each staff of ICPC will always get a salary even if it just 1 dollar!
The first line is an integer N. (1 <= N <= 10,000)
Each line i from 2 to N lines contains an integer x indicating the xth staff is the ith staff's superior(x<i).
The next line contains an integer M indicating the number of information from spy. (1 <= M <= 10,000)
The next M lines have the form like (x < (> or =) w), indicating the sum of the xth department is less than(more than or equal to) w (1 <= w <=100,000,000)
5
1
1
3
3
3
1 < 6
3 = 4
2 = 2 5
1
1
3
3
3
1 > 5
3 = 4
2 = 2
Lie
True
pid=4273" target="_blank">4273
pid=4270" target="_blank">4270
4269然后告诉你某棵子树权值和的范围。然后问你有没有矛盾。
#include<algorithm>
#include<iostream>
#include<string.h>
#include<stdio.h>
using namespace std;
const int maxn=10010;
typedef long long ll;
const ll INF=1e14;
int fa[maxn];
ll ns[maxn],nb[maxn],sz[maxn],ss[maxn],sb[maxn];
int main()
{
int n,i,x,m,w,flag;
char op[10]; while(~scanf("%d",&n))
{
fa[1]=flag=0;
for(i=1;i<=n;i++)
{
sz[i]=1;
ns[i]=-INF,nb[i]=INF;
ss[i]=sb[i]=0;
}
for(i=2;i<=n;i++)
{
scanf("%d",&x);
fa[i]=x;
}
scanf("%d",&m);
for(i=1;i<=m;i++)
{
scanf("%d%s%d",&x,op,&w);
if(op[0]=='=')
nb[x]=ns[x]=w;
else if(op[0]=='<')
nb[x]=min(nb[x],(ll)w-1);
else
ns[x]=max(ns[x],(ll)w+1);
}
for(i=n;i>=1;i--)
{
if(flag)
break;
ns[i]=max(ns[i],sz[i]);
if(ns[i]>nb[i]||nb[i]<=ss[i])
flag=1;
ns[i]=max(ns[i],ss[i]+1);
if(ns[i]>nb[i])
flag=1;
sz[fa[i]]+=sz[i];
ss[fa[i]]+=ns[i];
sb[fa[i]]+=nb[i];
}
if(flag)
printf("Lie\n");
else
printf("True\n");
}
return 0;
}
hdu 4274 Spy's Work(水题)的更多相关文章
- Hdu 4274 Spy's Work
Spy's Work Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- HDU 2096 小明A+B --- 水题
HDU 2096 /* HDU 2096 小明A+B --- 水题 */ #include <cstdio> int main() { #ifdef _LOCAL freopen(&quo ...
- [HDU 2602]Bone Collector ( 0-1背包水题 )
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 水题啊水题 还给我WA了好多次 因为我在j<w[i]的时候状态没有下传.. #includ ...
- hdu 2117:Just a Numble(水题,模拟除法运算)
Just a Numble Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- hdu 2050:折线分割平面(水题,递归)
折线分割平面 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- hdu 2044:一只小蜜蜂...(水题,斐波那契数列)
一只小蜜蜂... Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Submission(s): Accepte ...
- HDU 4706 Children's Day (水题)
Children's Day Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- hdu 1201:18岁生日(水题,闰年)
18岁生日 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...
- hdu 2025:查找最大元素(水题,顺序查找)
查找最大元素 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
随机推荐
- ASP.NET - 无限极分类
下拉列表-------- 数据库设计: -- 无限分类 -- -- 数据库:DB_InfiniteCategory -- 数据表:Tb_Infinite ----------------------- ...
- 新发现的Cyberduck(映射网盘)和zsuncloud(硬件产品很新潮),群辉nas的确好用(购买链接)
https://cyberduck.io/?l=en http://www.zsuncloud.com/ 群辉nas的确好用啊在哪里可以买到?官网 淘宝也可以自己做黑群晖 先用xpenoboot is ...
- perl post发送json数据
sub wx_init { #$login_url ="https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxinit?r=- ...
- G - Self Numbers(2.2.1)
G - Self Numbers(2.2.1) Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & % ...
- C++学习之路—继承与派生(三):多重继承与虚基类
(根据<C++程序设计>(谭浩强)整理,整理者:华科小涛,@http://www.cnblogs.com/hust-ghtao转载请注明) 多重继承是指一个派生类有两个或多个基类.例如,有 ...
- CSipSimple最新版本号
要使用CSipSimple有两种方法:第一种是不编译jni,另外一种是编译jni. 这里介绍的是第一种:不编译jni. 首先,用SVNclient检出CSipSimple源代码:svn checkou ...
- android中,如果使用imageButton可以在drawable 中设置一个selector,但是imageView设置不起作用
android中,如果使用imageButton可以在drawable 中设置一个selector,但是imageView设置不起作用,只要把Imageview的src给去掉就成了,src捕获了bac ...
- 用Stack实现对多线程的管理范例
多线程就是并发技术,当线程数量超过一定数量时,系统响应就会变慢,所以就必须对线程数量进行控制,那么采用哪种控制方法呢?采用Stack类模仿堆栈,之所以说是模仿,就是因为Stack类毕竟不是真实的堆栈, ...
- AJAX入门---DOM操作HTML
AJAX入门---DOM操作HTML 一边学习AJAX一边坐着总结加深印象.上次写的是怎样简单的使用XMLHttpRequest对象.今天写的是DOM(文档对象模型(Document Object M ...
- 搭建实时同步data guard的最高可用-切换主备
搭建实时同步data guard的最高可用-切换主备 首先保证主库在归档模式下:错过N次了 准备二台机器(hostname gw hosts ech0)host-only [root@node1 ~] ...