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 ...
随机推荐
- 幻世(OurDream)2D图形引擎使用教程8——处理操作输入(2)
声明:本教程版权归Lizcst Software Lab所有,欢迎转载,但是转载必须保留本段声明文字,并注明文章来源:http://blog.csdn.net/kflizcst 谢谢合作! 今天的教程 ...
- Delphi体系内部的4种消息传递办法(Send,Post,Perform,Dispatch)
一.什么是消息? 消息是windows对应用程序发送的有关‘发生了某种事件’的通知.例如点击鼠标,调整窗口大小或键盘上按下一个键,都会引起windows发送一条消息到应用程序中去,去通知应用程序发生了 ...
- android设置eclipse中的自动提示功能
菜单window->Preferences->Java->Editor->Content Assist->Enable auto activation 选项要打上勾 (并 ...
- 基于visual Studio2013解决面试题之1409基数排序
题目
- display:inline-block的运用
在实习中做专题时,遇到的一个问题:建立一个宽度很长的一个页面,里面包含许多列.或许许多人认为直接设置float:left:不就行了 但是这个有一个问题,你必须把外面的div的宽度设置的很长已满足大于所 ...
- 图片组件——axure线框图部件库介绍
我们在后面的组件使用中,都统一使用"从部件区域拖拽图片组件到页面区域中" 1. 图片载入 1.1 将图片组件拖拽到页面区域 1.2 双击图片组件 1.3 选择合适图片,点击打开 1 ...
- 九度OnlineJudge之1018:统计同成绩学生人数
题目描述: 读入N名学生的成绩,将获得某一给定分数的学生人数输出. 输入: 测试输入包含若干测试用例,每个测试用例的格式为 第1行:N 第2行:N名学生的 ...
- Linux 二层协议架构组织
本文主要讲解了Linux 二层协议架构组织,使用的内核的版本是2.6.32.27 为了方便理解,本文采用整体流程图加伪代码的方式从内核高层面上梳理了Linux 二层协议架构组织,希望可以对大家有所帮助 ...
- hadoop拷贝文件时 org.apache.hadoop.ipc.RemoteException异常的解决
1.系统或hdfs是否有空间 2.datanode数是否正常 3.是否在safemode 4.防火墙关闭 5.配置方面 6.把NameNode的tmp文件清空,然后重新格式化NameNode
- ASP.NET - 禁用ViewState
默认情况下,ViewState是被启用的,比如提交表单后,表单中输入的值会自动保留.但是如果不需要保留,也可以将其禁用,这样可以节省资源. 下面3种方式就可以分别禁用某一个控件.某一个页面和整个应 ...