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 ...
随机推荐
- MCU与FPGA通信
1.MCU启动FPGA相应功能模块 通过译码器选择相应的功能模块,调用实现功能. 2.MCU与FPGA串口通信 SPI协议简单.可靠.易实现,速度快,推荐使用SPI.SPI为四线机制,包含MOSI.M ...
- Python基础(18)_面向对象程序设计2(反射、__str__、__del__、__item__系列)
一 isinstance(obj,cls)和issubclass(sub,super) isinstance(obj,cls)检查是否obj是否是类 cls 的对象 class Foo(object) ...
- google黑客语法总结
搜索也是一门艺术 说起Google,可谓无人不知无人不晓,其强大的搜索功能,可以让你在瞬间找到你想要的一切.不过对于普通的用户而言,Google是一个强大的搜索引擎:而对于黑客而言,则可能是一款绝佳的 ...
- 转:Windows下USB接口驱动技术(一)
- linux切换用户命令
1. 切换用户的命令为:su +username 2.从普通用户切换到root用户:sudo su 3.退回到原来的用户:exit命令或logout,或者ctrl+d 4.如果要切换到新用户的工作环境 ...
- $Java-json系列(二):用JSONObject解析和处理json数据
本文中主要介绍JSONObject处理json数据时候的一些常用场景和方法. (一)jar包下载 所需jar包打包下载百度网盘地址:https://pan.baidu.com/s/1c27Uyre ( ...
- 主攻ASP.NET.4.5.1 MVC5.0之重生:根据产品类别显示菜单分类和分页
路径访问的几种方式和分页效果 显示其它类别的效果和多数据分页效果 默认访问网站路径效果和多数据分页效果 URL路径访问可页面 http://localhost:5339/stationery http ...
- vue项目的webpack设置请求模拟数据的接口方法
最近在跟着视频写饿了吗vue项目,其中模拟数据由于webpack版本变化,跟视频中不一致,下方博客有解决方案,其实视频里面的还能看懂,现在webpack的服务都在插件包里了,好难找. 请参考:http ...
- Guidelines for Successful SoC Verification in OVM/UVM
By Moataz El-Metwally, Mentor Graphics Cairo Egypt Abstract : With the increasing adoption of OVM/UV ...
- PHP用*隐藏中文问题
中文截取 function substr_cut($user_name){ $strlen= mb_strlen($user_name, 'utf-8'); $firstStr= mb_substr( ...