主题链接:点击打开链接

升序右键点。采取正确的点

删边暴力

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <iostream>
#include <map>
#include <set>
#include <math.h>
using namespace std;
#define inf 10000000
#define ll int
#define N 2105
#define L(x) (x<<1)
#define R(x) (x<<1|1)
inline ll Mid(ll a,ll b){return (a+b)>>1;}
ll n;
struct node{
ll x,y;
}a[N];
bool cmp(node a,node b){
if(a.y==b.y)return a.x<b.x;
return a.y<b.y;
}
vector<ll>ans;
ll h[N];
int main(){
ll i, j;
while(~scanf("%d",&n)){
for(i=1;i<=n;i++){
cin>>a[i].x>>a[i].y;
if(a[i].x>a[i].y)swap(a[i].x,a[i].y);
}
memset(h, 0, sizeof h);
sort(a+1,a+n+1,cmp);
ans.clear();
for(i = 1; i <=n;i++)if(!h[i]){
ans.push_back(a[i].y);
for(j=i;j<=n;j++)
{
if(a[j].x<=a[i].y && a[i].y<=a[j].y)
h[j] = 1;
}
}
cout<<ans.size()<<endl;
for(i=0;i<ans.size();i++)
printf("%d%c",ans[i],i==((ll)ans.size()-1)?'\n':' ');
}
return 0;
}
/*
3
40 -83
52 -80
-21 -4 */
/*
struct node{
ll l, r, id;
ll maxx,val,lmaxx;
}tree[N];
void push_down(ll id){
if(tree[id].l==tree[id].r)return ;
if(tree[id].val){
tree[L(id)].val += tree[id].val;
tree[R(id)].val += tree[id].val;
tree[L(id)].lmaxx += tree[id].val;
tree[L(id)].maxx += tree[id].val;
tree[R(id)].lmaxx += tree[id].val;
tree[R(id)].maxx += tree[id].val;
tree[id].val = 0;
}
}
void build(ll l, ll r, ll id){
tree[id].l = l, tree[id].r = r;
tree[id].maxx = tree[id].val = 0;
tree[id].lmaxx = 0;
if(l==r)return ;
ll mid = Mid(l,r);
build(l,mid,L(id)); build(mid+1,r,R(id));
}
void updata(ll l, ll r, ll val, ll id){
push_down(id);
if(l == tree[id].l && tree[id].r == r){
tree[id].val += val;
tree[id].maxx += val;
tree[id].lmaxx += val; return;
}
ll mid = Mid(tree[id].l, tree[id].r);
if(mid<l)updata(l,r,val,R(id));
else if(r<=mid)
updata(l,r,val,L(id));
else {
updata(l,mid,val,L(id));
updata(mid+1,r,val,R(id));
}
tree[id].maxx = max(tree[L(id)].maxx, tree[R(id)].maxx);
tree[id].lmaxx = tree[L(id)].lmaxx;
}
struct hehe{
ll val, x;
hehe(ll a=0,ll b=0):val(a),x(b){}
bool operator<(const hehe&a)const{
if(a.val==val)return a.x<x;
return a.val>val;
}
};
hehe query(ll l, ll r, ll id){
push_down(id);
if(l == tree[id].l && tree[id].r == r && tree[id].lmaxx==tree[id].maxx)
return hehe(tree[id].maxx, tree[id].l);
ll mid = Mid(tree[id].l, tree[id].r);
if(mid<l)return query(l,r,R(id));
else if(r<=mid)return query(l,r,L(id));
else return max(query(l,mid,L(id)),query(mid+1,r,R(id)));
}
set<ll>myset;
set<ll>::iterator p;
map<ll,ll>mp;
ll pos[N];
vector<ll>ans;
int use[N];
int main(){
ll i, j, u, v;
while(cin>>n){
myset.clear();
mp.clear();
ans.clear();
for(i=1;i<=n;i++){
cin>>x[i]>>y[i];
if(x[i]>y[i])swap(x[i],y[i]);
myset.insert(x[i]);
myset.insert(y[i]);
use[i] = true;
}
ll siz = 1;
for(p=myset.begin(); p!=myset.end(); p++, siz++) {
pos[siz] = *p;
mp.insert(pair<ll,ll>(*p,siz));
}
for(i=1;i<=n;i++) {
x[i] = mp.find(x[i])->second;
y[i] = mp.find(y[i])->second;
}
build(1,siz-1,1);
for(i=1;i<=n;i++)
updata(x[i],y[i],1,1);
while(tree[1].maxx){
hehe now = query(1,siz-1,1);
ans.push_back(pos[now.x]);
for(i=1;i<=n;i++)
if(x[i]<=now.x&&now.x<=y[i] && use[i])
updata(x[i],y[i],-1,1), use[i] = false;
}
cout<<ans.size()<<endl;
for(i=0;i<ans.size();i++)
printf("%d%c",ans[i],i==((ll)ans.size()-1)?'\n':' ');
}
return 0;
}
/**/

