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了,这是错误的。

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

看数据吧。

  1. #include <bits/stdc++.h>
  2. #define IOS ios::sync_with_stdio(false)
  3. using namespace std;
  4. #define inf (0x3f3f3f3f)
  5. typedef long long int LL;
  6. const int maxn = 1e5 + ;
  7. struct Node {
  8. int a, b;
  9. }one[maxn], two[maxn];
  10. bool cmp1(Node a, Node b) {
  11. if (a.a != b.a) return a.a > b.a;
  12. else return a.b < b.b;
  13. }
  14. bool cmp2(Node a, Node b) {
  15. if (a.b != b.b) return a.b > b.b;
  16. else return a.a > b.a;
  17. }
  18. multiset< int > ss;
  19. int f;
  20. void work() {
  21. ss.clear();
  22. int n, m;
  23. scanf("%d%d", &n, &m);
  24. for (int i = ; i <= n; ++i) {
  25. scanf("%d%d", &one[i].a, &one[i].b);
  26. }
  27. for (int i = ; i <= m; ++i) {
  28. scanf("%d%d", &two[i].a, &two[i].b);
  29. }
  30. sort(one + , one + + n, cmp1);
  31. sort(two + , two + + m, cmp2);
  32. int ans = n;
  33. multiset< int > :: iterator it;
  34. if (n < m || one[].a < two[].b) {
  35. ans = -;
  36. } else {
  37. int p = ;
  38. for (int i = ; i <= m; ++i) {
  39. while (p <= n && one[p].a >= two[i].b) {
  40. ss.insert(one[p].b);
  41. p++;
  42. }
  43. if (ss.empty()) {
  44. ans = -;
  45. break;
  46. }
  47. it = ss.upper_bound(two[i].a);
  48. if (it == ss.end()) {
  49. it = ss.begin();
  50. ss.erase(it);
  51. ans--;
  52. } else {
  53. ss.erase(it);
  54. }
  55. }
  56. }
  57. printf("Case #%d: %d\n", ++f, ans);
  58. }
  59.  
  60. int main() {
  61. #ifdef local
  62. freopen("data.txt", "r", stdin);
  63. // freopen("data.txt", "w", stdout);
  64. #endif
  65. int t;
  66. scanf("%d", &t);
  67. while (t--) work();
  68. return ;
  69. }

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. POJ2069:Super Star

    我对模拟退火的理解:https://www.cnblogs.com/AKMer/p/9580982.html 我对爬山的理解:https://www.cnblogs.com/AKMer/p/95552 ...

  2. 如何得到DataTable的列名

    foreach (DataColumn dc in dtfood.Columns) { string lm = dc.ColumnName; }

  3. HDU1247(经典字典树)

    Hat’s Words Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  4. java代码throws异常

    总结:抛出异常 package com.ds; //异常捕获 public class fdsg { private static void throwException() { try { Stri ...

  5. zk 02之 Windows安装和使用zookeeper

    本文介绍的 Zookeeper 是以 3.4.5 这个稳定版本为基础,最新的版本可以通过官网 http://hadoop.apache.org/zookeeper/来获取,Zookeeper 的安装非 ...

  6. kubeadm 搭建 K8S集群

    kubeadm是K8s官方推荐的快速搭建K8s集群的方法. 环境: Ubuntu 16.04 1 安装docker Install Docker from Ubuntu’s repositories: ...

  7. oracle--视图(2)---

    Oracle---视图 视图是基于一个表或多个表或视图的逻辑表,本身不包含数据,通过它可以对表里面的数据进行查询和修改.视图基于的表称为基表,Oracle的数据库对象分为五种:表,视图,序列,索引和同 ...

  8. JVM类加载(4)—加载器

    定义: 虚拟机设计团队把类加载阶段中“通过一个类的全限定名来获取描述此类的二进制字节流”这个动作放到虚拟机外部去实现,以便让应用程序自己决定如何去获取所需要的类.实现这个动作的代码模块称之为“类加载器 ...

  9. java try catch 与 throws 使用场景以及怎么合理使用?

    对于如下场景,给出不同的看法: 其实我更多的疑问在于,自定义的方法里面java api抛出了异常,这个时候,我是需要捕获呢?还是我也继续往上抛. 比如,我这里定义了一个日期处理的方法,有两种对异常的处 ...

  10. hdu1073

    #include<iostream> using namespace std; #define N 5050 char a[N],b[N],tmp[N]; void Read(char p ...