传送门

文章目录

  • 题意:
  • 思路:

题意:

思路:

考虑对于线段,如何建模。
我们考虑先将线段转换成左闭右开的形式,将左右点连起来。
再考虑每个点,将所有离散化后的点拿出来,每个点都有一个度,现在问题就是给每个边定向,让入度和出度之差≤1\le1≤1即可。
这就是欧拉回路的经典问题了,将奇度点之间连边即可。

// Problem: E. Points and Segments
// Contest: Codeforces - Codeforces Round #245 (Div. 1)
// URL: https://codeforces.com/contest/429/problem/E
// Memory Limit: 256 MB
// Time Limit: 1000 ms
//
// Powered by CP Editor (https://cpeditor.org)//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
//#pragma GCC optimize(2)
#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<map>
#include<cmath>
#include<cctype>
#include<vector>
#include<set>
#include<queue>
#include<algorithm>
#include<sstream>
#include<ctime>
#include<cstdlib>
#include<random>
#include<cassert>
#define X first
#define Y second
#define L (u<<1)
#define R (u<<1|1)
#define pb push_back
#define mk make_pair
#define Mid ((tr[u].l+tr[u].r)>>1)
#define Len(u) (tr[u].r-tr[u].l+1)
#define random(a,b) ((a)+rand()%((b)-(a)+1))
#define db puts("---")
using namespace std;//void rd_cre() { freopen("d://dp//data.txt","w",stdout); srand(time(NULL)); }
//void rd_ac() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//AC.txt","w",stdout); }
//void rd_wa() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//WA.txt","w",stdout); }typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;const int N=2000010,M=N,mod=1e9+7,INF=0x3f3f3f3f;
const double eps=1e-6;int n,m;
vector<int>v;
PII p[N];
int type;
int h[N], e[M], ne[M], idx;
bool used[M];
int ans[M], cnt;
int d[N];void add(int a, int b)
{e[idx] = b, ne[idx] = h[a], h[a] = idx ++ ;
}void dfs(int u)
{for (int &i = h[u]; ~i;){if (used[i]){i = ne[i];continue;}used[i] = true;if (type == 1) used[i ^ 1] = true;int t;if (type == 1){t = i / 2 + 1;if (i & 1) t = -t;}else t = i + 1;int j = e[i];i = ne[i];if(t>0) ans[t]=1;else ans[-t]=0;dfs(j);// if(t>0) ans[t]=1;// else ans[-t]=0;// cout<<t<<endl;}
}int find(int x) {return lower_bound(v.begin(),v.end(),x)-v.begin()+1;
}int main()
{//  ios::sync_with_stdio(false);
//  cin.tie(0);memset(h,-1,sizeof(h));type=1;scanf("%d",&n);for(int i=1;i<=n;i++) {int l,r; scanf("%d%d",&l,&r);p[i]={l,r+1}; v.pb(l); v.pb(r+1);}sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());for(int i=1;i<=n;i++) {p[i].X=find(p[i].X),p[i].Y=find(p[i].Y);add(p[i].X,p[i].Y); add(p[i].Y,p[i].X);d[p[i].X]++; d[p[i].Y]++;// cout<<p[i].X<<' '<<p[i].Y<<endl;}vector<int>now;for(int i=1;i<=v.size();i++) if(d[i]%2==1) now.pb(i);for(int i=0;i<now.size();i+=2) add(now[i],now[i+1]),add(now[i+1],now[i]);for(int i=1;i<=v.size();i++) if(h[i]!=-1) {dfs(i);}for(int i=1;i<=n;i++) printf("%d ",ans[i]);return 0;
}
/**/

Codeforces Round #245 (Div. 1) E. Points and Segments 欧拉回路 + 建模相关推荐

  1. Codeforces Round #585 (Div. 2) F. Radio Stations 2-sat + 神仙建模

    传送门 文章目录 题意: 思路: 题意: 你现在有ppp种电台,有nnn对关系(x,y)(x,y)(x,y)代表xxx电台或yyy电台中至少有一个,mmm对关系(x,y)(x,y)(x,y)代表xxx ...

  2. Codeforces Round #245 (Div. 2): C. Xor-tree(BFS)

    题意: 给你一棵树,每个节点都有一个颜色,不是黑就是白,你每次可以选择一个节点,将这个节点的颜色翻转,同时这个点所有孙子的颜色也会全部被翻转,孙子的孙子颜色也会全部被翻转-- 问至少操作多少次使得所有 ...

  3. Codeforces Round #337 (Div. 2) D. Vika and Segments 线段树扫描线

    D. Vika and Segments 题目连接: http://www.codeforces.com/contest/610/problem/D Description Vika has an i ...

  4. Codeforces Round #305 (Div. 1) D. Mike and Fish 欧拉回路

    传送门 文章目录 题意: 思路: 题意: 思路: 欧拉回路经典题. 将其转换成图上问题,对于横纵坐标我们将其分开,对于(x,y)(x,y)(x,y)我们将其横纵坐标连一个无向边,现在问题就转换成了我们 ...

  5. Codeforces Round #496 (Div. 3 ) E1. Median on Segments (Permutations Edition)(中位数计数)

    E1. Median on Segments (Permutations Edition) time limit per test 3 seconds memory limit per test 25 ...

  6. Codeforces Round #750 (Div. 2)E. Pchelyonok and Segments (数学+DP)

    链接 君子,修身齐家,治国平天下. 题意: Pchelyonok决定给Mila一件礼物.Pchelyonok已经"买"了一个长度为 n 的数组 a,但他觉得送一个数组太普通了.他决 ...

  7. Codeforces Round #770 (Div. 2) E. Fair Share(欧拉回路)

    题目 m(1<=m<=1e5)个数组,第i个数组的长度为ni(2<=ni<=2e5,ni为偶数) 第i个数组内的第j个值aij(1<=aij<=1e9),sumni ...

  8. Codeforces Round #734 (Div. 3) 题解

    Hello大家好,今天给大家带来的是 Codeforces Round #734 (Div. 3) 的全题目讲解. 本文链接:https://www.lanqiao.cn/questions/2040 ...

  9. Codeforces Round #198 (Div. 2)A,B题解

    Codeforces Round #198 (Div. 2) 昨天看到奋斗群的群赛,好奇的去做了一下, 大概花了3个小时Ak,我大概可以退役了吧 那下面来稍微总结一下 A. The Wall Iahu ...

最新文章

  1. php扩展swoole安装,php 安装swoole扩展
  2. 11年架构AI技术江湖,李彦宏:1块钱还是100亿,都会投进技术里
  3. I2C从驱动到应用(中篇)
  4. 数字证书原理简单说明
  5. mysql的timestamp类型_MySQL数据库中的timestamp类型与时区
  6. MyBatis第2天
  7. qthread run结束了算销毁吗_Java线程的run()方法和start()方法有什么区别?
  8. js面试题:创建一个json对象people,并追加属性:姓名、性别、年龄,追加run方法...
  9. nginx 转发慢_Nginx快速入门之Nginx反向代理与负载均衡
  10. matplotlib可视化学习笔记
  11. 【综合实训】图书管理系统——概要设计说明书
  12. python求n的阶乘并输出_python求n的阶乘
  13. 智能算法--------------进化计算总结
  14. 计算机提示无法识别优盘,U盘插入电脑提示无法识别的解决方法
  15. win7修改计算机名 bat,用cmd改计算机名.bat 无需重启电脑生效
  16. 为Exynos4412移植U-Boot-2017.11的步骤(一)——让U-Boot跑起来
  17. 【华为OD机试真题 JAVA】连续出牌数量
  18. RecyclerView 梳理:点击amp;长按事件、分割线、拖曳排序、滑动删除
  19. 保险业内控实施助力灾备服务与业务连续管理
  20. 国际c语言混乱编码大赛,国际C语言混乱代码大赛优胜作品详解之“A clock in one line”...

热门文章

  1. 甘肃2019年9月计算机二级报名入口,2019年9月甘肃计算机二级考试成绩查询入口...
  2. 中国十大最美梯田,个个都美如画!
  3. 那些视觉上骗了你的东西,你上当了吗?
  4. 绝对不能错过!2009~2019 高中数学联赛11年真题解析
  5. 双十一,单身狗除了买买买,还能做什么?
  6. 从生物神经网络到人工神经网络
  7. 超好用的27个谷歌Chrome浏览器使用技巧
  8. python with循环_Python for循环、while循环
  9. 冒泡排序c java c,冒泡排序,c语言冒泡排序法代码
  10. python回复邮件_在Python中通过Outlook回复电子邮件