hdu5596
来源:互联网 发布:网络用语:且是什么意思 编辑:程序博客网 时间:2024/04/27 20:59
题意
- n个人排成序列,每个人有类别ai(0或1),权值bi,一共n秒,第i秒,第i个人前面的很它类别不同,权值小于它的离开队伍。
- 另外,还有一些时间点,在这些时间点i后,前i个人bi加1,问最后队伍能剩几个人。
思路
- 倒着看序列,每次维护两种类别的最大值即可。
- 复杂度O(n)
- 注意时间点有可能重复。。。
实现
#include <iostream>#include <cstring>#include <cstdio>#include <algorithm>using namespace std;const int maxn = 50005;int sum[maxn];int b[maxn];int a[maxn];int main(){ int T; cin>>T; int n,m; while (T--){ cin>>n>>m; for (int i=1;i<=n;i++){ scanf("%d%d",&a[i],&b[i]); } memset(sum,0,sizeof(sum)); for (int i=0;i<m;i++){ int tmp; scanf("%d",&tmp); sum[tmp]++; } int v[2] = {0,0}; int ans = 0; int tot = 0; for (int i=n;i>0;i--){ tot += sum[i]; int j = (a[i] ^ 1); if (b[i] + tot >= v[j]){ ans++; } v[a[i]] = max(v[a[i]],b[i] + tot); } cout << ans <<"\n"; } return 0;}
0 0
- hdu5596
- 倒推 hdu5596 GTW likes gt
- 其实闭包并不高深莫测
- Sicily Shortest path in unweighted graph
- 1.linux运维系列写在最开始
- [iOS]Apple官方开源项目
- QEMU,KVM,QEMU-KVM,XEN,LIBVIRT的区别
- hdu5596
- coreseek 索引更新机制
- 【C++ STL应用与实现】目录
- LinearLayout布局
- 一起talk C栗子吧(第七十七回:C语言实例--DIY ls命令续)
- 20151219新的一天在小小的惊喜中开始
- 2016扁平化图标设计如何做太原UI设计师郭文军讲
- YII2.0 常用查询语句
- 浅析CSS——元素重叠及position定位的z-index顺序