uva 11020 Efficient Solutions
题意:给你n个人,有两个属性x、y,如果不存在另外一个人x2,y2满足 x2<=x,y2<y 或者 x2<x,y2<=y,那么就称这个人是有优势的,每次给你一个人得信息,问你当前有优势的人的人数是多少?
思路:刘汝佳训练指南P228 mutiset+lower_bound+upper_bound
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<set>
#include<iostream>
using namespace std; struct Point
{
int a,b;
bool operator < (const Point& rhs) const
{
return a<rhs.a||(a==rhs.a&&b<rhs.b);
}
}; multiset<Point> S;
multiset<Point>::iterator it; int main()
{
int T;
int n,a,b;
scanf("%d",&T);
for(int i=; i<=T; i++)
{
if(i>)
printf("\n");
printf("Case #%d:\n",i);
scanf("%d",&n);
S.clear();
while(n--)
{
scanf("%d%d",&a,&b);
Point p=(Point){a,b};
it=S.lower_bound(p);
if(it==S.begin()||(--it)->b>b)
{
S.insert(p);
it=S.upper_bound(p);
while(it!=S.end()&&it->b>=b)
S.erase(it++);
}
printf("%d\n",S.size());
}
}
return ;
}
uva 11020 Efficient Solutions的更多相关文章
- UVA 11020 - Efficient Solutions(set)
UVA 11020 - Efficient Solutions 题目链接 题意:每个人有两个属性值(x, y).对于每个人(x,y)而言,当有还有一个人(x', y'),假设他们的属性值满足x' &l ...
- uva 11020 - Efficient Solutions ——平衡BST
链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&am ...
- STL(multiset) UVA 11020 Efficient Solutions
题目传送门 题意:训练指南P228 分析:照着书上的做法,把点插入后把它后面不占优势的点删除,S.size ()就是优势的人数,时间复杂度O (nlogn) #include <bits/std ...
- UVa 11020 Efficient Solutions(平衡二叉树/multiset )
题意:有n个人,每个人有x.y两个属性,每次输入一个人(x,y).如果当前不存在一个人(x`,y`)的属性满足x`<=x,y`<y或者x`<x,y`<=y,就说这个人是有优势的 ...
- UVA - 11020 Efficient Solutions(Multiset)
本题利用multiset解决.根据题意,如果我们用P(x,y)表示一个人,因为人可以相同,所以用multiset.我们会发现,如果所有人群都是有优势的,那么这些点呈现一个递减的趋势.如果刚刚插入一个人 ...
- UVa 11020 Efficient Solutions (BST)
题意:给按顺序给定 n 个人群,用x和y来描述,如果有没有任何一个x' < x y' <= y 或 x '<= x y' <= y,那么这个群体就是优势群体, 让你求出每放入一 ...
- UVA 11020 Efficient Solutions (BST,Splay树)
题意:给n个坐标.一个坐标(x,y)若有无存在的坐标满足x1<x && y1<=y 或 x1<=x && y1<y 时,此坐标(x,y)是就 ...
- UVA 11020 Efficient Solutions+multiset的应用
题目链接:点击进入 首先来讲,非常easy看到我们事实上仅仅要维护优势人群的集合:假设增加一个新的人,我们首先看一下优势人群中是否有人会让这个人失去优势,假设没有,则将这个人插入集合中.但要注意到这个 ...
- UVA 110020 Efficient Solutions (STL)
把一个人看出一个二维的点,优势的点就是就原点为左下角,这个点为右上角的矩形,包含除了右上角以外边界,其他任意地方不存在点. 那么所有有优势的点将会形成一条下凹的曲线. 因为可能有重点,用multise ...
随机推荐
- @Entity设置OneToMany
Hibernate设置bean映射数据库的方式有配置模式与注解模式,下面通过注解模式配置OneToMany @Entity @Table(name="csdnbbs_sys_catalog& ...
- BZOJ 1706: [usaco2007 Nov]relays 奶牛接力跑
Description FJ的N(2 <= N <= 1,000,000)头奶牛选择了接力跑作为她们的日常锻炼项目.至于进行接力跑的地点 自然是在牧场中现有的T(2 <= T < ...
- HZNU1015: 矩阵排序
http://acm.hznu.edu.cn/JudgeOnline/problem.php?id=1015 题意:把矩阵每一行都排序. (以前觉得很难的题目回头看看原来如此简单 ][]; ; i&l ...
- The 6th Zhejiang Provincial Collegiate Programming Contest->ProblemK:K-Nice
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3212 题意:构造出一个n*m的有k个上下左右的和等于中间数的小矩阵的任意矩 ...
- Codeforces Round #242 (Div. 2) A~C
题目链接 A. Squats time limit per test:1 secondmemory limit per test:256 megabytesinput:standard inputou ...
- 1.Getting Started with ASP.NET MVC 5
Getting Started Start by installing and running Visual Studio Express 2013 for Web or Visual Studio ...
- highcharts 根据表格转化为不同的图表
<!doctype html> <html lang="zh"> <head> <meta http-equiv="Conten ...
- windows 下 文件属性及目录列表操作
转:http://blog.sina.com.cn/s/blog_686d0fb001012tsg.html 我们需要一个结构体和几个函数.这些函数和结构体在<io.h>的头文件中,结构体 ...
- Fast Matrix Operations
A Simple Problem with Integers 每次将区间向下更新,或是用之前的方法,统计当前节点到父节点处的覆盖数目. #include <cstdio> #include ...
- Android开发:向下一个activity传递数据,返回数据给上一个activity
1.向下一个activity传递数据 activity1 Button button=(Button) findViewById(R.id.button1); button.setOnClickLis ...