题意:给按顺序给定 n 个人群,用x和y来描述,如果有没有任何一个x' < x y' <= y 或 x '<= x y' <= y,那么这个群体就是优势群体,

让你求出每放入一个人群,已经知道的群体有几个优势群体。

析:首先我们知道的是,如果某个群体失去了优势,那么该群体就不可能再获得优势,然后我们把已经得到的优势群体按x 从小到大排序,

那么得到曲线是一个向下的也就是严格递减的,所以我们就可以用multiset来维护所有的优势群体,然后我们考虑每加入一个群体,

如果在坐标上画出来的满足该要求,那么就是有优势,然后再删掉后面没有优势的。

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <sstream>
#define debug() puts("++++");
#define gcd(a, b) __gcd(a, b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const LL LNF = 1e16;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 1e5 + 10;
const int mod = 1e9 + 7;
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}
struct Node{
int x, y;
bool operator < (const Node &p) const{
return x < p.x || (x == p.x && y < p.y);
}
};
multiset<Node> sets;
multiset<Node> :: iterator it; int main(){
int T; cin >> T;
for(int kase = 1; kase <= T; ++kase){
if(kase > 1) printf("\n");
sets.clear();
printf("Case #%d:\n", kase);
scanf("%d", &n);
for(int i = 0; i < n; ++i){
int x, y;
scanf("%d %d", &x, &y);
it = sets.lower_bound((Node){x, y});
if(it == sets.begin() || (--it)->y > y){
sets.insert((Node){x, y});
it = sets.upper_bound((Node){x, y});
while(it != sets.end() && it->y >= y) it = sets.erase(it);
}
printf("%d\n", sets.size());
}
}
return 0;
}

  

UVa 11020 Efficient Solutions (BST)的更多相关文章

  1. UVA 11020 - Efficient Solutions(set)

    UVA 11020 - Efficient Solutions 题目链接 题意:每个人有两个属性值(x, y).对于每个人(x,y)而言,当有还有一个人(x', y'),假设他们的属性值满足x' &l ...

  2. uva 11020 - Efficient Solutions ——平衡BST

    链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&am ...

  3. UVA 11020 Efficient Solutions (BST,Splay树)

    题意:给n个坐标.一个坐标(x,y)若有无存在的坐标满足x1<x && y1<=y  或  x1<=x && y1<y 时,此坐标(x,y)是就 ...

  4. STL(multiset) UVA 11020 Efficient Solutions

    题目传送门 题意:训练指南P228 分析:照着书上的做法,把点插入后把它后面不占优势的点删除,S.size ()就是优势的人数,时间复杂度O (nlogn) #include <bits/std ...

  5. UVa 11020 Efficient Solutions(平衡二叉树/multiset )

    题意:有n个人,每个人有x.y两个属性,每次输入一个人(x,y).如果当前不存在一个人(x`,y`)的属性满足x`<=x,y`<y或者x`<x,y`<=y,就说这个人是有优势的 ...

  6. uva 11020 Efficient Solutions

    题意:给你n个人,有两个属性x.y,如果不存在另外一个人x2,y2满足 x2<=x,y2<y 或者 x2<x,y2<=y,那么就称这个人是有优势的,每次给你一个人得信息,问你当 ...

  7. UVA - 11020 Efficient Solutions(Multiset)

    本题利用multiset解决.根据题意,如果我们用P(x,y)表示一个人,因为人可以相同,所以用multiset.我们会发现,如果所有人群都是有优势的,那么这些点呈现一个递减的趋势.如果刚刚插入一个人 ...

  8. UVA 11020 Efficient Solutions+multiset的应用

    题目链接:点击进入 首先来讲,非常easy看到我们事实上仅仅要维护优势人群的集合:假设增加一个新的人,我们首先看一下优势人群中是否有人会让这个人失去优势,假设没有,则将这个人插入集合中.但要注意到这个 ...

  9. UVA 110020 Efficient Solutions (STL)

    把一个人看出一个二维的点,优势的点就是就原点为左下角,这个点为右上角的矩形,包含除了右上角以外边界,其他任意地方不存在点. 那么所有有优势的点将会形成一条下凹的曲线. 因为可能有重点,用multise ...

随机推荐

  1. 各种IoC框架下实现AOP

    .Net AOP(五) 各种IoC框架下实现AOP 利用AOP可以对业务逻辑的各个部分进行隔离,从而使得业务逻辑各部分之间的耦合度降低,提高程序的可重用性,同时提高了开发的效率 主要功能 日志记录,性 ...

  2. JavaScript 使用技巧(持续更新)

    JavaScript 使用技巧(持续更新) 类型检测 使用Object.prototype.toString.call(obj)的方式. 因为无论typeof还是instanceof都无法做到精确判断 ...

  3. Git_错误_03_ Git提交时显示用户 unknown

    这是因为没有设置用户名 $ git config --global user.name "your_name" $ git config --global user.email & ...

  4. hdu-5867 Water problem(水题)

    题目链接: Water problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Othe ...

  5. VScode 为 *.cu文件 添加高亮及c++ intelligence相关操作的方法

    问题:*.cu在VScode不能像*.cc或*.cpp一样在c++及c++ intelligence插件有关键字的高亮以及go to definition等的操作 解决方案:添加*.cu与*.cpp文 ...

  6. STL defalloc.h

    defalloc.h . // Filename: defalloc.h . . // Comment By: 凝霜 . // E-mail: mdl2009@vip.qq.com . // Blog ...

  7. Skype SILK vs. iLBC vs. Speex

    对比一下这三种VOIP语音算法的特点: 1 参数与特征 2 SILK性能 关于iLBC和Speex的性能可以参考以前写的文章. 3 关于VOIP一些观点(仅代表个人观点) 1)  Skype 辛苦三年 ...

  8. 影响Cache的几个HTTP头信息【转载http://hi.baidu.com/feilala_fly/item/f79eca08fbf389026c9048a7】

    Http的Cache机制总共有4个组成部分: Cache-Control.Last-Modified(If-Modified-Since).Etag(If-None-Match) .Expires 服 ...

  9. [IBM]掌握Ajax,Ajax中的高级请求和响应

    掌握 Ajax, Ajax 中的高级请求和响应 http://www.ibm.com/developerworks/cn/xml/wa-ajaxintro1.html http://www.ibm.c ...

  10. 洛谷【P1009】阶乘之和

    题目传送门:https://www.luogu.org/problemnew/show/P1009 高精度加法:https://www.cnblogs.com/AKMer/p/9722610.html ...