UVA 11292 和 UVA 11729
来源:互联网 发布:you don t know js 编辑:程序博客网 时间:2024/05/16 06:37
最近开始刷刘汝佳的大白书,这两道妥妥的贪心题目,第一道很快就知道怎么做,第二道稍微分析一下也可以知道是用贪心来写,先把完成任务时间长的先安排。第一题的代码就不附上了,第二题代码如下:#include <iostream>#include <cstring>#include <string>#include <cstdio>#include <algorithm>using namespace std;const int maxn=10000+10;int t;struct job { int j,b;} a[maxn];bool cmp(job k1,job k2) { return k1.j>k2.j;}int main() { int tcase=0; while(scanf("%d",&t),t) { for(int i=0; i<t; i++) { scanf("%d%d",&a[i].b,&a[i].j); } sort(a,a+t,cmp); cout<<"###########"<<endl; for(int i=0; i<t; i++) { cout<<a[i].b<<" "<<a[i].j<<endl; } cout<<"###########"<<endl; int s=0; int ans=0; for(int i=0; i<t; i++) { s+=a[i].b; ans=max(ans,s+a[i].j); } printf("Case %d: %d\n",++tcase,ans); } return 0;}
0 0
- UVA 11292 和 UVA 11729
- Uva 11292 and Uva 11729
- uva
- UVA
- UVA
- UVA
- uva
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- Activity生命周期方法的调用顺序工程与测试日志
- 输入一行字符串,找出其中出现的相同且长度最长的字符串,输出他及其首字符串位置
- 缺乏运动 七种病早早光临
- 数据库分类
- 资源分离
- UVA 11292 和 UVA 11729
- 百度面试题
- sznsadtryk
- 汉字对应的unicode编码
- 快速排序
- 非极大值抑制(NMS)
- 网易java开发实习日记
- codeforce 5A Chat Server's Outgoing Traffic
- html5.js让IE(包括IE6)支持HTML5元素方法