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

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

2012 ACM/ICPC Asia Regional Changchun Online

Recommend

liuyiding   |   We have carefully selected several similar problems for you:  4272 4277 4273 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's Work(水题)

时间: 2024-11-03 05:40:08

hdu 4274 Spy's Work(水题)的相关文章

hdu 4274 Spy&amp;#39;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 Problem Description I'm a manager of a large trading company, called ACM, and responsible for the

HDU 4274 Spy&#39;s Work (树形DP,模拟)

题意: 给定一棵树,每个节点代表一个员工,节点编号小的级别就小,那么点1就是boss了.接下来给出对m个点的限制,有3种符号分别是op=“大于/小于/等于”,表示以第i个点为根的子树所有人的工资之和 大于/小于/等于 x,要求判断m个限制是否冲突了.注意每个员工的工资下限是1,而无上限.ps:可能出现对同个点多个限制,注意取交集. 思路: 很水的题嘛,想复杂了.注意限制是针对整棵子树的!所以我们只需要算出这棵子树的范围,再判断是否和所给的限制有冲突,如果没有冲突的话还得取“所给限制”与“计算出的

hdu 1999 不可摸数 水题。

不可摸数 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 7966    Accepted Submission(s): 2024 Problem Description s(n)是正整数n的真因子之和,即小于n且整除n的因子和.例如s(12)=1+2+3+4+6=16.如果任何数m,s(m)都不等于n,则称n为不可摸数. Input 包

Hdu 4274 Spy&#39;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 Problem Description I'm a manager of a large trading company, called ACM, and responsible for the

HDU Senior&#39;s Gun (水题)

题意:给n把枪,m个怪兽,每把枪可消灭1怪兽,并获得能量=枪的攻击力-怪兽的防御力.求如何射杀能获得最多能量?(不必杀光) 思路:用最大攻击力的枪杀防御力最小的怪兽明显可获得最大能量.如果每把枪都去射杀刚好1点能量都拿不到的怪物,那简直等于把枪全丢掉. 1 //#pragma comment(linker,"/STACK:102400000,102400000") 2 #include <iostream> 3 #include <stdio.h> 4 #inc

Hdu 4274 Spy&amp;#39;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 Problem Description I'm a manager of a large trading company, called ACM, and responsible for the

HDU 5590 ZYB&#39;s Biology 水题

ZYB's Biology Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5590 Description ZYB(ZJ−267)在NOIP拿到600分之后开始虐生物题,他现在扔给你一道简单的生物题:给出一个DNA序列和一个RNA序列,问它们是否配对. DNA序列是仅由A,C,G,T组成的字符串,RNA序列是仅由A,C,G,U组成的字符串. DNA和RNA匹配当且仅当每

hdu 4847 Wow! Such Doge! 水题

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4847 统计文本中一共有多少个“Doge” 水题 #include <cstring> #include <cstdlib> #include <cstring> #include <cmath> #include <algorithm> #include <iostream> #include <cstdio> #includ

HDU 5578 Friendship of Frog 水题

Friendship of Frog Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5578 Description N frogs from different countries are standing in a line. Each country is represented by a lowercase letter. The distance betwee