HDU 5596 GTW likes 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);
}
}
HDU 5596 GTW likes gt 倒推的更多相关文章
- HDU 5596 ——GTW likes gt——————【想法题】
GTW likes gt Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)To ...
- hdu 5596 GTW likes gt
题目链接: hdu 5596 题意不难懂(虽然我还是看了好久)大概就是说 n 个人排成一列,分成两组, 第 i 秒时第 i 个人会消灭掉前面比他 b[i] 值低的且和他不同组的人,c[i] 表示第 c ...
- HDU 5597 GTW likes function 打表
GTW likes function 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5596 Description Now you are give ...
- HDU 5597 GTW likes function 欧拉函数
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5597 题意: http://bestcoder.hdu.edu.cn/contests/contes ...
- Hdu 5595 GTW likes math
题意: 问题描述 某一天,GTW听了数学特级教师金龙鱼的课之后,开始做数学<从自主招生到竞赛>.然而书里的题目太多了,GTW还有很多事情要忙(比如把妹),于是他把那些题目交给了你.每一道题 ...
- hdu 5595 GTW likes math(暴力枚举查询)
思路:直接暴力枚举区间[l,r]的整数值,然后max和min就可以了. AC代码: #pragma comment(linker, "/STACK:1024000000,1024000000 ...
- HDU 5596/BestCoder Round #66 (div.2) GTW likes math 签到
GTW likes math Memory Limit: 131072/131072 K (Java/Others) 问题描述 某一天,GTW听了数学特级教师金龙鱼的课之后,开始做数学<从自主 ...
- hdu-5596 GTW likes gt(模拟+优先队列)
题目链接: GTW likes gt Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Othe ...
- TYVJ P1034 尼克的任务 Label:倒推dp
背景 题库靠大家,人人都爱它. 描述 尼克每天上班之前都连接上英特网,接收他的上司发来的邮件,这些邮件包含了尼克主管的部门当天要完成的全部任务,每个任务由一个开始时刻与一个持续时间构成.尼克的一个工作 ...
随机推荐
- linux中ulimit作用
一.作用 Linux对于每个用户,系统限制其最大进程数.为提高性能,可以根据设备资源情况,设置各linux 用户的最大进程数. ulimit主要是用来限制进程对资源的使用情况的,它支持各种类型的限制, ...
- Linux CPU相关信息查看
linux 下查看机器是cpu是几核的 几个cpu more /proc/cpuinfo |grep "physical id"|uniq|wc -l 每个cpu是几核(假设cpu ...
- 【转】Bellman_ford算法
原文链接:http://www.cnblogs.com/Jason-Damon/archive/2012/04/21/2460850.html 摘自百度百科 Bellman-ford算法是求含负权图的 ...
- Slideout吐槽
前言: 今天有点事,只尝试做一个侧边栏.SlideOut一个侧边栏,对着github,ReadMe看,并尝试着写了.还不错,关键是当与bootstrap一起时,什么效果都没了, 这是什么情况,明天想再 ...
- PYTHON压平嵌套列表
list 是 Python 中使用最频繁的数据类型, 标准库里面有丰富的函数可以使用.不过,如果把多维列表转换成一维列表(不知道这种需求多不多),还真不容易找到好用的函数,要知道Ruby.Mathem ...
- 20151227感知机(perceptron)
1 感知机 1.1 感知机定义 感知机是一个二分类的线性分类模型,其生成一个分离超平面将实例的特征向量,输出为+1,-1.导入基于误分类的损失函数,利用梯度下降法对损失函数极小化,从而求得此超平面,该 ...
- 桶排序-OC
NSArray * b = @[@,@,@,@,@]; NSMutableArray *a = @[].mutableCopy; ; i<; i++) { a[i] = @; } for (NS ...
- ipython, 一个 python 的交互式 shell,比默认的python shell 好用得多,支持变量自动补全,自动缩进,支持 bash shell 命令,内置了许多很有用的功能和函数
一个 python 的交互式 shell,比默认的python shell 好用得多,支持变量自动补全,自动缩进,支持 bash shell 命令,内置了许多很有用的功能和函数. 若用的是fish s ...
- Openstack之Swift架构(Cloud Storage)
Swift是OpenStack的子项目之一,也称为对象储存,适用于储存永久类型的静态数据,例如:虚拟机镜像文件.图片.存档备份等 复制的三个副本如何联系在一起? 让我们用一些具体场景和介绍一些组件,来 ...
- JVM内存的那些事
前言 对于C语言开发的程序员来说,在内存管理方面,必须负责每一个对象的生命周期,从有到无. 对于Java程序员你来说,在虚拟机内存管理的帮助下,不需要为每个new对象都匹配free操作,内存泄露和内存 ...