题意:给按顺序给定 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. fzu 1476 矩形个数

    注意点:精度 #include<iostream> using namespace std; typedef long long ll; int main() { int a,b; ll ...

  2. sqlserver 函数里并返回一个表格数据拼接的字符串

    Create function [dbo].[GetChildWorkerExtension](     @ChildId int)returns nvarchar(100)asbegin       ...

  3. vue2.0使用Sortable.js实现的拖拽功能

    简介 在使用vue1.x之前的版本的时候,页面中的拖拽功能,我在项目中是直接用的jQuery ui中的sortable.js,只是在拖拽完成后,在update的回调函数中又重新排序了存放数据的数组.但 ...

  4. Tomcat_总结_02_单机多实例

    一.tomcat下载及环境变量配置 1.tomcat下载 下载地址:tomcat官网 2.环境变量配置 只用配置一个CATALINA_HOME就可以了 二.CATALINA_HOME 与 CATALI ...

  5. 【leetcode刷题笔记】N-Queens II

    Follow up for N-Queens problem. Now, instead outputting board configurations, return the total numbe ...

  6. 【遍历二叉树】06二叉树曲折(Z字形)层次遍历II【Binary Tree Zigzag Level Order Traversal】

    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 给定一个二叉树,返回他的Z字形层次 ...

  7. Hexo 版本

    Mac hexo s 启动Hexo服务报错如下: Error: The module '/usr/local/lib/node_modules/hexo-cli/node_modules/.0.8.0 ...

  8. Qt Create 4.6.2无法自动生成Android Kit

    开发环境: OS,Microsoft Windows [Version 10.0.17134.523] Qt,5.11.1 Qt Creator,4.6.2 JDK,1.8.0_181 Android ...

  9. poj3252 Round Numbers[数位DP]

    地址 拆成2进制位做dp记搜就行了,带一下前导0,将0和1的个数带到状态里面,每种0和1的个数讨论一下,累加即可. WA记录:line29. #include<iostream> #inc ...

  10. 冷备手工完全恢复(recover database,recover tablespace,recover datafile)

    冷备手工完全恢复 1.   手工完全恢复三种级别: recover database: 所有或大部分datafile丢失,一般是在mount状态完成.recover tablespace:    非关 ...