zoukankan      html  css  js  c++  java
  • Defeat the Enemy UVALive

     

      Long long ago there is a strong tribe living on the earth. They always have wars and eonquer others. One day, there is another tribe become their target. The strong tribe has decide to terminate them!!! There are villages in the other tribe. Each village contains a troop with attack power EAttacki, and defense power EDefensei. Our tribe has troops to attack the enemy. Each troop also has the attack power Attacki, and defense power Defensei. We can use at most one troop to attack one enemy village and a troop can only be used to attack only one enemy village. Even if a troop survives an attack, it can’t be used again in another attack.

      The battle between 2 troops are really simple. The troops use their attack power to attack against the other troop simultaneously. If a troop’s defense power is less than or equal to the other troop’s attack power, it will be destroyed. It’s possible that both troops survive or destroy.

    The main target of our tribe is to destroy all the enemy troops. Also, our tribe would like to have most number of troops survive in this war.

    Input

      The first line of the input gives the number of test cases, Ttest cases follow. Each test case start with 2 numbers and m, the number of our troops and the number of enemy villages. lines follow, each with Attackand Defensei, the attack power and defense power of our troops. The next lines describe the enemy troops. Each line consist of EAttackand EDefensei, the attack power and defense power of enemy troops

    Output

      For each test ease, output one line containing ‘Case #xy’, where is the test case number (starting from 1) and is the max number of survive troops of our tribe. If it‘s impossible to destroy all enemy troops, output ‘-1’ instead.

    Limits:

    1≤ ≤100,

    1≤ n,m ≤105,

    1≤ Attacki,Defensei,EAttacki,EDefense≤109,

    Sample Input

    2

    3 2

    5 7

    7 3

    1 2

    4 4

    2 2

    2  1

    3  4

    1 10

    5 6

    Sample Output

    Case #1: 3

    Case #2: -1

     

    很久以前,地球上有一个强大的部落生活着。他们总是有战争和其他人。有一天,有另一个部落成为他们的目标。强大的部落决定终止他们!另一个部落有m个村庄。每个村庄都有一支攻击力量EAttacki和防御力量EDefensei的部队。我们的部落有n个部队来攻击敌人。每个部队还拥有攻击力Attacki和防御力Defensei。我们最多可以使用一个部队攻击一个敌方村庄,部队只能用来攻击一个敌方村庄。即使一个部队在袭击中幸存,它也不能在另一次袭击中再次使用。

    两支部队之间的战斗非常简单。部队利用其攻击力同时攻击对方。如果一个部队的防御力小于或等于另一部队的攻击力,它将被破坏。两个部队都有可能生存或摧毁。

    我们部落的主要目标是摧毁所有的敌军。此外,我们的部落希望在这场战争中有大量的部队生存下来。

    这题和我的上一篇随笔差不多,一样的原理,stl在ACM里面作用非常大啊

    注意multiset的运用

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<cmath>
     4 #include<algorithm>
     5 #include<queue>
     6 #include<set>
     7 #include<cctype>
     8 using namespace std;
     9 struct node {
    10     int x,y;
    11 } a[100010],b[100010];
    12 int cmp1(node a,node b) {
    13     return a.x>b.x;
    14 }
    15 int cmp2(node a,node b) {
    16     return a.y>b.y;
    17 }
    18 
    19 int main() {
    20     int n,t,cas=1,m;
    21     scanf("%d",&t);
    22     while(t--) {
    23         scanf("%d%d",&n,&m);
    24         multiset<int>ms;
    25         multiset<int>::iterator it;
    26         for (int i=0 ; i<n ; i++)
    27             scanf("%d%d",&a[i].x,&a[i].y);
    28         for (int i=0 ; i<m ; i++)
    29             scanf("%d%d",&b[i].x,&b[i].y);
    30         sort(a,a+n,cmp1);
    31         sort(b,b+m,cmp2);
    32         int ans=0,flag=1;
    33         for (int i=0 ,j=0; i<m ; i++ ) {
    34             while(j<n && a[j].x>=b[i].y ) {
    35                 ms.insert(a[j++].y);
    36             }
    37             if (ms.empty()) {
    38                 flag=0;
    39                 break;
    40             }
    41             it=ms.upper_bound(b[i].x);
    42             if (it==ms.end()) it=ms.begin();
    43             if (*it<=b[i].x)  ans++;
    44             ms.erase(it);
    45         }
    46         printf("Case #%d: %d
    ",cas++,flag?(n-ans):-1);
    47     }
    48     return 0;
    49 }
  • 相关阅读:
    使用NBU进行oracle异机恢复
    mycat偶尔会出现JVM报错double free or corruption并崩溃退出
    exp导出数据时丢表
    service_names配置不正确,导致dg创建失败
    XML概念定义以及如何定义xml文件编写约束条件java解析xml DTD XML Schema JAXP java xml解析 dom4j 解析 xpath dom sax
    HTTP协议简介详解 HTTP协议发展 原理 请求方法 响应状态码 请求头 请求首部 java模拟浏览器客户端服务端
    java集合框架容器 java框架层级 继承图结构 集合框架的抽象类 集合框架主要实现类
    【JAVA集合框架一 】java集合框架官方介绍 Collections Framework Overview 集合框架总览 翻译 javase8 集合官方文档中文版
    java内部类深入详解 内部类的分类 特点 定义方式 使用
    再谈包访问权限 子类为何不能使用父类protected方法
  • 原文地址:https://www.cnblogs.com/qldabiaoge/p/8530719.html
Copyright © 2011-2022 走看看