uva 11729 - Commando War

点击打开链接uva 11729

思路:贪心
分析:
1 给定n个人的交待任务的时间和完成任务的时间,要求不能同时给两个人交代任务,但是可以多人同时去做任务,求最短的完成任务的时间
2 根据贪心的原则,我们知道执行时间比较长的任务必须先交待,于是我们只要对这n个任务按照完成任务的时间进行排序,然后枚举n个人进去求解即可。

代码:

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

const int MAXN = 1010;
struct Node{
   int b;
   int j;
   bool operator<(const Node& tmp)const{
      if(j > tmp.j)
        return true;
      if(j == tmp.j && b < tmp.b)
        return true;
      return false;
   }
};
int n;
Node node[MAXN];

int main(){
    int Case = 1;
    while(scanf("%d" , &n) && n){
        for(int i = 0 ; i < n ; i++)
           scanf("%d%d" , &node[i].b , &node[i].j);
        sort(node , node+n);
        int ans , tmp;
        tmp = ans = 0;
        for(int i = 0 ; i < n ; i++){
           tmp += node[i].b;//当前任务的开始的执行时间
           ans = max(ans , tmp+node[i].j);//更新任务的最晚结束的时间
        }
        printf("Case %d: %d\n" , Case++ , ans);
    }
    return 0;

}
时间: 2024-09-23 00:11:43

uva 11729 - Commando War的相关文章

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

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之409 - Excuses, Excuses!

 Excuses, Excuses!  Judge Ito is having a problem with people subpoenaed for jury duty giving rather lame excuses in order to avoid serving. In order to reduce the amount of time required listening to goofy excuses, Judge Ito has asked that you write

UVa 402 M*A*S*H (STL&amp;amp;list)

402 - M*A*S*H Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=343 Corporal Klinger is a member of the 4077th Mobile Army Surgical Hospital in the Korean W

UVa 409 Excuses, Excuses! (字符串匹配)

409 - Excuses, Excuses! Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=96&page=show_problem&problem=350 Judge Ito is having a problem with people subpoenaed for jury duty giving rath

刘汝佳uva 字符串专题

第一题   palindrome 点击打开链接uva 401 题目意思:给定一个字符串判断是什么类型 分析: 1 根据输出我们知道这个字符串总共有4种类型 2 首先应该是否是"palindrome ",判断的理由很简单直接对这个字符串进行判断,但是这里有个地方会出错就是'0'和'O',题目明确说明了'0'和'O'看成相同,所以我们应该在输入的时候就把所有的'0'处理成'O',注意这里不能把'O'改成'0'(想想为什么?) 3 接下来判断是否是"mirrored string&

UVa 10602

链接: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=113&page=show_problem&problem=1543 类型:贪心 原题: Company Macrohard has released it's new version of editor Nottoobad, which can understand a few voice commands.

UVa 10392 Factoring Large Numbers:素因子分解

10392 - Factoring Large Numbers Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=100&page=show_problem&problem=1333 One of the central ideas behind much cryptography is that factoring

UVa 10182 Bee Maja:规律&amp;amp;O(1)算法

10182 - Bee Maja Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1123 Maja is a bee. She lives in a bee hive with thousands of other bees. This bee hive c