【bzoj 1029】 [JSOI2007]建筑抢修
来源:互联网 发布:淘宝 企业店铺 假货 编辑:程序博客网 时间:2024/04/30 05:05
贪心,按时间限制排序,记录当前维修需要的时间;
1.当前时间+这个建筑物维修需要的时间<=当前限制 ans++ 因为这个建筑的限制度后面没有影响,不选一定不会更优秀 //保证所有答案均符合要求
2.当前时间+这个建筑物维修需要的时间<=当前限制 :a。当前维修时间比之前一个小,更新之前的情况
b。更大 ,扔掉不管
这样,即保证解满足要求,同时使得维修时间最少
#include<cstdio>#include<cstring>#include<iostream>#include<queue>#include<algorithm>#define maxn 150020using namespace std;int n;struct node{int t,limit;bool operator < (const node& b)const {return limit<b.limit ; }}nod[maxn];priority_queue<int>q;int main(){scanf("%d",&n);for(int i=1;i<=n;i++){scanf("%d%d",&nod[i].t,&nod[i].limit);}sort(nod+1,nod+1+n);int now=nod[1].t,ans=1;q.push(nod[1].t );for(int i=2;i<=n;i++){if(now+nod[i].t<=nod[i].limit){q.push(nod[i].t);now+=nod[i].t;ans++;}else{int u=q.top();if(u>nod[i].t){q.pop();q.push(nod[i].t);now=now-u+nod[i].t;}}}printf("%d",ans);return 0;}
0 0
- BZOJ 1029: [JSOI2007]建筑抢修
- BZOJ 1029: [JSOI2007]建筑抢修
- bzoj 1029: [JSOI2007]建筑抢修
- 【BZOJ 1029】 [JSOI2007]建筑抢修
- [BZOJ 1029][JSOI2007]建筑抢修
- BZOJ 1029 [JSOI2007]建筑抢修
- 【bzoj 1029】 [JSOI2007]建筑抢修
- 【BZOJ 1029】[JSOI2007]建筑抢修
- [bzoj] 1029 [JSOI2007]建筑抢修
- BZOJ 1029: [JSOI2007]建筑抢修
- bzoj[JSOI2007]建筑抢修
- bzoj 1029 [JSOI2007] 建筑抢修 题解
- BZOJ 1029 JSOI2007 建筑抢修 贪心+堆
- 【BZOJ】1029 [JSOI2007]建筑抢修 贪心+堆
- bzoj 1029: [JSOI2007]建筑抢修 贪心+堆
- BZOJ 1029: [JSOI2007]建筑抢修 优先队列
- 1029: [JSOI2007]建筑抢修
- 1029: [JSOI2007]建筑抢修
- c!#!获!取!文!件!夹!中!的!图!标!资!源
- HTML5学习_day10(2)--css文件书写格式
- DG之主库、备库切换(物理备库)
- hdu 4758 Walk Through Squares AC自动机
- 监听EditText的复制、粘贴、全选、剪切、选择等状态
- 【bzoj 1029】 [JSOI2007]建筑抢修
- 如何取消ctrl+space以便在Myecplise中使用快捷键
- codeforces Gym 101102F
- MATLAB数组加减法
- 有一个分数序列:2/1, 3/2, 5/3, 8/5, 13/8, …编写程序求出这个序列的前n项之和。
- 关于RN的配置流程
- 用实例理解Storm的Stream概念
- 面试--华为资料开发工程师
- Codechef Xor Queries(可持久化字典树)