HDOJ 5596-GTW likes gt【思维题】
来源:互联网 发布:淘宝上悦诗风吟专柜 编辑:程序博客网 时间:2024/05/16 14:12
GTW likes gt
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 1133 Accepted Submission(s): 403
Problem Description
Long long ago, there were n adorkable GT. Divided into two groups, they were playing games together, forming a column. Thei−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 form 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 then−th second.
In order to make the game more interesting, GTW, the leader of those GTs, would emit energy for
GTW wanted to know how many GTs would survive after the
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 aren+m+1 lines in the input file.
The first line of each test case contains 2 integersn and m , which indicate the number of GTs and the number of emitting energy, respectively.(1≤n,m≤50000)
In the followingn 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 followingm lines, the i−th line contains an integer ci , which indicates the time of emitting energy for i−th time.
For each test case, there are
The first line of each test case contains 2 integers
In the following
In the following
Output
There should be exactly T lines in the output file.
Thei−th line should contain exactly an integer, which indicates the number of GTs who survive.
The
Sample Input
14 30 31 20 31 1134
Sample Output
3HintAfter 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.
Source
BestCoder Round #66 (div.2)
解题思路:
从后向前查找,并且先用dv数组从后向前把每个人的增量都记录下来,最后遍历一下数组,并且维护0和1的最大值,从后向前原先的加上后来发功加的比最大值小的就会被干掉。
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;int dv[60000];struct node{int tamp;int gong;}wc[100000];int n,m; int main(){int t;scanf("%d",&t);while(t--){int i,j;scanf("%d%d",&n,&m);for(i=1;i<=n;i++){scanf("%d%d",&wc[i].tamp,&wc[i].gong);dv[i]=0;}dv[i+1]=0;for(i=1;i<=m;i++){int gg;scanf("%d",&gg);dv[gg]++;}for(i=n;i>=1;i--){dv[i]+=dv[i+1];}int mm1,mm2;int ans=0;mm1=-1,mm2=-1;for(i=n;i>=1;i--){if(wc[i].tamp==0){if(wc[i].gong+dv[i]>mm1)mm1=wc[i].gong+dv[i];if(wc[i].gong+dv[i]<mm2){ans++;}}else{if(wc[i].gong+dv[i]>mm2)mm2=wc[i].gong+dv[i];if(wc[i].gong+dv[i]<mm1){ans++;}}}printf("%d\n",n-ans);}return 0;}
0 0
- HDOJ 5596-GTW likes gt【思维题】
- HDOJ 5596 GTW likes gt 【思维 】
- hdoj 5596 GTW likes gt 【思维】
- HDOJ 5596 GTW likes gt(巧解)
- HDU 5596 GTW likes gt(逆向思维)
- hdu 5596 GTW likes gt(逆向思维)
- hdu 5596 GTW likes gt
- HDU 5596:GTW likes gt
- HDU 5596 GTW likes gt
- hdu 5596 GTW likes gt
- HDU - 5596 - GTW likes gt
- hdu 5596 GTW likes gt
- hdoj GTW likes gt 5596 (DP机智转换)好题
- HDU 5596 GTW likes gt 暴力~
- HDU 5596 GTW likes gt(multiset)
- HDU 5596 GTW likes gt 倒推
- BC66 GTW likes gt
- 杭电 HDU 5596 (详解)GTW likes gt(思维)
- 阿里云服务器运行VS2013项目问题-C++操作数据库
- Android Lollipop 新特性 - Palette
- 自己实现AtomicFloat的示例代码
- 冒泡法排序
- myeclipse反向机制生成javabean
- HDOJ 5596-GTW likes gt【思维题】
- 日期控件如何显示出时分秒
- c/c++静态区 常量区 栈 堆
- C#.NET扩展方法
- 数据结构——链表
- leetcode 每日一题 104. Maximum Depth of Binary Tree
- 第一篇博客-忽悠妹子的
- Chart.js
- GUISkin 自定义皮肤样式