uva11729 - Commando War(贪心)
贪心法,执行任务的时间J越长的应该越先交待。可以用相邻交换法证明正确性。其实对于两个人,要让总时间最短,就要让同一时间干两件事的时间最长。
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<stack>
#include<queue>
#include<cctype>
#include<sstream>
using namespace std;
#define pii pair<int,int>
#define LL long long int
const int eps=1e-;
const int INF=;
const int maxn=+;
struct node
{
int B,J;
}a[maxn];
int n,ans,cas=;
bool cmp(node x,node y)
{
return x.J>y.J;
}
int main()
{
//freopen("in2.txt","r",stdin);
//freopen("out.txt","w",stdout);
while(scanf("%d",&n)==&&n)
{
for(int i=;i<n;i++)
{
scanf("%d%d",&a[i].B,&a[i].J);
}
sort(a,a+n,cmp);
ans=a[].B+a[].J;
int t=a[].B+a[].J;
for(int i=;i<n;i++)
{
t+=a[i].B+a[i].J-a[i-].J;//t表示每一“横条”的用时
ans=max(ans,t); }
printf("Case %d: %d\n",++cas,ans);
}
//fclose(stdin);
//fclose(stdout);
return ;
}
uva11729 - Commando War(贪心)的更多相关文章
- uva----11729 Commando war (突击战争)
G Commando War Input: Standard Input Output: Standard Output “Waiting for orders we held in the wood ...
- UVa 11729 - Commando War(贪心)
"Waiting for orders we held in the wood, word from the front never came By evening the sound of ...
- Uva11729 Commando War
相邻两个士兵交换顺序,不会对其他的有所影响,贪心考虑两两之间交换策略即可. sort大法好.印象中这类排序题里有一种会卡sort,只能冒泡排序,然而到现在还没有遇到 /**/ #include< ...
- 【题解】 UVa11729 Commando War
题目大意 你有n个部下,每个部下需要完成一项任务.第i个部下需要你花Bj分钟交代任务,然后他就会立刻独立地.无间断地执行Ji分钟后完成任务.你需要选择交代任务的顺序,使得所有任务尽早执行完毕(即最后一 ...
- 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 (简单贪心)
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 ...
- Commando War
Commando War“Waiting for orders we held in the wood, word from the front never cameBy evening the so ...
随机推荐
- 剑指offer 面试6题
面试6题: 题目:从尾到头打印链表 输入一个链表,从尾到头打印链表每个节点的值. 解题代码: # -*- coding:utf-8 -*- # class ListNode: # def __init ...
- LeetCode:螺旋矩阵||【59】
LeetCode:螺旋矩阵||[59] 题目描述 给定一个正整数 n,生成一个包含 1 到 n2 所有元素,且元素按顺时针顺序螺旋排列的正方形矩阵. 示例: 输入: 3 输出: [ [ 1, 2, 3 ...
- Python 3 文件和字符编码
一.文件: 打开文件的模式有: r,只读模式(默认). w,只写模式. 不可读,不存在则创建:存在则删除内容 a,追加模式. 可读,不存在则创建:存在则只追加内容 "+"表示可以 ...
- Python框架之Tornado(概述)
本系列博文计划: 1.剖析基于Python的Web框架Tornado的源码,为何要阅读源码? Tornado 由前 google 员工开发,代码非常精练,实现也很轻巧,加上清晰的注释和丰富的 demo ...
- spring RMI的使用
Spring整合RMI的原理 客户端的核心是RmiProxyFactoryBean,包含serviceURL属性和serviceInterface属性. 通过JRMP访问服务.JRMP JRMP:ja ...
- python cookboo 文件与IO 函数
写出文本数据 g = open('test.txt', 'rt', newline='',encoding = 'utf-8', errors='replace') t是windows平台特有的所谓t ...
- [NOI2008]设计路线
题目 洛谷 BZOJ 做法 神仙题 显然这是棵树 个节点相东仅连接一个结点 不同于剖分,还能存在\("V"\)字型,一个节点最多与另外节点连两条边 \(dp[i][j][k]\)表 ...
- Django源码剖析
一.Django底层剖析之一次请求到响应的整个流程 As we all know,所有的Web应用,其本质上其实就是一个socket服务端,而用户的浏览器就是一个socket客户端 #!/usr/bi ...
- 最长公共子序列的C++实现---附二维指针的使用方法
想了挺久到底第一篇在这儿的博客写什么好,刚好这两天又一次看到动态规划的LCS算法觉得还是有点意思的,就拿来写了写,第一篇博客就发它吧. #include<iostream> #includ ...
- Android系统--Binder系统具体框架分析(一)补充
Android系统--Binder系统具体框架分析(一)补充 补充:对Binder驱动分析一的代码补充,添加saygoobye和saygoodbye_to服务 test_server.h #ifnde ...