【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 ...
随机推荐
- [React Intl] Format Numbers with Separators and Currency Symbols using react-intl FormattedNumber
Using a react-intl FormattedNumber component, we'll pass a Number and a few additional props in orde ...
- Gamma correction 伽马校准及 matlab 实现
matlab 内置实现:imadjust Gamma Correction gamma correction formula : .^(gamma) or .^(1/gamma)? 用以调整图像光照强 ...
- Android 用SQLite 使用 CursorLoader 中的数据填充列表视图
我做了简单的测试应用程序基于此示例.有一个按钮,插入到数据库和列表视图的数据.都是在 MainActivity 中.在原来的代码是restartLoader() 仅从调用 onResume() ,但它 ...
- iOS:实现图片的无限轮播---之使用第三方库SDCycleScrollView
SDCycleScrollView API // // SDCycleScrollView.h // SDCycleScrollView #import <UIKit/UIKit.h> ...
- FPGA实现UHS的一些资料
对使用FPGA和SD卡进行UHS模式通信的评估: 论文:基于FPGA的SD UHS-II卡控制器设计与实现 设计IP:SD UHS-II Host Controller 供应商: System Lev ...
- 对照jQuery和AngularJS的不同思维模
对照jQuery和AngularJS的不同思维模 Question 如果我已经熟悉了怎样使用jQuery来开发client应用.我如今打算使用AngularJS.请描写叙述一下有那些思维模式方面的东西 ...
- swift项目第八天:自定义转场动画以及设置titleView的状态
如图效果: 一:Home控制器 /* 总结:1:设置登陆状态下的导航栏的左右按钮:1:在viewDidLoad里用三目运算根据从父类继承的islogin的登陆标识来判断用户是否登陆来显示不同的界面.未 ...
- Mac OS X Kernel Basic User Credentials
User Credentials In order to understand security in OS X, it is important to understand that there a ...
- [Swift] Storyboard outlet and action
To programmaictlly change the content of app, we need to contect storyboard to a view controller. To ...
- word多出空标题,样式是列出段落 - -显示时,选择不勾选“隐藏文字”
word多出空标题,样式是列出段落