版权声明:本文博客原创文章,博客,未经同意,不得转载。

CodeForces 22D Segments 排序水问题的更多相关文章

  1. CodeForces.158A Next Round (水模拟)

    CodeForces.158A Next Round (水模拟) 题意分析 校赛水题的英文版,坑点就是要求为正数. 代码总览 #include <iostream> #include &l ...

  2. Codeforces Gym 100531G Grave 水题

    Problem G. Grave 题目连接: http://codeforces.com/gym/100531/attachments Description Gerard develops a Ha ...

  3. Division and Union CodeForces - 1101C (排序后处理)

    There are nn segments [li,ri][li,ri] for 1≤i≤n1≤i≤n. You should divide all segments into two non-emp ...

  4. PAT甲题题解-1012. The Best Rank (25)-排序水题

    排序,水题因为最后如果一个学生最好的排名有一样的,输出的课程有个优先级A>C>M>E那么按这个优先级顺序进行排序每次排序前先求当前课程的排名然后再与目前最好的排名比较.更新 至于查询 ...

  5. PAT甲题题解-1062. Talent and Virtue (25)-排序水题

    水题,分组排序即可. #include <iostream> #include <cstdio> #include <algorithm> #include < ...

  6. hdu1106 排序水题

    Problem Description 输入一行数字,如果我们把这行数字中的‘5’都看成空格,那么就得到一行用空格分割的若干非负整数(可能有些整数以‘0’开头,这些头部的‘0’应该被忽略掉,除非这个整 ...

  7. CodeForces 705A(训练水题)

    题目链接:http://codeforces.com/problemset/problem/705/A 从第三个输出中可看出规律, I hate that I love that I hate it ...

  8. CodeForces Gym 100685C Cinderella (水题)

    题意:给定 n 个杯子,里面有不同体积的水,然后问你要把所有的杯子的水的体积都一样,至少要倒少多少个杯子. 析:既然最后都一样,那么先求平均数然后再数一下,哪个杯子的开始的体积就大于平均数,这是一定要 ...

  9. CodeForces 534B Covered Path (水题)

    题意:给定两个速度,一个一初速度,一个末速度,然后给定 t 秒时间,还每秒速度最多变化多少,让你求最长距离. 析:其实这个题很水的,看一遍就知道怎么做了,很明显就是先从末速度开始算起,然后倒着推. 代 ...

随机推荐

  1. DataTable数据转换为实体

    我们在用三层架构编写软件时,常常会遇到例如以下问题,就是三层之间的參数传递问题:假设我们在D层查询出数据是DataTable类型的,那么我们在B层甚至U层使用这条数据时,就要用DataTable类型来 ...

  2. python socket编程实现的简单tcp迭代server

    与c/c++ socket编程对照见http://blog.csdn.net/aspnet_lyc/article/details/38946915 server: import socket POR ...

  3. hdu1042(大数模板)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1042 在网上找了个大数模板方便以后用得到. #include<iostream> #inc ...

  4. Windows下安装MySQLdb, Python操作MySQL数据库的增删改查

    这里的前提是windows上已经安装了MySQL数据库,且配置完成,能正常建表能操作. 在此基础上仅仅需安装MySQL-python-1.2.4b4.win32-py2.7.exe就ok了.仅仅有1M ...

  5. Android它SDK Manager无法更新终极解决方案

    前些日子.Google终于发布Android5.0正式版--棒糖.也许你和我一样,,此外,我想在第一时间更新SDK,结果打开SDK Manager,但令人失望,络围墙啊.默默问一句:近期好久没有听到方 ...

  6. iText操作word文档总结

    操作word文档的工具有很多,除了iText之外还有POI,但是POI擅长的功能是操作excel,虽然也可以操作word,但是能力有限,而且还有很多的bug,技术并不成熟,下面就重点介绍一种操作wor ...

  7. 伪教练技术培训之殇-2013年9月江西IDC拓行榜与综述

    纠集几个人,然后培训所谓的教练技术培训. 培训的人一期又一期的参与,国学.佛学.超能量,无所不用其极,然后就是疯狂的拿人头,邀请朋友加盟. 有甚者还披上“科技”的外衣,用“水知道答案”这种早被公知指出 ...

  8. pygame系列_游戏窗口显示策略

    在这篇blog中,我将给出一个demo演示: 当我们按下键盘的‘f’键的时候,演示的窗口会切换到全屏显示和默认显示两种显示模式 并且在后台我们可以看到相关的信息输出: 上面给出了一个简单的例子,当然在 ...

  9. (hdu step 7.1.3)Lifting the Stone(求凸多边形的重心)

    题目: Lifting the Stone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...

  10. 垂死或涅槃重生 -- Delphi XE5 我们将宣布感情的回归

    Delphi 在很大程度上是一个被遗忘我的工具. 无论是在使用RapidSql , 我还没有收到Embarcadero 本公司发行参与邀请Delphi XE5该公告将. 可能有人会问,为什么Embar ...