算法 UVA 11729
例2:假设当前小光有n个部下,每个部下需要完成一项任务。第i个部下需要小光花Bi分钟交代任务,然后他会立刻独立地、无间断地执行Ji分钟后完成任务。小光需要选择交代任务的顺序,使得所有任务尽早执行完毕(即最后一个执行完的任务应尽早结束)。注意,不能同时给两个部下交代任务,但部下们可以同时执行他们各自的任务。
Input
输入包含多组数据,每组数据的第一行为部下的个数n(1<=n<=1000);以下n行,每行两个正整数B和J(1<=B<=10000,1<=J<=10000),即交待任务的时间和执行任务的时间。输入结束标志为n=0。
Output
对组每组数据,输出所有任务完成的最短时间。具体输出格式见样例,用Case开头,Case以后输出当前数据的序号,然后输出答案。
Sample Input
3
2 5
3 2
2 1
3
3 3
4 4
5 5
0
Sample Output
Case 1: 8
Case 2: 15
//2019.4.20 突击战
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std; struct Job
{
int j, b;
bool operator < (const Job& x) const {
return j > x.j;
}
}; int main()
{
int n, b, j, kase = ;
while (scanf_s("%d", &n) == && n)
{
vector<Job> v;
for (int i = ; i < n; i++)
{
scanf_s("%d%d", &b, &j);
v.push_back({j, b});
}
sort(v.begin(), v.end());
int s = , ans = ;
for (int i = ; i < n; i++)
{
s += v[i].b;
ans = max(ans, s + v[i].j);
}
cout << "Case " << kase++ << ": " << ans << endl;
}
return ;
}
算法 UVA 11729的更多相关文章
- Uva 11729 Commando War (简单贪心)
Uva 11729 Commando War (简单贪心) There is a war and it doesn't look very promising for your country. N ...
- 贪心 UVA 11729 Commando War
题目传送门 /* 贪心:按照执行时间长的优先来排序 */ #include <cstdio> #include <algorithm> #include <iostrea ...
- cogs 1446. [Commando War,Uva 11729]突击战
1446. [Commando War,Uva 11729]突击战 ★ 输入文件:commando.in 输出文件:commando.out 简单对比时间限制:1 s 内存限制:64 ...
- UVa 11729 - Commando War(贪心)
"Waiting for orders we held in the wood, word from the front never came By evening the sound of ...
- Floyd判圈算法 UVA 11549 - Calculator Conundrum
题意:给定一个数k,每次计算k的平方,然后截取最高的n位,然后不断重复这两个步骤,问这样可以得到的最大的数是多少? Floyd判圈算法:这个算法用在循环问题中,例如这个题目中,在不断重复中,一定有一个 ...
- 算法 UVA 11292
***从今天开始自学算法. ***代码是用c++,所以顺便再自学一下c++ 例题1 勇者斗恶龙(The Dragon of Loowater, UVa 11292) 你的王国里有一条n个头的恶龙,你 ...
- 二分图最大匹配(匈牙利算法) UVA 10080 Gopher II
题目传送门 /* 匈牙利算法:这题比UVA_670简单,注意是要被吃的鼠的最少个数,套模板 */ #include <cstdio> #include <algorithm> ...
- 二分图最大匹配(匈牙利算法) UVA 670 The dog task
题目传送门 /* 题意:bob按照指定顺序行走,他的狗可以在他到达下一个点之前到一个景点并及时返回,问狗最多能走多少个景点 匈牙利算法:按照狗能否顺利到一个景点分为两个集合,套个模板 */ #incl ...
- UVA 11729 - Commando War(贪心 相邻交换法)
Commando War There is a war and it doesn't look very promising for your country. Now it's time to ac ...
随机推荐
- kubenetes dns
E0228 07:32:28.912833 1 reflector.go:201] k8s.io/dns/pkg/dns/dns.go:147: Failed to list *v1.En ...
- minio test
docker pull minio/minio docker run --name=minio -d -p 9001:9000 minio/minio server /data https://do ...
- CocoaPods私有库!!!!!!!!!!!(装逼特技)
1http://www.jianshu.com/p/4b63dfbd8be7 2 修改工程下的.podspec文件,如 注意1: 验证库是否正确: pod lib lint --verbose -- ...
- CloudFoundry 快速上手笔记
1.登陆cf 2.登陆进入webservice 3.查看ruby版本 4.查看gem版本 5.安装CF 6.配置cf Download the CLI from github: https://git ...
- Ubuntu14.04下opencv卸载与重装
参考链接:http://askubuntu.com/questions/334158/installing-opencv http://stackoverflow.com/questions/1313 ...
- CentOS Mysql安装配置
一.mysql简介 MySQL是一个关系型数据库管理系统,由瑞典MySQL AB公司开发,目前属于Oracle公司.MySQL是一种关联数据库管理系统,关联数据库将数据保存在不同的表中,而不是将所有数 ...
- array_combine()
- 点云数据保存为pcd文件_pcd_write.cpp
#include <iostream>#include <pcl/io/pcd_io.h>#include <pcl/point_types.h> int main ...
- [Groovy]获取当前活动的Environment,获取response中节点的name和节点的value
import com.eviware.soapui.support.GroovyUtils import com.eviware.soapui.support.XmlHolder import org ...
- js运算浮点数
在js中做小数:9.3+0.3会发现,得到的结果并不是9.6,而是9.600000000000001.这是为什么? Javascript采用了IEEE-745浮点数表示法,这是一种二进制表示法,可以精 ...