朝鲜战争:轰炸大小和岛
来源:互联网 发布:centos 安装mysql pdo 编辑:程序博客网 时间:2024/04/25 03:50
试题描述
输入
输出
输入示例
4
100 200
200 1300
1000 1250
2000 3200
100 200
200 1300
1000 1250
2000 3200
输出示例
3
其他说明
C程序:
#include <iostream>#include <cstring>#include <queue>#include <cstdio>#include <algorithm>using namespace std;const int N=150006;struct Big_Heap { int A[N<<1|1], tot; void init(int n) { for(int i=1; i<=(n<<1|1); i++) A[i]=0; tot=0; } void Insert(int val) { A[++tot]=val; for(int x=tot; x>1 && A[x]>A[x>>1]; x>>=1) swap(A[x], A[x>>1]); } void Update(int val) { A[1]=val; for(int i=1, j=2; j<=tot; i=j, j<<=1) { if((j|1)<=tot && A[j]<A[j|1]) j|=1; if(A[j]<A[i]) break; swap(A[i], A[j]); } }} heap;struct data { int t1, t2; bool operator < (const data &T) const { return t2<T.t2; }} A[N];int n, ans, cur;int main() { while(scanf("%d", &n)!=EOF) { for(int i=0; i<n; i++) scanf("%d%d", &A[i].t1, &A[i].t2); sort(A, A+n); cur=ans=0, heap.init(n); for(int i=0; i<n; i++) { if(A[i].t1+cur<=A[i].t2) ans++, heap.Insert(A[i].t1), cur+=A[i].t1; else { if(!heap.tot) continue; int val=heap.A[1]; if(val<=A[i].t1) continue; cur-=val-A[i].t1; heap.Update(A[i].t1); } } printf("%d\n", ans); } return 0;}
0 0
- 朝鲜战争:轰炸大小和岛
- 朝鲜战争
- 朝鲜战争
- 轰炸
- 轰炸
- 章16 缺陷轰炸和beta测试
- 和菜头:在碎片化的轰炸中喘息
- 讨论朝鲜战争之前必读
- 外国人眼里的朝鲜战争
- 朝鲜战争史实点滴记录
- 朝鲜战争中的牺牲者
- 【模拟】轰炸
- RQNOJ 轰炸
- 【u209】轰炸
- P1142 轰炸
- 抗美系列之朝鲜战争
- 轰炸问题、连续子序列的积、n个最大连续子序列和
- 如何实施手机短信轰炸
- Codeforces Round #315 (Div. 2)569B Inventory(队列)
- 在C下执行DOS命令
- Matlab下地理热度图的绘制
- LeetCode-18 4Sum
- 16-集合框架-03-常用对象API(集合框架-方法演示_1)
- 朝鲜战争:轰炸大小和岛
- Leetcode#2||Add Two Numbers
- malloc的使用
- poj 2406 Power Strings
- DevExpress v15.1:ASP.NET WebForms功能增强(二)
- PostgreSQ 连接问题 FATAL: no pg_hba.conf entry for host
- Light OJ 1319 Monkey Tradition(中国剩余定理)
- caffe net 类代码分析
- 16-集合框架-04-常用对象API(集合框架-方法演示_2)