codeforces 725D . Contest Balloons(贪心+优先队列)
2024-10-19 11:45:51
题目链接:codeforces 725D . Contest Balloons
先按气球数从大到小排序求出初始名次,并把名次排在第一队前面的队放入优先队列,按w-t-1值从小到大优先,然后依次给气球给排名在前面的的队,给完后自己的气球数减少,继续跟之前排在第一队后面的队比较,考虑是否加入队列,每次记录最好的名次。
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long ll;
const int N = ;
struct team{
ll t, w, wa;
team(ll t = , ll w = ):t(t),w(w) { wa = w - t + ; }
bool operator < (const team &r)const{
return r.wa < wa;
}
}a[N];
bool cmp(team x, team y){
return x.t > y.t;
}
priority_queue<team>q;
int main(){
int n, i, j;
ll ans, a1;
scanf("%d", &n);
for(i = ; i < n; ++i)
scanf("%lld%lld", &a[i].t, &a[i].w);
sort(a+, a+n, cmp);
for(i = ; i < n; ++i){
if(a[i].t > a[].t)
q.push(team(a[i].t, a[i].w));
else break;
}
a1 = ans = i;//初始名次
while(!q.empty()){
team tt = q.top(); q.pop();
a[].t -= tt.wa;
if(a[].t < ) break;
for(j = i; j < n; ++j){
if(a[j].t > a[].t){
q.push(team(a[j].t , a[j].w));}
else break;
}
a1 += j - i - ;
i = j;
ans = min(ans, a1);
}
printf("%lld\n", ans);
return ;
}
最新文章
- 【WPF】整个自定义按钮后台添加
- SQL SERVER全面优化-------索引有多重要?
- CodeForces 515C. Drazil and Factorial
- iOS开发——源代码管理——SVN
- web前端基础篇⑧
- this.Invoke
- OC基础(16)
- dojo 十一 jsonp
- (转)Const,Const函数,Const变量,函数后面的Const
- openssl windows编译 32位&;64位
- strlen 与 sizeof
- JVM组成
- docker 数据卷管理
- 刘志梅201771010115.《面向对象程序设计(java)》第十七周学习总结
- Linux之cp、rm、mv
- Python 基础数据类型之set
- QQ 互联认证 回调地址提示说要http :// 但是事实不用
- django-template-forloop
- 29.OGNL与ValueStack(VS)-总结OGNL[重点]
- c# -- Form1_Load()不被执行的三个解决方法