UVA LIVE 7146 Defeat the Enemy
这个题跟codeforces 556 D Case of Fugitive思路一样
关于codeforces 556 D Case of Fugitive的做法的链接http://blog.csdn.net/stl112514/article/details/46868749
题意大概我方有n个军队,敌方有m个军队。军队有两个属性:攻击力和防御力
一个军队能打败还有一个军队的条件:一军队攻击力不低于还有一个军队防御力
大概是2014上海区域赛最简单的一个题?
#include<map>
#include<string>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<vector>
#include<iostream>
#include<algorithm>
#include<bitset>
#include<climits>
#include<list>
#include<iomanip>
#include<stack>
#include<set>
using namespace std;
struct Tr
{
int at,df;
bool operator <(Tr one)const
{
return df<one.df;
}
}gd[int(1e5)+10],bd[int(1e5)+10];
bool cmp(Tr one,Tr two)
{
return one.at>two.at;
}
bool cmp1(Tr one,Tr two)
{
return one.df>two.df;
}
int main()
{
int T;
cin>>T;
for(int cs=1;cs<=T;cs++)
{
int n,m;
cin>>n>>m;
for(int i=0;i<n;i++)
cin>>gd[i].at>>gd[i].df;
for(int i=0;i<m;i++)
cin>>bd[i].at>>bd[i].df;
sort(gd,gd+n,cmp);
sort(bd,bd+m,cmp1);
map<Tr,int>mp;
int ans=0;
for(int i=0,j=0;i<m;i++)
{
while(j<n&&gd[j].at>=bd[i].df)
mp[gd[j++]]++;
if(mp.empty())
{
ans=-1;
break;
}
map<Tr,int>::iterator it;
swap(bd[i].at,bd[i].df);
it=mp.upper_bound(bd[i]);
swap(bd[i].at,bd[i].df);
if(it==mp.end())
it=mp.begin();
Tr t=it->first;
it->second--;
if(it->second==0)
mp.erase(it);
if(t.at<bd[i].df)
{
ans=-1;
break;
}
if(t.df<=bd[i].at)
ans++;
}
if(ans!=-1)
ans=n-ans;
printf("Case #%d: %d\n",cs,ans);
}
return 0;
}
Time Limit:3000MS
7146 Defeat The Enemy
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
ACM-ICPC Live Archive: 7146 – Defeat The Enemy 2/2
Sample Output
Case #1: 3
Case #2: -1
UVA LIVE 7146 Defeat the Enemy的更多相关文章
- 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
Defeat The Enemy Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu Long long ...
- 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. ...
- UVA LA 7146 2014上海亚洲赛(贪心)
option=com_onlinejudge&Itemid=8&page=show_problem&category=648&problem=5158&mosm ...
- Defeat the Enemy UVALive - 7146
Long long ago there is a strong tribe living on the earth. They always have wars and eonquer other ...
- I - Defeat the Enemy UVALive - 7146 二分 + 贪心
https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...
- [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, ...
- Codeforces 240E. Road Repairs 最小树形图+输出路径
最小树形图裸题,只是须要记录路径 E. Road Repairs time limit per test 2 seconds memory limit per test 256 megabytes i ...
随机推荐
- 前端h5开发调试神奇vconsole
(1)项目中安装vconcole插件 npm install vconcole (2)在vue项目中main.js中引入插件 import Vconsole from 'vconsole'; cons ...
- JS高级——instanceof语法
基本语法 对象 instanceof 构造函数 基本使用 <script> function Person() { } //p--->Person.prototype--->O ...
- SQL基本操作——GROUP BY
GROUP BY 语句用于结合合计函数,根据一个或多个列对结果集进行分组. SQL GROUP BY 实例:我们拥有下面这个 "Orders" 表 O_Id OrderDate O ...
- 使用doxmate生成文档
主页:http://html5ify.com/doxmate/ 在windows下面使用doxmate 1. 下载node.js(msi)并安装 http://www.nodejs.org/downl ...
- 設置VS2015
減少VsHub的資源占用 VsHub在某些環境下會挂,原因見這個帖子 其作用簡述如下: First, the service that detects and auto-updates extensi ...
- HDU_5723_最小生成树+任意两点距离的期望
Abandoned country Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
- 关于在win7旗舰版32位上 安装 net4.0 的闪退问题研究 和安装sqlserver2008问题
1.配置文件客户端[目标x86x64]的 可以安装 2.配置文件完全的目标x86x64的 出现闪退. 3.服务器核心的出现无法安装 安装 sqlserver 2008R2数据库 报错 \最后留下了它, ...
- c#中通过事件实现按下回车跳转控件
//接受用户输入参数后回车事件 private void tb_KeyPress(object sender, KeyPressEventArgs e) { ) { SendKeys.Send(&qu ...
- 洛谷——P1966 火柴排队&&P1774 最接近神的人_NOI导刊2010提高(02)
P1966 火柴排队 这题贪心显然,即将两序列中第k大的数的位置保持一致,证明略: 树状数组求逆序对啦 浅谈树状数组求逆序对及离散化的几种方式及应用 方法:从前向后每次将数插入到bit(树状数组)中, ...
- C++ 中 字符数组 和 指针 区别
char str1[] = "abc"; char str2[] = "abc"; const char str3[] = "abc"; c ...