UVa 11729 Commando War 突击战
你有 n 个部下,每个部下需要完成一个任务。第 i 个部下需要你花 Bi 分钟交待任务,然后他会立刻独立地、无间断地执行 Ji 分钟后完成任务。你需要选择交待任务的顺序,使得所有任务尽早执行完毕(即最后一个执行完的任务尽早结束)。注意,不能同时给两个部下交待任务,但部下们可以同时执行他们各自的任务。
既然是要尽早完成任务,当然执行时间长的先交待,先执行。所以对所有数据按执行时间从大到小的顺序进行排序,然后开始处理,通过更新最晚的时间来得到最终结果。
简单的贪心,附上AC代码:
1: #include <stdio.h>
2: #include <math.h>
3: #include <iostream>
4: #include <cstdarg>
5: #include <algorithm>
6: #include <string.h>
7: #include <stdlib.h>
8: #include <string>
9: #include <list>
10: #include <vector>
11: #include <map>
12: #define LL long long
13: #define M(a) memset(a, 0, sizeof(a))
14: using namespace std;
15:
16: void Clean(int count, ...)
17: {
18: va_list arg_ptr;
19: va_start (arg_ptr, count);
20: for (int i = 0; i < count; i++)
21: M(va_arg(arg_ptr, int*));
22: va_end(arg_ptr);
23: }
24:
25: typedef struct A
26: {
27: int b, j;
28: bool operator < (const A& x) const
29: {
30: return j > x . j;
31: }
32: }A;
33:
34: int main()
35: {
36: int n, count = 1;
37: while (~scanf("%d", &n) && n)
38: {
39: vector <A> buf;
40: int b, j;
41: for (int i = 0; i < n; i++)
42: {
43: scanf("%d%d", &b, &j);
44: buf.push_back((A){b, j});
45: }
46: sort(buf.begin(), buf.end());
47: int end = 0, now = 0, ans = 0;
48: for (int i = 0; i < n; i++)
49: {
50: now += buf[i] . b;
51: end = max(end, now + buf[i] . j);
52: }
53: printf("Case %d: %d\n", count++, end);
54: }
55: return 0;
56: }
UVa 11729 Commando War 突击战的更多相关文章
- 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 ...
- 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 ...
- UVa 11729 - Commando War(贪心)
"Waiting for orders we held in the wood, word from the front never came By evening the sound of ...
- [ACM_水题] UVA 11729 Commando War [不可同时交代任务 可同时执行 最短完成全部时间 贪心]
There is a war and it doesn't look very promising for your country. Now it's time to act. You have a ...
- UVa 11729 - Commando War
[题目翻译]: 题目分析:因为任务是可以并行的执行,所以直觉上是花费时间长的任务优先去部署.但是这到题目还给你交待任务的时间,所以容易让人想多了. 不管有没有交待任务的时间,对于任务x和y,只可能有两 ...
- UVa 11729 Commando War 【贪心】
题意:有n个部下,交待每个部下完成他相应的任务需要bi的时间,然后完成这项任务需要ji的时间, 选择交待任务的顺序,使得总的花费的时间最少 因为不管怎么样,交待所需要的n*bi的时间都是要花费的, 然 ...
- uva----11729 Commando war (突击战争)
G Commando War Input: Standard Input Output: Standard Output “Waiting for orders we held in the wood ...
- Commando War
Commando War“Waiting for orders we held in the wood, word from the front never cameBy evening the so ...
随机推荐
- NYOJ-456 邮票分你一半 AC 分类: NYOJ 2014-01-02 14:33 152人阅读 评论(0) 收藏
#include<stdio.h> #define max(x,y) x>y?x:y int main(){ int n,x,y; scanf("%d",& ...
- java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver
因为这个问题折腾了以上午,终于解决了,做下记录: 错误提示为:java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLSer ...
- iOS开发之静态库的制作
当你需要和别人分享代码,但又不想让别人看到你内部的实现时就需要制作静态库,通常用于第三方SDK 下面就分享一下制作静态库(.a)的过程: 1.打开Xcode,新建workspace 2.随便给work ...
- Java基于Socket文件传输示例(转)
最近需要进行网络传输大文件,于是对基于socket的文件传输作了一个初步的了解.在一位网友提供的程序基础上,俺进行了一些加工,采用了缓冲输入/输出流来包装输出流,再采用数据输入/输出输出流进行包装,加 ...
- String 内在分配解析
1.String类概念 (1)String是final的,不可被继承.public final class String.String是的本质是字符数组char[], 并且其值不可改变.private ...
- Robot Framework 环境搭建
一.下载软件 1.安装Python 到官网,下载Python 2.7.9:https://www.python.org/downloads/,最好选择32位版本的(64位系统也支付32位版本),然后安 ...
- ssh 公钥
以前做ssh key登录方式时都是用的root帐号,基本都是无往不利的,权限采用默认即可.今天实验中两台机器帐号都是nianzong,一个普通的帐号.按照如下步骤: A机器:ssh-keygen -t ...
- 黑马程序员--C#中属性和字段(变量)的区别
---------------------- ASP.Net+Android+IOS开发..Net培训.期待与您交流! ---------------------- 属性为类提供了一种很有用的封装数据 ...
- [优先队列]HDOJ5289 Assignment
题意:有多少个区间,区间内最大的数减去最小的数差小于k 对每个数它所在的区间,可以只往前找(类似dp的无后效性) 比如对位置3的数,可以往前找的区间是[3, 3], [2, 3], [1, 3], [ ...
- 使用post()方法以POST方式从服务器发送数据
使用post()方法以POST方式从服务器发送数据 与get()方法相比,post()方法多用于以POST方式向服务器发送数据,服务器接收到数据之后,进行处理,并将处理结果返回页面,调用格式如下: $ ...