【BZOJ 1029】[JSOI2007]建筑抢修
【题目链接】: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;
}
【BZOJ 1029】[JSOI2007]建筑抢修的更多相关文章
- BZOJ 1029: [JSOI2007]建筑抢修 堆+贪心
1029: [JSOI2007]建筑抢修 Description 小刚在玩JSOI提供的一个称之为“建筑抢修”的电脑游戏:经过了一场激烈的战斗,T部落消灭了所有z部落的入侵者.但是T部落的基地里已经有 ...
- BZOJ 1029 [JSOI2007] 建筑抢修(贪心)
1029: [JSOI2007]建筑抢修 Time Limit: 4 Sec Memory Limit: 162 MBSubmit: 2285 Solved: 1004[Submit][Statu ...
- BZOJ 1029 [JSOI2007]建筑抢修 已更新
1029: [JSOI2007]建筑抢修 Time Limit: 4 Sec Memory Limit: 162 MBSubmit: 2748 Solved: 1213[Submit][Statu ...
- BZOJ 1029: [JSOI2007]建筑抢修
1029: [JSOI2007]建筑抢修 Description 小刚在玩JSOI提供的一个称之为“建筑抢修”的电脑游戏:经过了一场激烈的战斗,T部落消灭了所有z部落的入侵者.但是T部落的基地里已经有 ...
- BZOJ 1029: [JSOI2007]建筑抢修【优先队列+贪心策略】
1029: [JSOI2007]建筑抢修 Time Limit: 4 Sec Memory Limit: 162 MBSubmit: 4810 Solved: 2160[Submit][Statu ...
- BZOJ 1029 [JSOI2007]建筑抢修 (贪心 + 优先队列)
1029: [JSOI2007]建筑抢修 Time Limit: 4 Sec Memory Limit: 162 MBSubmit: 5452 Solved: 2422[Submit][Statu ...
- BZOJ 1029: [JSOI2007]建筑抢修 优先队列
1029: [JSOI2007]建筑抢修 Time Limit: 4 Sec Memory Limit: 162 MB 题目连接 http://www.lydsy.com/JudgeOnline/p ...
- BZOJ 1029: [JSOI2007]建筑抢修 贪心
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1029 小刚在玩JSOI提供的一个称之为“建筑抢修”的电脑游戏:经过了一场激烈的战斗,T部落 ...
- [BZOJ 1029] [JSOI2007] 建筑抢修 【贪心】
题目链接:BZOJ - 1029 题目分析 使用一种贪心策略. 现将任务按照deadline从小到大排序. 然后枚举每一个任务,如果当前消耗的时间加上完成这个任务的时间不会超过这个任务的deadlin ...
- BZOJ 1029 JSOI2007 建筑抢修 贪心+堆
题目大意:n个建筑须要抢修.第i个建筑须要T1时间抢修.必须在T2时间之前抢修完成.求最多能抢修多少建筑 首先我们对T2排序 然后依次修理 可是这样贪心显然是不对的 比方说这组数据: 5 10 10 ...
随机推荐
- 调色板原理 & 编程
调色板原理 & 编程 逻辑调色板结构LOGPALETTE,该结构定义如下: typedef struct tagLOGPALETTE { WORD palVersion; //调色板的板本号, ...
- php-wamp环境搭建
wamp(Windows,Apache,Mysql,PHP) win8.1下搭建apache2.4(64位) php5.6.11(64位) mysql5.6.24(32位) d盘创建文件结构为: ...
- [RxJS] Avoid mulit post requests by using shareReplay()
With the shareReplay operator in place, we would no longer fall into the situation where we have acc ...
- 【Codeforces Round #433 (Div. 1) B】Jury Meeting
[链接]h在这里写链接 [题意] 有n个人,它们都要在某一时刻开始,全都到达0位置,然后维持最少k个时间单位,然后再全都回到原来的位置; 第i个人初始的位置是i. 且一共有m班航班. 每一班航班,要么 ...
- uva 10710 - Chinese Shuffle(完美洗牌)
option=com_onlinejudge&Itemid=8&category=474&page=show_problem&problem=1651"> ...
- LA 5902 - Movie collection 树状数组(Fenwick树)
看题传送门 题目大意:XXX喜欢看电影,他有好多好多的影碟,每个影碟都有个独立的编号.开始是从下往上影碟的顺序是n~1,他每次拿出影碟的时候,你需要输出压在该影碟上的有几个.(拿出后其他影碟顺序不变) ...
- DOS 命令forfiles
forfiles /p E:/dbbackup/diff /s /m *.* /d -14 /c "cmd /c del @file" forfiles: /p 指定的路径 /s ...
- cocos 关于文件名称的各种坑 各种斜杠坑
cocos 全部文件路径 的斜杠 必须 用 / 而不能够用 \ 不然编译到安卓各种坑 相对路径 第一个字符不可 带 / /*比如 res/test.png 这样的应该是标准的 /res/test.p ...
- occcont.cpp 925
将InitInstance()中调用的 InitATL() 替换为 AfxOleInit()即可.
- PatentTips - SNMP firewall
BACKGROUND OF THE INVENTION [0001] The present invention relates to communications and, more particu ...