例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的更多相关文章

  1. Uva 11729 Commando War (简单贪心)

    Uva 11729  Commando War (简单贪心) There is a war and it doesn't look very promising for your country. N ...

  2. 贪心 UVA 11729 Commando War

    题目传送门 /* 贪心:按照执行时间长的优先来排序 */ #include <cstdio> #include <algorithm> #include <iostrea ...

  3. cogs 1446. [Commando War,Uva 11729]突击战

    1446. [Commando War,Uva 11729]突击战 ★   输入文件:commando.in   输出文件:commando.out   简单对比时间限制:1 s   内存限制:64 ...

  4. UVa 11729 - Commando War(贪心)

    "Waiting for orders we held in the wood, word from the front never came By evening the sound of ...

  5. Floyd判圈算法 UVA 11549 - Calculator Conundrum

    题意:给定一个数k,每次计算k的平方,然后截取最高的n位,然后不断重复这两个步骤,问这样可以得到的最大的数是多少? Floyd判圈算法:这个算法用在循环问题中,例如这个题目中,在不断重复中,一定有一个 ...

  6. 算法 UVA 11292

    ***从今天开始自学算法. ***代码是用c++,所以顺便再自学一下c++ 例题1  勇者斗恶龙(The Dragon of Loowater, UVa 11292) 你的王国里有一条n个头的恶龙,你 ...

  7. 二分图最大匹配(匈牙利算法) UVA 10080 Gopher II

    题目传送门 /* 匈牙利算法:这题比UVA_670简单,注意是要被吃的鼠的最少个数,套模板 */ #include <cstdio> #include <algorithm> ...

  8. 二分图最大匹配(匈牙利算法) UVA 670 The dog task

    题目传送门 /* 题意:bob按照指定顺序行走,他的狗可以在他到达下一个点之前到一个景点并及时返回,问狗最多能走多少个景点 匈牙利算法:按照狗能否顺利到一个景点分为两个集合,套个模板 */ #incl ...

  9. 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 ...

随机推荐

  1. Spring 学习记录5 BeanFactory

    主题 记录我对BeanFactor接口的简单的学习. BeanFactory我感觉就是管理bean用的容器,持有一堆的bean,你可以get各种bean.然后也提供一些bean相关的功能比如别名呀之类 ...

  2. 在Ajax请求中什么时候用GET方式什么时候用POST方式?

    当我们有大量数据要传送时最好的办法是一次发出多个只传递少量信息的Ajax调用时.如果你正用一个Ajax调用发送大量数据,那么最好是结束这种做法,因为这样做并不能节约时间. 因此,需要传送大量数据能成为 ...

  3. 【UVA11613 训练指南】生产销售规划 【费用流】

    题意: Acme公司生产一种X元素,给出该元素在未来M个月中每个月的单位售价.最大产量.最大销售量,以及最大储存时间(过期报废不过可以储存任意多的量).你的任务是计算出公司能够赚到的最大利润. 分析: ...

  4. Hibernate中Session与本地线程绑定

    ------------------siwuxie095 Hibernate 中 Session 与本地线程绑定 1.Session 类似于 JDBC 的连接 Connection 2.Session ...

  5. 750. Number Of Corner Rectangles四周是点的矩形个数

    [抄题]: Given a grid where each entry is only 0 or 1, find the number of corner rectangles. A corner r ...

  6. Apache CloudStack Features

    As a mature and turnkey Infrastructure-as-a-Service (IaaS) platform, Apache CloudStack has a compreh ...

  7. 关于oraclize使用最好的一篇文章

    https://medium.com/@msolomon44/using-apis-in-your-ethereum-smart-contract-with-oraclize-95656434292e ...

  8. jstack调试core文件

    摘自:https://stackoverflow.com/questions/37331266/jstack-throws-exception-interrogating-a-core // 错误示例 ...

  9. 一起做RGB-D SLAM (4)

    第四讲 点云拼接 广告:“一起做”系列的代码网址:https://github.com/gaoxiang12/rgbd-slam-tutorial-gx 当博客更新时代码也会随着更新. SLAM技术交 ...

  10. javascrip总结43:标签上自定义属性的操作

    1 获取标签属性 语法: element.getAttribute('属性名') 返回对应属性的值 ,如果没有返回null. //html <div id="box" ind ...