Defeat the Enemy UVALive - 7146
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 m villages in the other tribe. Each village contains a troop with attack power EAttacki, and defense power EDefensei. Our tribe has n 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, T. T test cases follow. Each test case start with 2 numbers n and m, the number of our troops and the number of enemy villages. n lines follow, each with Attacki and Defensei, the attack power and defense power of our troops. The next m lines describe the enemy troops. Each line consist of EAttacki and EDefensei, the attack power and defense power of enemy troops
Output
For each test ease, output one line containing ‘Case #x: y’, where x is the test case number (starting from 1) and y is the max number of survive troops of our tribe. If it‘s impossible to destroy all enemy troops, output ‘-1’ instead.
Limits:
1≤ T ≤100,
1≤ n,m ≤105,
1≤ Attacki,Defensei,EAttacki,EDefensei ≤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的运用
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<set>
#include<cctype>
using namespace std;
struct node {
int x,y;
} a[],b[];
int cmp1(node a,node b) {
return a.x>b.x;
}
int cmp2(node a,node b) {
return a.y>b.y;
} int main() {
int n,t,cas=,m;
scanf("%d",&t);
while(t--) {
scanf("%d%d",&n,&m);
multiset<int>ms;
multiset<int>::iterator it;
for (int i= ; i<n ; i++)
scanf("%d%d",&a[i].x,&a[i].y);
for (int i= ; i<m ; i++)
scanf("%d%d",&b[i].x,&b[i].y);
sort(a,a+n,cmp1);
sort(b,b+m,cmp2);
int ans=,flag=;
for (int i= ,j=; i<m ; i++ ) {
while(j<n && a[j].x>=b[i].y ) {
ms.insert(a[j++].y);
}
if (ms.empty()) {
flag=;
break;
}
it=ms.upper_bound(b[i].x);
if (it==ms.end()) it=ms.begin();
if (*it<=b[i].x) ans++;
ms.erase(it);
}
printf("Case #%d: %d\n",cas++,flag?(n-ans):-);
}
return ;
}
Defeat the Enemy UVALive - 7146的更多相关文章
- I - Defeat the Enemy UVALive - 7146 二分 + 贪心
https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...
- UVALive 7146 Defeat The Enemy
Defeat The Enemy Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu Long long ...
- UVA LIVE 7146 Defeat the Enemy
这个题跟codeforces 556 D Case of Fugitive思路一样 关于codeforces 556 D Case of Fugitive的做法的链接http://blog.csdn. ...
- UVa 7146 Defeat the Enemy(贪心)
题目链接: 传送门 Defeat the Enemy Time Limit: 3000MS Memory Limit: 32768 KB Description Long long ago t ...
- UVALive 7146 Defeat the Enemy(贪心+STL)(2014 Asia Shanghai Regional Contest)
Long long ago there is a strong tribe living on the earth. They always have wars and eonquer others. ...
- UVALive 7146
Long long ago there is a strong tribe living on the earth. They always have wars and eonquer others. ...
- UVALive 7146 (贪心+少许数据结构基础)2014acm/icpc区域赛上海站
这是2014年上海区域赛的一道水题.请原谅我现在才发出来,因为我是在太懒了.当然,主要原因是我刚刚做出来. 其实去年我就已经看到这道题了,因为我参加的就是那一场.但是当时我们爆零,伤心的我就再也没有看 ...
- [uva_la7146 Defeat the Enemy(2014 shanghai onsite)]贪心
题意:我方n个军队和敌方m个军队进行一对一的对战,每个军队都有一个攻击力和防御力,只要攻击力不小于对方就可以将对方摧毁.问在能完全摧毁敌方的基础上最多能有多少军队不被摧毁. 思路:按防御力从大到小考虑 ...
- 25 Killer Actions to Boost Your Self-Confidence
25 Killer Actions to Boost Your Self-Confidence Once we believe in ourselves, we can risk curiosity, ...
随机推荐
- python---协程 学习笔记
协程 协程又称为微线程,协程是一种用户态的轻量级线程 协程拥有自己的寄存器和栈.协程调度切换的时候,将寄存器上下文和栈都保存到其他地方,在切换回来的时候,恢复到先前保存的寄存器上下文和栈,因此:协程能 ...
- Promise对象的简单用法
要了解一个东西,首先要从,它是什么.用来做什么以及怎么取用它这三个方面来了解. 首先,promise是什么? 我们来参考一下MDN对它的定义: Promise 对象用于一个异步操作的最终完成(或失败) ...
- grep命令的-P选项
man grep的时候有一个-P,文档上的英文: -P, --perl-regexp Interpret PATTERN as a Perl regular expression. This is ...
- 【NOIP2015】字串
[NOIP2015]字串 标签: DP NOIP Description 有两个仅包含小写英文字母的字符串 A 和 B.现在要从字符串 A 中取出 k 个互不重叠的非空子串,然后把这 k 个子串按照其 ...
- Mysql(一):初识数据库
一 数据库管理软件的由来 基于我们之前所学,数据要想永久保存,都是保存于文件中,毫无疑问,一个文件仅仅只能存在于某一台机器上. 如果我们暂且忽略直接基于文件来存取数据的效率问题,并且假设程序所有的组件 ...
- WinXP系统下Opencms的安装与配置
1.WinXP系统下安装opencms (1)mysql已安装5.1.40 cmd命令行:mysql -uroot -proot (2)OpenCMS在安装时要求MySQL系统变量“max_al ...
- Java经典编程题50道之三十
有一个已经排好序的数组.现输入一个数,要求按原来的规律将它插入数组中. public class Example30 { public static void main(String[] arg ...
- echarts legend 重叠 (转载)
解决方案: 1. 调整option中的grid.top值才能避免重叠:(可以设置定制,也可以定义了一个计算公式) 2. 文档注明[特殊字符串 ''(空字符串)或者 '\n' (换行字符串)用于图例的 ...
- 通过Yii来理解MVC
模型:是表现业务数据.规则和逻辑的对象. 可以通过集成yii\base\Model或者它的子类定义模型类. 基类yii\base\Model支持许多实用的特性: A 属性:表现业务数据,可以像普通类属 ...
- 动态规划算法的java实现
一:动态规划 1)动态规划的向前处理法 java中没有指针,所以邻接表的存储需要转化一中形式,用数组存储邻接表 用三个数组u,v,w存储边,u数组代表起点,v数组代表终点,w代表权值;例如:1--&g ...