HDOJ 5596 GTW likes gt(巧解)
来源:互联网 发布:spss数据分析报告模板 编辑:程序博客网 时间:2024/04/30 00:48
GTW likes gt
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 324 Accepted Submission(s): 113
Problem Description
Long long ago, there weren 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 integerT(≤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.
题意:有n个GT排成一列,被分成两组,每个GT都会随机拥有bi点能量,到第i秒时第i个GT要消灭掉排在他前面的且与他不是一个组的比他能量低的GT。为了游戏更有意思,GT族的酋长会发功m次,第i次发功在ci秒,第ci秒结束后, b1,b2,b3....bci都会增加1。 问第n秒后,还有几个GT。
题解:O(n*n)的傻瓜方法果断错了,比赛结束后看了OI爷的代码,学了一发O(n)法。从GT数列的最后端开始考虑,先将酋长在整个过程中给每个GT的能量全加上。然后从数列尾端开始将当前GT与最大值比较,大于最大值就表示能存活下来,然后更新最大值。
代码如下:
#include<cstdio> #include<cstring>#include<algorithm>using namespace std;int a[50010],b[50010],s[50010];int main(){int n,m,i,c,t;scanf("%d",&t);while(t--){scanf("%d%d",&n,&m);for(i=1;i<=n;++i)scanf("%d%d",&a[i],&b[i]);memset(s,0,sizeof(s));for(i=0;i<m;++i){scanf("%d",&c);s[c]++;}for(i=n;i;--i)//越向前增加的能量越多{s[i]+=s[i+1];b[i]+=s[i];}int ans=0;int max1=-1,max2=-1;for(i=n;i;--i){if(!a[i]){if(max2<=b[i])ans++;max1=max(max1,b[i]);}else{if(max1<=b[i])ans++;max2=max(max2,b[i]);}}printf("%d\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(multiset)
- HDU 5596 GTW likes gt 倒推
- BC66 GTW likes gt
- hdoj GTW likes gt 5596 (DP机智转换)好题
- HDOJ 5596 GTW likes gt (线段树区间更新+单点查询+技巧)
- BC #66 GTW likes gt
- 倒推 hdu5596 GTW likes gt
- 使用ActionBar和DrawerLayout纯原生控件,实现侧滑栏和滑动Tab界面
- Java Notes-7
- 可旋转的汽车3D模型效果的实现
- About netstat commnd
- 2015-12-12 java hibernate 微信表情昵称保存
- HDOJ 5596 GTW likes gt(巧解)
- Python学习笔记-6(类、胡乱写)
- Java Notes-8
- 我们要友好的告诉用户,程序要崩溃了
- Java Notes-9
- Java Notes-10
- 如何保证Android与服务器的DES加密保持一致
- Android Development Notes -1
- iOS 中KVC、KVO、NSNotification、delegate 总结及区别