A - Points and Segments CodeForces - 429E
题解:
方法非常巧妙的一道题
首先考虑要求全部为0怎么做
发现是个欧拉回路的问题(很巧妙)
直接dfs一遍就可以了
而这道题
要求是-1,1,0
我们可以先离散化
完了之后判断每个点被奇数还是偶数条边覆盖
如果是奇数,那么就多连一条边
另外有个细节是为了要用欧拉回路区间左开右闭
代码:
#include <bits/stdc++.h>
using namespace std;
const int N=4e5;
const int INF=1e9+;
int n,cnt[N],rd[N],b[N],head[N],l1;
struct re{
int a,b,c,w;
}a[N],e[N*];
bool cmp(re x,re y)
{
return(x.a<y.a);
}
void arr(int x,int y)
{
e[++l1].a=head[x];
e[l1].b=y;
head[x]=l1;
e[l1].c=;
rd[x]++;
}
void dfs(int x)
{
int u=head[x];
while (u)
{
int v=e[u].b;
if (e[u].c)
{
e[u].c=; e[((u-)^)+].c=;
if (x<v) e[u].w=; else e[u].w=;
e[((u-)^)+].w=e[u].w;
dfs(v);
}
u=e[u].a;
}
}
int main()
{
freopen("1.in","r",stdin);
freopen("1.out","w",stdout);
ios::sync_with_stdio(false);
cin>>n;
for (int i=;i<=n;i++)
{
int li,ri;
cin>>li>>ri;
a[i*-].a=li; a[i*].a=ri;
a[i*-].b=i*-; a[i*].b=i*;
}
sort(a+,a+n*+,cmp);
a[].a=-INF; int l=;
for (int i=;i<=n*;i++)
{
if (a[i].a!=a[i-].a)
if (a[i].a==a[i-].a+) l++;
else l+=;
b[a[i].b]=l;
}
for (int i=;i<=n;i++)
cnt[b[i*-]]++,cnt[b[i*]+]--;
int ans=;
for (int i=;i<=l;i++)
{
ans+=cnt[i];
if (ans%) arr(i,i+),arr(i+,i);
}
int l2=l1+;
for (int i=;i<=n;i++)
arr(b[i*-],b[i*]+),arr(b[i*]+,b[i*-]);
for (int i=;i<=l;i++)
if (rd[i]%)
{
cout<<"-1";
exit();
}
for (int i=;i<=l+;i++)
{
dfs(i);
}
while (l2<=l1)
{
cout<<e[l2].w<<" ";
l2+=;
}
return ;
}
A - Points and Segments CodeForces - 429E的更多相关文章
- Codeforces Round #245 (Div. 2) A. Points and Segments (easy) 贪心
A. Points and Segments (easy) Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/con ...
- 『ACM C++』 Codeforces | 1066A - Points in Segments
大一生活真 特么 ”丰富多彩“ ,多彩到我要忙到哭泣,身为班长,很多班级的事情需要管理,也是,什么东西都得体验学一学,从学生会主席.团委团总支.社团社长都体验过一番了,现在差个班长也没试过,就来体验了 ...
- Codeforces Round #501 (Div. 3) 1015A Points in Segments (前缀和)
A. Points in Segments time limit per test 1 second memory limit per test 256 megabytes input standar ...
- 【CF429E】Points and Segments(欧拉回路)
[CF429E]Points and Segments(欧拉回路) 题面 CF 洛谷 题解 欧拉回路有这样一个性质,如果把所有点在平面内排成一行,路径看成区间的覆盖,那么每个点被从左往右的覆盖次数等于 ...
- 【CF429E】Points and Segments 欧拉回路
[CF429E]Points and Segments 题意:给你数轴上的n条线段$[l_i,r_i]$,你要给每条线段确定一个权值+1/-1,使得:对于数轴上的任一个点,所有包含它的线段的权值和只能 ...
- D - Nested Segments CodeForces - 652D (离散化+树桩数组)
D - Nested Segments CodeForces - 652D You are given n segments on a line. There are no ends of some ...
- CF429E Points and Segments
链接 CF429E Points and Segments 给定\(n\)条线段,然后给这些线段红蓝染色,求最后直线上上任意一个点被蓝色及红色线段覆盖次数之差的绝对值不大于\(1\),构造方案,\(n ...
- Codeforces 429E - Points and Segments(欧拉回路)
Codeforces 题面传送门 & 洛谷题面传送门 果然我不具备融会贯通的能力/ll 看到这样的设问我们可以很自然地联想到这道题,具体来说我们可以通过某种方式建出一张图,然后根据" ...
- Codeforces 429E Points and Segments
Description 题面 题目大意:有 \(n\) 个区间 \([L_i,R_i]\) ,你要给每一个区间染红蓝,使得每一个位置被红色染过的次数与被蓝色染过的次数差的绝对值不大于\(1\) Sol ...
随机推荐
- Hibernate search使用示例(基础小结-注解方式)
(对于项目环境配置,一直没怎么看过.这次经历里从基础环境搭建到hibernate search示例的完成) 1.首先创建project,选择了web project. 2.导入hibernate se ...
- 缓存系列之二:CDN与其他层面缓存
缓存系列之二:CDN与其他层面缓存 一:内容分发网络(Content Delivery Network),通过将服务内容分发至全网加速节点,利用全球调度系统使用户能够就近获取,有效降低访问延迟,提升服 ...
- Keil和SourceInsight中文乱码解决方法
一.KEIL乱码 到菜单栏Edit--->Configuration-->Encoding ---ChineseSimplied 二.SourceInsight乱码 错误现象:注释乱码,查 ...
- cdh5.15集群添加spark2.3服务(parcels安装)
背景: 机器系统:redhat7.3:已经配置了http服务 集群在安装的时候没有启动spark服务,因为cdh5.15自带的spark不是2.0,所以直接进行spark2.3的安装 参考文档:htt ...
- Confluence 6 配置快捷链接
快捷链接提供了提供了一个在 Confluence 中访问从常用资源的快速方法.当你创建一个快捷链接的时候,你需要为你的快捷链接 URL 指派一个 Key,用户可以在 Confluence 中只输入这个 ...
- kernel_size
kernel_size=(1,3)[flag] if flag==True:kernel_size=3 else: kernel_size=1
- Mysql哪些字段适合建立索引
数据库建立索引常用的规则如下: 1.表的主键.外键必须有索引: 2.数据量超过300的表应该有索引: 3.经常与其他表进行连接的表,在连接字段上应该建立索引: 4.经常出现在Where子句中的字段,特 ...
- SpringBoot捕获全局异常
1.创建GloableExceptionAop类捕获全局异常 package com.cppdy.exception; import org.springframework.web.bind.anno ...
- Python的图像库
对数字图像基本的处理的学习按照下面两个博客: Python的图像库(Opencv.PIL.matplotlib.skimage)的使用(读取.存储.变换.滤波) python数字图像处理
- java和python对比----实例化的对象属性:
python 可以直接对实例化的属性进行赋值 class Test(): name = "小明" def __init__(self):{ //self.name = name; ...