主题链接:点击打开链接

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

删边暴力

#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. Hive Metastore ObjectStore PersistenceManager自动关闭bug解析

    最近在测试HCatalog,由于Hcatalog本身就是一个独立JAR包,虽然它也可以运行service,但是其实这个service就是metastore thrift server,我们在写基于Hc ...

  2. hdu5179(数位dp)

    传送门:beautiful number 题意:令 A=∑ni=1ai?10n?i(1≤ai≤9)(n为A的位数).若A为“漂亮的数”当且仅当对于任意1≤i<n满足a[i]≥a[i+1]且对于任 ...

  3. 【剑指offer】约瑟夫环问题

    转载请注明出处:http://blog.csdn.net/ns_code/article/details/27957407 题目描写叙述: 每年六一儿童节,JOBDU都会准备一些小礼物去看望孤儿院的小 ...

  4. JDBC数据库连接

    JDBC是什么? Java Data Base Connectivity JDBC是: 以统一方式訪问数据库的API,能够訪问不论什么类型表列数据.特别是存储在关系数据中的数据.JDBC代表Java数 ...

  5. linux LNMP自动安装脚本

    #!/bin/bashsoft_dir="/home/soft"config_dir="/home/config"httpd="httpd-2.0.5 ...

  6. jersey client上传下载文件

    jersey client上传文件demo File file = new File("/tmp/test.jpg"); System.out.println(file.exist ...

  7. Coreseek:indexer crashed神秘

    浩哥前两天让我再Coreseek该指数再次这样做,由于需求方面变化不大,公司名称应出现指数.在添加的配置文件的面孔sql_field_string:串场.. 此属性特别有用,因为它不仅作为过滤器的特性 ...

  8. Linux php/php-fpm 安装,配置

    1> 下载php源代码   #wget  http://cn2.php.net/get/php-5.4.30.tar.gz/from/this/mirror   官网5.2的版本号貌似没提供   ...

  9. PHP Html 弹窗,本页面弹窗子页面

    echo '<script type=text/javascript>window.open("","name1","width=100, ...

  10. 黄聪:Microsoft Enterprise Library 5.0 系列教程(二) Cryptography Application Block (高级)

    原文:黄聪:Microsoft Enterprise Library 5.0 系列教程(二) Cryptography Application Block (高级) 本章介绍的是企业库加密应用程序模块 ...