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 theattack power Attacki, and defense power Defensei. We can use at most one troop to attack one enemyvillage and a troop
can only be used to attack only one enemy village. Even if a troop survives anattack, 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 againstthe other troop simultaneously.
If a troop’s defense power is less than or equal to the other troop’sattack 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 havemost
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 startwith 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 mlines describe the enemy troops. Each line consist of EAttacki and EDefensei, the attack power anddefense power of enemy troops
Output
For each test ease, output one line containing ‘Case #x: y’, where x is the test case number (startingfrom 1) and y is the max number of survive troops of our tribe. If it‘s impossible to destroy all enemytroops, 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
题意:我方有n个军队,敌方有m个军队,每一个军队有攻击力a[i].l和防御力a[i].r,我方的每一个军队只能攻击一个敌方的军队,且只能攻击一次,当攻击的军队的攻击力大于等于敌方的防御力,若防御力大于等于敌方的攻击力,那么敌方军队消灭,且我方攻击的军队还存在,否则我两个军队同归于尽,问要把敌方的m个军队都消灭,我方至少损失多少军队。
思路:可以先把两个的军队分别按攻击力从大到小排序,依次询问敌方m个军队,把我方攻击力大于当前询问的敌方军队的军队都加入到set里面,然后再set里找到比当前询问的敌方军队防御力第一个大的军队,用它把它消灭,如果找不到,那么直接break或者删去set里的第一个。
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<string>
#include<algorithm>
using namespace std;
#define ll long long
#define inf 0x7fffffff
#define maxn 100050
struct node{
int l,r;
}a[maxn],b[maxn];
bool cmp(node a,node b){
return a.l>b.l;
}
multiset<int>myset;
multiset<int>::iterator it;
int main()
{
int n,m,i,j,T,t,ans;
scanf("%d",&T);
int num1=0;
while(T--)
{
scanf("%d%d",&n,&m);
for(i=1;i<=n;i++){
scanf("%d%d",&a[i].l,&a[i].r);
}
for(i=1;i<=m;i++){
scanf("%d%d",&b[i].r,&b[i].l);
}
sort(a+1,a+1+n,cmp);
sort(b+1,b+1+m,cmp);
myset.clear();
t=1;ans=n;
for(i=1;i<=m;i++){
while(t<=n && a[t].l>=b[i].l){
myset.insert(a[t].r);t++;
}
if(myset.size()==0){
ans=-1;break;
}
it=myset.upper_bound(b[i].r);
if(it==myset.end()){
ans--;
myset.erase(myset.begin() );
}
else{
myset.erase(it);
}
}
num1++;
printf("Case #%d: %d\n",num1,ans);
}
return 0;
}
UVALive 7146的更多相关文章
- 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. ...
- Defeat the Enemy UVALive - 7146
Long long ago there is a strong tribe living on the earth. They always have wars and eonquer other ...
- UVALive 7146 (贪心+少许数据结构基础)2014acm/icpc区域赛上海站
这是2014年上海区域赛的一道水题.请原谅我现在才发出来,因为我是在太懒了.当然,主要原因是我刚刚做出来. 其实去年我就已经看到这道题了,因为我参加的就是那一场.但是当时我们爆零,伤心的我就再也没有看 ...
- 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 ...
- UVALive - 4108 SKYLINE[线段树]
UVALive - 4108 SKYLINE Time Limit: 3000MS 64bit IO Format: %lld & %llu Submit Status uDebug ...
- UVALive - 3942 Remember the Word[树状数组]
UVALive - 3942 Remember the Word A potentiometer, or potmeter for short, is an electronic device wit ...
- UVALive - 3942 Remember the Word[Trie DP]
UVALive - 3942 Remember the Word Neal is very curious about combinatorial problems, and now here com ...
- 思维 UVALive 3708 Graveyard
题目传送门 /* 题意:本来有n个雕塑,等间距的分布在圆周上,现在多了m个雕塑,问一共要移动多少距离: 思维题:认为一个雕塑不动,视为坐标0,其他点向最近的点移动,四舍五入判断,比例最后乘会10000 ...
随机推荐
- 【Sphinx】 为Python自动生成文档
sphinx 前言 Sphinx是一个可以用于Python的自动文档生成工具,可以自动的把docstring转换为文档,并支持多种输出格式包括html,latex,pdf等 开始 建一个存放文档的do ...
- Kubernetes学习笔记之认识Kubernetes组件
前言:笔记知识点来源于Kubernetes官方文档说明,链接:https://kubernetes.io/docs/concepts/overview/components/ ,本记录仅仅是学习笔记记 ...
- Nginx基础知识学习(安装/进程模型/事件处理机制/详细配置/定时切割日志)
一.Linux下Nginx的安装 1.去官网 http://nginx.org/download/下载对应的Nginx安装包,推荐使用稳定版本. 2.上传Nginx到Linux服务器. 3.安装依赖环 ...
- python学习笔记 | PyCharm出现卡顿解决方法
问题:使用pycharm时常出现 the IDE is running low on memory 的问题 表示pycharm这款IDE使用内存不足 需要在系统内存充足的情况下扩充IDE memory ...
- 【分布式锁的演化】终章!手撸ZK分布式锁!
前言 这应该是分布式锁演化的最后一个章节了,相信很多小伙伴们看完这个章节之后在应对高并发的情况下,如何保证线程安全心里肯定也会有谱了.在实际的项目中也可以参考一下老猫的github上的例子,当然代码没 ...
- 基础篇-http协议《http 简介、url详解、request》
目录 一.http 简介 二.url 详解 三.request 1.get 和 post 2.请求方法 3.request 组成 4.请求头 5.get 请求参数 6.post 请求参数 7.post ...
- 【RAC】运行root.sh的时候报错root.sh Oracle CRS stack is already configured and will be running under init(1M)
环境:oracle10g 系统:CentOS6.4 开始的时候,在节点1上运行root.sh发现出现90s 的时候hang住了,结束掉,结局完事后,再次运行root.sh报错 WARNING: dir ...
- apiAutoTest: 接口自动化测试的数据清洗(备份/恢复)处理方案
接口自动化测试之数据清洗/隔离/备份/恢复 在得到QQ:1301559180 得代码贡献之后,想到了通过ssh连接上服务器,然后进行数据库备份,数据库恢复, 主要使用了 paramiko库 最终效果 ...
- three.js cannon.js物理引擎之约束
今天郭先生继续说cannon.js,主演内容就是点对点约束和2D坐标转3D坐标.仍然以一个案例为例,场景由一个地面.若干网格组成的约束体和一些拥有初速度的球体组成,如下图.线案例请点击博客原文. 下面 ...
- 使用pushplus+python实现亚马逊到货消息推送微信
xbox series和ps5发售以来,国内黄牛价格一直居高不下.虽然海外amazon上ps5补货很少而且基本撑不过一分钟,但是xbox series系列明显要好抢很多. 日亚.德亚的xbox ser ...