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:  4272 4277 

pid=4273" target="_blank">4273 

pid=4270" target="_blank">4270 4269 

 题意:
给你一棵树。

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

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

  1. Hdu 4274 Spy&#39;s Work

    Spy's Work Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  2. HDU 2096 小明A+B --- 水题

    HDU 2096 /* HDU 2096 小明A+B --- 水题 */ #include <cstdio> int main() { #ifdef _LOCAL freopen(&quo ...

  3. [HDU 2602]Bone Collector ( 0-1背包水题 )

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 水题啊水题 还给我WA了好多次 因为我在j<w[i]的时候状态没有下传.. #includ ...

  4. hdu 2117:Just a Numble(水题,模拟除法运算)

    Just a Numble Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

  5. hdu 2050:折线分割平面(水题,递归)

    折线分割平面 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Subm ...

  6. hdu 2044:一只小蜜蜂...(水题,斐波那契数列)

    一只小蜜蜂... Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Submission(s): Accepte ...

  7. HDU 4706 Children's Day (水题)

    Children's Day Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  8. hdu 1201:18岁生日(水题,闰年)

    18岁生日 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submi ...

  9. hdu 2025:查找最大元素(水题,顺序查找)

    查找最大元素 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Subm ...

随机推荐

  1. Java基础11 对象引用

    链接地址:http://www.cnblogs.com/vamei/archive/2013/04/01/2992484.html 作者:Vamei 出处:http://www.cnblogs.com ...

  2. fullcalendar日历控件知识点集合

    1.基本的语法: 首先,fullcalendar和JQUERY一样,以面向对象的方式来组织代码.当然,这里的面向对象不过指能够把整个fullcalendar理解为一个类,这个类里包含有非常多的属性.方 ...

  3. HTML5 Canvas自定义圆角矩形与虚线(Rounded Rectangle and Dash Line)

    HTML5 Canvas自定义圆角矩形与虚线(RoundedRectangle and Dash Line) 实现向HTML Canvas 2d context绘制对象中添加自定义的函数功能演示,如何 ...

  4. sharepoint具体错误提示

    sharepoint页面发生错误时,默认不会显示具体错误信息,只显示“未知错误”提示.需要修改配置站点的webconfig文件,才能显示出具体错误提示.具体方法如下: 将safeMode中的CallS ...

  5. Ajax - 手册

    一.Ajax概述:    1.Ajax(Asynchronous JavaScript and XML):异步的JavaScript和XML    2.Ajax不是某种语言,而是在现实网页的时候一种局 ...

  6. PHP学习之-数据库操作

    PHP学习之-数据库操作 1.PHP支持那些数据库 PHP通过安装相应的扩展来实现数据库操作,现代应用程序的设计离不开数据库的应用,当前主流的数据库有MsSQL,MySQL,Sybase,Db2,Or ...

  7. webview加载网页加载不出来

    1.webView.loadUrl(picTargetUrl); 写在最前面. 1.在无线城市迷你版的项目,用webview去loadUrl的时候出现加载的现象. url 地址是 http://go. ...

  8. OS X 10.10 Yosemite Beta能够下载了

    刚刚启动迅雷.蹦出一消息.点击后出现-- watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdmlzdGE5OTk5OQ==/font/5a6L5L2T/fon ...

  9. Python中的列表解析和生成表达式

    摘要:优雅.清晰和务实都是python的核心价值观,如果想通过操作和处理一个序列(或其他的可迭代对象)来创建一个新的列表时可以使用列表解析( List comprehensions)和生成表达式,通过 ...

  10. JQuery+AJax - 无刷新使用验证码

    最终效果: 项目目录: Default.aspx前端代码: <%@ Page Language="C#" AutoEventWireup="true" C ...