HDU--4221--Greedy?
来源:互联网 发布:网络宣传要会什么 编辑:程序博客网 时间:2024/06/06 02:33
题目
这个题目题意有点容易理解错,理解了后就比较简单了。
题目要求的是求出总罚值最小的情况下最大的罚值
要让总罚值最小,将最小期限Di排序,然后将最大的罚值求出来就可以了。
#include<cstdio>#include<algorithm>using namespace std;struct Time //定义Di , Ci 的结构体,方便排序操作{ int Ci; int Di;};bool cmp(Time a,Time b) //定义比较函数{ return a.Di<b.Di;}Time a[100005];int main(){ int T,ca=0; scanf("%d",&T); while(T--) { ca++; int n; long long sum=0,ans=0; scanf("%d",&n); for(int i=0;i<n;i++) { scanf("%d%d",&a[i].Ci,&a[i].Di); } sort(a,a+n,cmp); //快速排序 for(int i=0;i<n;i++) { ans+=a[i].Ci; if(ans-a[i].Di>sum) sum=ans-a[i].Di; } printf("Case %d: %lld\n",ca,sum); }}
题目还是比较简单的,运用的就只有对结构体进行排序知识点,不是很难。
阅读全文
0 0
- hdu 4221Greedy?
- HDU 4221 Greedy?
- hdu 4221 Greedy?
- HDU 4221 Greedy?
- 贪心--HDU - 4221 Greedy?
- hdu Greedy 4221 (贪心)
- HDU 4221 Greedy?
- HDU 4221 Greedy?(贪心)
- HDU--4221--Greedy?
- HDU 4221 Greedy?(贪心)
- HDU 4221 Greedy?(DP)
- hdu 4221 Greedy 贪心算法
- HDU 4221 Greedy?(贪心)
- Greedy? HDU
- 4221 Greedy?
- hdu 1338 #greedy
- HDU 4380 - Farmer Greedy
- hdu 1009--greedy
- 【补充】完善jdbc 【学习笔记】
- 常用JS功能函数汇总
- leetcode-387. First Unique Character in a String
- 订单信息
- 171122之导入项目常见问题
- HDU--4221--Greedy?
- Java读书笔记——07 面向对象 继承
- 针对在webstorm开发React Native的代码快捷设置
- 拦截器——okhttp(post)+recyclerView显示数据
- codeforce 825E. Minimal Labels 拓扑排序 贪心思想
- 转:spring上下文,spring mvc上下文,以及servlet上下文的关联以及理解
- 互联网产品的运营指标
- OpenGL从1.0开始--绘制规则多面体
- 网络工程师成长日记151-面试好好面,别耍怪!