【题目链接】:http://www.lydsy.com/JudgeOnline/problem.php?id=1029

【题意】

【题解】

/*
按照T2升序排
顺序枚举每一个建筑;
如果当前建筑能够修理;
则修理它;
并将它的T1值加入到堆中;
然后累加当前所用的时间now;
如果加了这个T1之后会大于T2则这个建筑没办法修理;
则在堆里面去找
看看有没有比T1大的值;
如果有的话,就改修这个建筑;而那个建筑不修了;
这样虽然不能增加修理的建筑的个数;
但是now的值会减小;
增加了后面能够新修理建筑的机会.
因为now是肯定小于等于T2的,
所以更换以后,相当于是在确定的时间范围里面
有两个建筑都能修好;
但不能同时修好;
则当然先修那个修的时间短的了。
开long long安全点。
用STL的priority_queue很方便。
*/

【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%lld",&x)
#define ref(x) scanf("%lf",&x) typedef pair<int, int> pii;
typedef pair<LL, LL> pll; const int dx[9] = { 0,1,-1,0,0,-1,-1,1,1 };
const int dy[9] = { 0,0,0,-1,1,-1,1,-1,1 };
const double pi = acos(-1.0);
const int N = 15e4+100; struct Node
{
LL val;
friend bool operator<(Node a, Node b) { return a.val < b.val; }
}; struct abc
{
LL T1, T2;
}; priority_queue<Node>Q;
Node tq;
abc a[N]; int n,ans;
LL now; void in()
{
rei(n);
rep1(i, 1, n)
{
rel(a[i].T1), rel(a[i].T2);
}
} bool cmp(abc a, abc b)
{
return a.T2 < b.T2;
} void ga()
{
rep1(i, 1, n)
{
LL temp = now + a[i].T1;
if (temp <= a[i].T2)
{
ans++;
tq.val = a[i].T1;
Q.push(tq);
now = temp;
}
else
{
LL d = Q.top().val;
if (d > a[i].T1)
{
Q.pop();
tq.val = a[i].T1;
Q.push(tq);
now -= (d - a[i].T1);
}
}
}
} void out()
{
printf("%d\n", ans);
} int main()
{
//freopen("F:\\rush.txt", "r", stdin);
in();
sort(a + 1, a + 1 + n, cmp);
ga();
out();
//printf("\n%.2lf sec \n", (double)clock() / CLOCKS_PER_SEC);
return 0;
}

最新文章

  1. 从零开始攻略PHP(5)——字符串操作与POSIX正则
  2. 简单Spinner
  3. 专家谈国产CPU最新发展态势:需强化标准建设(很全面)
  4. CONTROLS: &lt;&gt; TYPE TABLEVIEW USING SCREEN&lt;&gt;.在 ABAP/4 中声明表格 控制
  5. mysqldump备份、还原数据库路径名含有空格的处理方法(如:Program Files)
  6. AT&amp;T汇编试讲--获取CPU Vendor ID
  7. [转]tripwire-文件指纹
  8. 剖析html对标准标签和自定义标签闭合与不闭合渲染问题
  9. Cocos2d学习之路三(使用Zwoptex创建精灵表单和CCAnimate动画)
  10. 排序 之 快排、归并、插入 - &lt;时间复杂度&gt;----掌握思想和过程
  11. JQuery UI的拖拽功能
  12. JAVA 平台
  13. 【转】干货 | 【虚拟货币钱包】从 BIP32、BIP39、BIP44 到 Ethereum HD Wallet
  14. Android Studio3.0.1集成Git
  15. flask自定义转换器
  16. BZOJ 5249: [2018多省省队联测]IIIDX(贪心 + 线段树)
  17. 如何优雅地等待所有的goroutine退出
  18. JavaScript三种方式改变标签css
  19. 【Android】1.1 开发环境安装和配置
  20. SpringBoot打成的jar包发布,shell关闭之后一直在服务器运行

热门文章

  1. 【例题 7-13 UVA-1374】Power Calculus
  2. Android中的Parcelable接口和Serializable使用方法和差别
  3. asp.net mvc 中的自定义验证(Custom Validation Attribute)
  4. Altium Designer导入pcb原件之后都是绿的
  5. UVA 11796 - Dog Distance 向量的应用
  6. NSDate时间
  7. 9.13 Binder系统_Java实现_内部机制_Server端
  8. ITFriend月刊-第1期-2014年6月.pdf
  9. 更改jdk所用内存空间
  10. View的事件分发机制解析