HDU 5596 GTW likes gt 倒推

探讨了在特定游戏规则下,GT群体的生存策略,通过能力值对比和能量释放,计算最终存活个体数量。

GTW likes gt

题目连接:

http://acm.hdu.edu.cn/showproblem.php?pid=5596

Description

Long long ago, there were n adorkable GT. Divided into two groups, they were playing games together, forming a column. The i−th GT would randomly get a value of ability bi. At the i−th second, the i−th GT would annihilate GTs who are in front of him, whose group differs from his, and whose value of ability is less than his.

In order to make the game more interesting, GTW, the leader of those GTs, would emit energy for m times, of which the i−th time of emitting energy is ci. After the ci second, b1,b2,...,bci would all be added 1.

GTW wanted to know how many GTs would survive after the n−th second.

Input

The first line of the input file contains an integer T(≤5), which indicates the number of test cases.

For each test case, there are n+m+1 lines in the input file.

The first line of each test case contains 2 integers n and m, which indicate the number of GTs and the number of emitting energy, respectively.(1≤n,m≤50000)

In the following n lines, the i−th line contains two integers ai and bi, which indicate the group of the i−th GT and his value of ability, respectively. (0≤ai≤1,1≤bi≤106)

In the following m lines, the i−th line contains an integer ci, which indicates the time of emitting energy for i−th time.

Output

There should be exactly T lines in the output file.

The i−th line should contain exactly an integer, which indicates the number of GTs who survive.

Sample Input

1

4 3

0 3

1 2

0 3

1 1

1

3

4

Sample Output

3

Hint

题意

从前,有n只萌萌的GT,他们分成了两组在一起玩游戏。他们会排列成一排,第i只GT会随机得到一个能力值bi。

在第i秒的时候,第ii只GT可以消灭掉所有排在他前面的和他不是同一组的且能力值小于他的GT。

为了使游戏更加有趣,GT的首领GTW会发功m次,第ii次发功的时间为ci,则在第ci秒结束后,b1,b2,...,bci都会增加1。

现在,GTW想知道在第n秒之后,会有几只GT存活下来。

题解:

倒着做

首先我们倒着做.

倒着做就可以只由后面的最大值所影响了。

所以,记录分别1组此时的最大值和0组的此时最大值。

然后扫一遍就好了。

代码

#include<iostream>
#include<stdio.h>
#include<cstring>
using namespace std;

#define maxn 1000005
struct node
{
    int x,y;
}A[maxn];
int n,m;
int Time[maxn];
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        memset(Time,0,sizeof(Time));
        memset(A,0,sizeof(A));
        scanf("%d%d",&n,&m);
        for(int i=1;i<=n;i++)
            scanf("%d%d",&A[i].x,&A[i].y);
        for(int i=1;i<=m;i++)
        {
            int x;scanf("%d",&x);
            Time[x]++;
        }
        int Max[3];
        Max[0]=Max[1]=0;
        int ans=0;
        int tot=0;
        for(int i=n;i>=1;i--)
        {
            tot+=Time[i];
            A[i].y+=tot;
            if(Max[A[i].x^1]>A[i].y)
                ans++;
            Max[A[i].x]=max(A[i].y,Max[A[i].x]);
        }
        printf("%d\n",n-ans);
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值