HDU 5596 ——GTW likes gt——————【想法题】
GTW likes gt
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 833 Accepted Submission(s): 299
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.
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.
The i−th line should contain exactly an integer, which indicates the number of GTs who survive.
After the first seconds,$b_1=4,b_2=2,b_3=3,b_4=1$
After the second seconds,$b_1=4,b_2=2,b_3=3,b_4=1$
After the third seconds,$b_1=5,b_2=3,b_3=4,b_4=1$,and the second GT is annihilated by the third one.
After the fourth seconds,$b_1=6,b_2=4,b_3=5,b_4=2$
$c_i$ is unordered.
题目大意:有n个gt(认为是一种动物),每个有一个法力值b[i],有0,1两个组,在第i秒的时候,第i只gt可以消灭前面不跟他一组且法力值小于他的gt。有一个巫师,发m次功,在c[i]秒的时候发功,在第c[i]秒结束后,b[i],b[2]...b[c[i]]都会增加1。问你最后活下来的有多少只gt。
解题思路:倒着处理,首先预处理出来第i秒时第i只gt的法力值增量dv[i]。然后维护每组当前的最大法力值Max。对于每只gt,我们判断他跟另外一组最大法力值的关系,同时维护该组的最大法力值。
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e6+2000;
struct GT{
int group,val;
}gts[maxn];
int dv[maxn], b[maxn];
int main(){
int T,n,m;
scanf("%d",&T);
while(T--){
scanf("%d%d",&n,&m);
for(int i = 1;i <= n; i++){
scanf("%d%d",>s[i].group,>s[i].val);
dv[i] = 0;
}
dv[n+1] = 0;
for(int i = 1;i <= m; i++){
scanf("%d",&b[i]);
dv[b[i]]++;
}
for(int i = n; i >= 1; i--){
dv[i] += dv[i+1];
}
int Max0 = -1, Max1 = -1, ans = 0;
for(int i = n; i >= 1; i--){
if(gts[i].group == 1){
if(gts[i].val + dv[i] < Max0){
ans++;
}
if(gts[i].val + dv[i] > Max1){
Max1 = gts[i].val + dv[i];
}
}else{
if(gts[i].val + dv[i] < Max1){
ans++;
}
if(gts[i].val + dv[i] > Max0){
Max0 = gts[i].val + dv[i];
}
}
}
printf("%d\n",n-ans);
}
return 0;
}
HDU 5596 ——GTW likes gt——————【想法题】的更多相关文章
- HDU 5596 GTW likes gt 倒推
GTW likes gt 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5596 Description Long long ago, there w ...
- 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 - 5806 NanoApe Loves Sequence Ⅱ 想法题
http://acm.hdu.edu.cn/showproblem.php?pid=5806 题意:给你一个n元素序列,求第k大的数大于等于m的子序列的个数. 题解:题目要求很奇怪,很多头绪但写不出, ...
- HDU 4972 Bisharp and Charizard 想法题
Bisharp and Charizard Time Limit: 1 Sec Memory Limit: 256 MB Description Dragon is watching NBA. He ...
- HDU - 5969 最大的位或 想法题
http://acm.hdu.edu.cn/showproblem.php?pid=5969 (合肥)区域赛签到题...orz 题意:给你l,r,求x|y的max,x,y满足l<=x<=y ...
- Hdu 5595 GTW likes math
题意: 问题描述 某一天,GTW听了数学特级教师金龙鱼的课之后,开始做数学<从自主招生到竞赛>.然而书里的题目太多了,GTW还有很多事情要忙(比如把妹),于是他把那些题目交给了你.每一道题 ...
- HDU 5632 Rikka with Array [想法题]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5632 ------------------------------------------------ ...
- HDU 5597 GTW likes function 欧拉函数
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5597 题意: http://bestcoder.hdu.edu.cn/contests/contes ...
随机推荐
- IIS部署SSL,.crt .key 的证书,怎么部署到IIS
SSL连接作用不说,百度很多.因为最近想考虑重构一些功能,在登录这块有打算弄成HTTPS的,然后百度了,弄成了,就记录一下,以便以后万一部署的时候忘记掉. 做实验的时候,拿的我个人申请的已经备案的域名 ...
- C# LINQ(3)
我们还是接着讨论一下group by 这一章节讨论group的本质:分组. 分组之后进行存储或者查询. 这个时候就要用一个新的关键字:into 这个之后就group就不作为结尾了. 必须重写另起sel ...
- Tensorflow报错:InvalidArgumentError: You must feed a value for placeholder tensor 'input_y' with dtype
此错误神奇之处是每次第一次运行不会报错,第二次.第三次第四次....就都报错了.关掉重启,又不报错了,运行完再运行一次立马报错!搞笑! 折磨了我半天,终于被我给解决了! 问题解决来源于这边博客:htt ...
- zookeeper安装和使用 windows
的 Zookeeper 是以 3.4.5 这个稳定版本为基础,最新的版本可以通过官网 http://hadoop.apache.org/zookeeper/来获取,Zookeeper 的安装非常简单, ...
- Flink应用场景
本文为<Flink大数据项目实战>学习笔记,想通过视频系统学习Flink这个最火爆的大数据计算框架的同学,推荐学习课程: Flink大数据项目实战:http://t.cn/EJtKhaz ...
- 将0移到最后,在原数组操作,并且不能改变源数据顺序(JS编程)
一.问题描述: 将0移到最后,在原数组操作,并且不能改变源数据顺序. 示例:输入:[2,0,0,1,0,3], 结果:[2,1,3,0,0,0] 二.问题分析与解决: 注意是在原数组上操作,不要进行 ...
- redis原理及实现
1 什么是redis redis是nosql(也是个巨大的map) 单线程,但是可处理1秒10w的并发(数据都在内存中) 使用java对redis进行操作类似jdbc接口标准对mysql,有各类实现他 ...
- ubuntu设置静态 ip
查看ip和DNS 终端输入ifconfig获取ip,子网掩码.输入nm-tool获取网关,DNS 修改配置文件/etc/network/interfaces root@ubuntu:~# sudo g ...
- MySQL 安装 linux ,window 傻瓜版
现在作为服务器操作系统的一般有三种,Windows Server,Linux,Unix,在这里我们只介绍在windows下和linux下安装mysql,Unix下安装应该和linux差不多. Wind ...
- 167 Two Sum-Input array is sorted, 125 Valid Palindrome,344
注意这两个元素不能是相同的. 解法一:二分查找法,逐一取数组中的值,然后second = target - numbers[i] , 用二分查找法求第二个值. 时间复杂度:O(nlongn) clas ...