https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=5158

这样的受到两个东西限制的,很容易想到要排序,然后加进去multiset,加的时候保证一个key是成立的,就转化为一个key的问题了。

这题需要打死m个全部的军队。

那么应该是枚举m个军队,去找一个n打死它,或者同归于尽。

开始的时候我是枚举n去选m了,这是错误的。

因为可以同归于尽,也可以杀死别人的时候(而且那个别人可以和自己一个同归于尽),不知道如何选择,

看数据吧。

#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL;
const int maxn = 1e5 + ;
struct Node {
int a, b;
}one[maxn], two[maxn];
bool cmp1(Node a, Node b) {
if (a.a != b.a) return a.a > b.a;
else return a.b < b.b;
}
bool cmp2(Node a, Node b) {
if (a.b != b.b) return a.b > b.b;
else return a.a > b.a;
}
multiset< int > ss;
int f;
void work() {
ss.clear();
int n, m;
scanf("%d%d", &n, &m);
for (int i = ; i <= n; ++i) {
scanf("%d%d", &one[i].a, &one[i].b);
}
for (int i = ; i <= m; ++i) {
scanf("%d%d", &two[i].a, &two[i].b);
}
sort(one + , one + + n, cmp1);
sort(two + , two + + m, cmp2);
int ans = n;
multiset< int > :: iterator it;
if (n < m || one[].a < two[].b) {
ans = -;
} else {
int p = ;
for (int i = ; i <= m; ++i) {
while (p <= n && one[p].a >= two[i].b) {
ss.insert(one[p].b);
p++;
}
if (ss.empty()) {
ans = -;
break;
}
it = ss.upper_bound(two[i].a);
if (it == ss.end()) {
it = ss.begin();
ss.erase(it);
ans--;
} else {
ss.erase(it);
}
}
}
printf("Case #%d: %d\n", ++f, ans);
} int main() {
#ifdef local
freopen("data.txt", "r", stdin);
// freopen("data.txt", "w", stdout);
#endif
int t;
scanf("%d", &t);
while (t--) work();
return ;
}

toshiba大佬的数据

2
5 5
16 10
19 8
20 18
8 20
6 1

13 19
5 1
8 3
1 1
13 9

10 10
3 1
15 12
4 16
13 2
20 10
12 17
17 7
14 17
18 15
12 17
6 2
7 11
6 2
16 2
16 10
9 18
9 17
13 10
9 4
16 12

I - Defeat the Enemy UVALive - 7146 二分 + 贪心的更多相关文章

  1. Defeat the Enemy UVALive - 7146

      Long long ago there is a strong tribe living on the earth. They always have wars and eonquer other ...

  2. UVALive 7146 (贪心+少许数据结构基础)2014acm/icpc区域赛上海站

    这是2014年上海区域赛的一道水题.请原谅我现在才发出来,因为我是在太懒了.当然,主要原因是我刚刚做出来. 其实去年我就已经看到这道题了,因为我参加的就是那一场.但是当时我们爆零,伤心的我就再也没有看 ...

  3. [uva_la7146 Defeat the Enemy(2014 shanghai onsite)]贪心

    题意:我方n个军队和敌方m个军队进行一对一的对战,每个军队都有一个攻击力和防御力,只要攻击力不小于对方就可以将对方摧毁.问在能完全摧毁敌方的基础上最多能有多少军队不被摧毁. 思路:按防御力从大到小考虑 ...

  4. UVALive 7146 Defeat The Enemy

    Defeat The Enemy Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu Long long ...

  5. UVa 7146 Defeat the Enemy(贪心)

    题目链接: 传送门 Defeat the Enemy Time Limit: 3000MS     Memory Limit: 32768 KB Description Long long ago t ...

  6. UVA LIVE 7146 Defeat the Enemy

    这个题跟codeforces 556 D Case of Fugitive思路一样 关于codeforces 556 D Case of Fugitive的做法的链接http://blog.csdn. ...

  7. Codeforces Gym 100231B Intervals 线段树+二分+贪心

    Intervals 题目连接: http://codeforces.com/gym/100231/attachments Description 给你n个区间,告诉你每个区间内都有ci个数 然后你需要 ...

  8. 2016-2017 ACM-ICPC CHINA-Final Ice Cream Tower 二分+贪心

    /** 题目:2016-2017 ACM-ICPC CHINA-Final Ice Cream Tower 链接:http://codeforces.com/gym/101194 题意:给n个木块,堆 ...

  9. 【bzoj2097】[Usaco2010 Dec]Exercise 奶牛健美操 二分+贪心

    题目描述 Farmer John为了保持奶牛们的健康,让可怜的奶牛们不停在牧场之间 的小路上奔跑.这些奶牛的路径集合可以被表示成一个点集和一些连接 两个顶点的双向路,使得每对点之间恰好有一条简单路径. ...

随机推荐

  1. 快速排序的JavaScript实现

    思想 分治的思想,将原始数组分为较小的数组(但没有像归并排序一样将它们分隔开). 主元选择: 从数组中任意选择一项作为主元,通常为数组的第一项,即arr[i]:或数组的中间项, arr[Math.fl ...

  2. [转]升级Flash Builder 4.6中的Flash Player版本

    Adobe自发布Flash Builder 4.6后,就暂停了Flash Builder新版本的发布.但AIR和FlashPlayer版本仍然保持不断的更新.在下载新的AIRSDK并覆盖到Flash ...

  3. ceph-deploy mon add 失败

    ceph-deploy mon add 失败 标签(空格分隔): ceph-deploy 运维 问题描述: 现有集群只有一个mon,需要通过ceph-deploy mon add添加两个mon.在ad ...

  4. Python学习:命令行运行,循环结构

    一.安装配置和运行方法 1.安装OpenCV 3.1: 假设安装目录为"C:\Python34" 2.配置环境变量: 方法一:直接配置:打开"控制面板",搜索& ...

  5. 关于ArcGis for javascript整合百度地图 天地图 高德地图进行搜索

    1.ArcGis for javascript整合百度地图搜索 1.1.首先引入百度地图的api <!-- 引入百度地图API --> <script type="text ...

  6. 树莓派 Learning 002 装机后的必要操作 --- 07 设置静态IP地址

    树莓派 装机后的必要操作 之 设置静态IP地址 我的树莓派型号:Raspberry Pi 2 Model B V1.1 装机系统:NOOBS v1.9.2 为了避免IP变来变去,我们将IP地址设置为静 ...

  7. error C2872: “flann”: 不明确的符号 --- PCL 与OpenCV2 的flann命名空间冲突问题的解决方法

    error C2872: "flann": 不明确的符号 - PCL 与OpenCV2命名空间冲突问题的解决方法 error C2872: "flann" 如果 ...

  8. 使用python ftplib包递归下载文件夹及文件

    #!/usr/bin/env python # -*- coding: utf-8 -*- # @Date : 2018-06-11 09:35:49 # @Author : Yaheng Wang ...

  9. JavaScript: 高级技巧: window 对象也可以添加自定义属性

    JavaScript: 高级技巧: window 对象也可以添加自定义属性 例如 window.ntName = 'a';例如 window.ntXw = top; 优点是, window 无须等加载 ...

  10. jQuery学习1

    学习jQuery的过程中发现了一个博客把jquery的要点整理的很不错,摘抄其精华以备学习.感谢:http://blog.csdn.net/wph_1129/article/details/59932 ...