博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu 4274 Spy's Work(水题)
阅读量:7145 次
发布时间:2019-06-29

本文共 3657 字,大约阅读时间需要 12 分钟。

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
Problem Description
I'm a manager of a large trading company, called ACM, and responsible for the market research. Recently, another trading company, called ICPC, is set up suddenly. It's obvious that we are the competitor to each other now!
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!
 
Input
There are multiple test cases.
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)
 
Output
For each test case, output "True" if the information has no confliction; otherwise output "Lie".
 
Sample Input
 
5 1 1 3 3 3 1 < 6 3 = 4 2 = 2 5 1 1 3 3 3 1 > 5 3 = 4 2 = 2
 
Sample Output
 
Lie True
 
Source
 
Recommend
liuyiding   |   We have carefully selected several similar problems for you:            
 
题意:
给你一棵树。

然后告诉你某棵子树权值和的范围。然后问你有没有矛盾。

思路:
每一个结点维护两个值ns[i],nb[i]存当前子树的权值范围ns[i]<=val<=nb[i]从儿子到父亲一层一层更新父亲的范围。中间推断下是否冲突。
具体见代码:
#include
#include
#include
#include
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;}

转载地址:http://rxgrl.baihongyu.com/

你可能感兴趣的文章
linux rehat 9.0 系统基本操作/命令
查看>>
Android MediaPlayer各个状态和错误详情
查看>>
linux排优命令
查看>>
iptables学习笔记
查看>>
网络工程师的爱情...
查看>>
struts2
查看>>
ZOJ - 3981 - Balloon Robot (思维)
查看>>
s:property 获取 ValueStack中的值
查看>>
String.replace
查看>>
一次性事务和CTE插入数据的比较
查看>>
RHEL6基础之一系统内核Kernel与GNU计划及Linux发行版本
查看>>
网络问题真的很怪
查看>>
Calendar日历类和GregorianCalendar公历类用法的一个小结
查看>>
NoSQL -- php应用redis、mongodb
查看>>
Nginx 配置全解析(一)
查看>>
java中的URLEncoder和URLDecoder类的联系与区别
查看>>
我的友情链接
查看>>
Redis 连接池配置及redis操作
查看>>
MDT2012/13功能测试(1)—向MDT工作台添加资源
查看>>
NFS文件系统
查看>>