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): 1324 Accepted Submission(s): 415
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
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <string>
#include <map>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <set>
#include <queue> using namespace std; typedef long long ll;
const ll INF=1e16;
const int maxn=1e4+5; struct T {
ll l;
ll r;
};
T range[maxn];
vector<int> g[maxn]; int n; void inti() {
for(int i=1; i<=n; i++) {
g[i].clear();
range[i].l=1;
range[i].r=INF;
}
} bool dfs(int u) {
if(g[u].size()==0)
return true;
ll l=1;///左区间的最小值,初始化为1,右区间不用更新
for(int i=0; i<g[u].size(); i++) {
int v=g[u][i];
bool res=dfs(v);
if(res==false)
return false;
l+=range[v].l;
if(l>range[u].r)
return false;
}
range[u].l=max(range[u].l,l);///更新
return true;
} int main() {
while(~scanf("%d",&n)) {
inti();
for(int i=2; i<=n; i++) {
int x;
scanf("%d",&x);
g[x].push_back(i);
}
int m;
scanf("%d",&m);
bool res=true;
for(int i=1; i<=m; i++) {
int ith,x;
char c;
scanf("%d %c %d",&ith,&c,&x);
if(c=='=') { ///等于的情况。左右区间都为x
if(x<range[ith].l||x>range[ith].r)///不符合
res=false;
range[ith].l=x;
range[ith].r=x;
} else if(c=='<') { ///小于的情况更新有区间
if(range[ith].l>=x)
res=false;
range[ith].r=x-1;
} else { ///大于的情况更新左区间
if(range[ith].r<=x)
res=false;
range[ith].l=x+1;
}
}
if(res) {
res=dfs(1);
}
if(res==true)
puts("True");
else
puts("Lie");
}
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 4274 Spy's Work (树 DFS)
给定N个点,每个点都有一个唯一的前驱结点(点1为大boss),每个点的实际权值是子节点的求和值.现在给出某些点的权值的估算(> , = , < ),问这些估算是否会有冲突,现在保证每个点的 ...
- HDU 4274 Spy's Work (树形DP)
题意 给定一棵树,给出一些子树的权值关系,问是否矛盾(初始所有结点的下限为1) 思路 设lmin和lmax表示题目给定的限制范围,默认为[1..oo]:amin和amax表示实际符合要求的范围.从根节 ...
- HDU 4274 Spy's Work (树形DP,模拟)
题意: 给定一棵树,每个节点代表一个员工,节点编号小的级别就小,那么点1就是boss了.接下来给出对m个点的限制,有3种符号分别是op=“大于/小于/等于”,表示以第i个点为根的子树所有人的工资之和 ...
- hdu 3966 Aragorn's Story(树链剖分+树状数组)
pid=3966" target="_blank" style="">题目链接:hdu 3966 Aragorn's Story 题目大意:给定 ...
- HDU 3966 Aragorn's Story(树链剖分)
HDU Aragorn's Story 题目链接 树抛入门裸题,这题是区间改动单点查询,于是套树状数组就OK了 代码: #include <cstdio> #include <cst ...
- hdu 5282 Senior's String 两次dp
题链:http://acm.hdu.edu.cn/showproblem.php?pid=5282 Senior's String Time Limit: 2000/1000 MS (Java/Oth ...
- HDU 3177 Crixalis's Equipment(贪婪)
主题链接:http://acm.hdu.edu.cn/showproblem.php? pid=3177 Problem Description Crixalis - Sand King used t ...
- HDU - 5186 - zhx's submissions (精密塔尔苏斯)
zhx's submissions Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
随机推荐
- I/O输入系统
I/O输入系统 计算机有两个主要任务:I/O操作与计算处理.在许多情况下,主要任务是I/O操作.而计算处理只是附带的. 操作系统在计算机I/O方面的作用是管理和控制I/O操作和I/O设备. 概述 对与 ...
- 100个直接可以拿来用的JavaScript实用功能代码片段(转)
把平时网站上常用的一些实用功能代码片段通通收集起来,方面网友们学习使用,利用好的话可以加快网友们的开发速度,提高工作效率. 目录如下: 1.原生JavaScript实现字符串长度截取2.原生JavaS ...
- 【Luogu】P1383高级打字机
可持久化线段树模板题之一. 权当温习主席树模板 #include<cstdio> #include<cstdlib> #include<cctype> #defin ...
- 阐述struts2的执行流程。
Struts 2框架本身大致可以分为3个部分:核心控制器FilterDispatcher.业务控制器Action和用户实现的企业业务逻辑组件. 核心控制器FilterDispatcher是Struts ...
- cf493E Vasya and Polynomial
Vasya is studying in the last class of school and soon he will take exams. He decided to study polyn ...
- Bat命令学习 (转载)
基础部分:====================================================================== 一.基础语法: 1.批处理文件是一个“.bat” ...
- 洛谷P2677 超级书架 2
题目描述 Farmer John最近为奶牛们的图书馆添置了一个巨大的书架,尽管它是如此的大,但它还是几乎瞬间就被各种各样的书塞满了.现在,只有书架的顶上还留有一点空间. 所有N(1 <= N & ...
- HDU 4803 Poor Warehouse Keeper (贪心+避开精度)
555555,能避开精度还是避开精度吧,,,,我们是弱菜.. Poor Warehouse Keeper Time Limit: 2000/1000 MS (Java/Others) Memor ...
- poj 3083 dfs,bfs
传送门 Children of the Candy Corn Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I6 ...
- 在ScrollView添加一个ListView造成的滚动问题的简单解决办法()
正常来说,在ScrollView添加一个ListView后在真机上只会显示ListView的一行多一点,我也不理解为什么会这样,后来我把ListView的layout_height改成400dip,而 ...