【UVA11729】Commando War

给n个人分配任务 分配任务的时间b和执行任务的时间j 每一次只能给一个人分配任务 求最小的时间

贪心求解  将任务 按照执行时间从长到短排序 依次分配任务 并执行 求出时间即所得最短时间 证明自证

#include <cstdio>
#include <algorithm>
using namespace std;

const int maxn = 1010;
struct Job{
    int b, j;
    bool operator < (const Job& x) const{
        return j > x.j;
    }
}job[maxn];

int main(){
    int n;
    int cas = 0;
    while(scanf("%d", &n)!=EOF && n){
        for(int i = 0; i < n; ++i){
            scanf("%d%d", &job[i].b, &job[i].j);
        }
        sort(job, job+n);

        int cnt = 0;
        int ans = 0;
        for(int i = 0; i < n; ++i){
            cnt += job[i].b;
            ans = max(ans, cnt + job[i].j);
        }

        printf("Case %d: %d\n", ++cas, ans);
    }
    return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-08-29 13:19:23

【UVA11729】Commando War的相关文章

【Maven】构建war包时排除web.xml

经过多次尝试,终于可以在打包时在maven-war-plugin中配置来忽略掉web.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.o

【poj1085】 Triangle War

http://poj.org/problem?id=1085 (题目链接) 题意 A,B两人玩游戏,在一个大三角形上放火柴,若A放上一根火柴后成功组成一个三角形,那么这个三角形就归属于A,并且A被奖励再放一根火柴.最后谁三角形多谁就胜. 给出一个残局,判断是否存在先手必胜策略. Solution 最近一直在颓,好久没刷题了... 这就是神乎其技的极大极小搜索,其实也差不多就是个贪心,基本很少用上,因为很难判断估价函数的正确性..详情请见:http://blog.csdn.net/gwq5210/

【Algorithm】平面图最小割转最短路

杭电上碰巧有几道求最小割的题目,用网络流解超时.通过离散数学中的一些知识可以将平面图最小割转化为最短路径,通过最短路解提高效率.这个转化过程很简单,但是很巧妙,详细内容可以参考<浅析最大最小定理在信息学竞赛中的应用>. 1. [HDU] 3870 Catch the Theves有一个网格拓扑,每条边都表示有$A_{ij}$个小偷,现在希望对其中一条边部署警察,使得小偷不可能偷到右下角的财宝.求至少需要多少个警察?这题是个挺有实际意义的题目,基本思路也很简单.因为题目给定小偷都从左上角出发向右

uva----11729 Commando war (突击战争)

G Commando War Input: Standard Input Output: Standard Output "Waiting for orders we held in the wood, word from the front never came By evening the sound of the gunfire was miles away Ah softly we moved through the shadows, slip away through the tree

hihoCoder 1392 War Chess 【模拟】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2016)网络赛)

#1392 : War Chess 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 Rainbow loves to play kinds of War Chess games. There are many famous War Chess games such as "Biography of Cao Cao", "Anecdotes of Wagang Mountain", etc. In this problem, let's c

【Java】eclipse导入war包二次开发

有实际项目在跑的war包,却没有源码,苦于想查看源码,身处运维组为研发组看不起,拿不到源码,只能自己来反编译了. 其实很简单!!!! 其实很简单!!!! 其实很简单!!!! 重要的事情说三遍! 只要你细心点,其实在解压war包后,可以看到文件夹中,已经存在了jsp文件,但是却没有逻辑代码层(action.bean等等).再仔细在WEB-INF文件夹下查看,会发现class文件却都存在,那就好办了.推荐一款反编译class的工具[JD-GUI],下载地址:http://www.duote.com/

【Linux】Jenkins以war包运行及开机启动配置(四)

本例介绍jenkins已war包运行及开机启动配置 环境:Linux环境(CentOS 7.4) 以war包运行 1.下载jenkins.war包 2.启动war包( 默认端口:8080,默认JENKINS_HOME目录:-/.jenkins ) 前台启动命令:java -jar jenkins.war 后台启动命令:nohup java -jar jenkins.war & 3.使用浏览器打开地址:http://ip:8080,即可访问到jenkins 关闭jenkins,页面访问地址:htt

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 commando squad at your disposal and planning an ambush on an important enemy camp located nearby. You have N soldiers in your squad. In your master-p

UVA 11729 Commando War 题解

“Waiting for orders we held in the wood, word from the front never came By evening the sound of the gunfire was miles away Ah softly we moved through the shadows, slip away through the trees Crossing their lines in the mists in the fields on our hand