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 ...
随机推荐
- u3d人物控制
//https://blog.csdn.net/Htlas/article/details/79188008 //人物移动 http://gad.qq.com/article/detail/28921 ...
- Oracle服务器定位CPU使用率高的瓶颈(SQL)
1.首先用TOP命令监控系统资源,如果是AIX系统,就用topas,进入TOP命令的滚动刷新数据时,发现userCPU高达98%!! 保持top的状态下,按shift+p,可以将所有进程按CPU使用率 ...
- 【原创】大叔经验分享(30)CM开启kerberos
kerberos安装详见:https://www.cnblogs.com/barneywill/p/10394164.html 一 为CM创建用户 # kadmin.local -q "ad ...
- nodejs,javascript过滤emoj表情
1 前言 由于带emoj表情的昵称无法存储在mysql character_set_server= utf8模式下,按照参考文章[1],改成utf8mb4,无效(可能使用方法不对). 总体思路是,把昵 ...
- [C]二级指针
二级指针即“指向指针的指针”: 下面的实例代码创建了一个二级指针c int a = 5; int* b = &a; int** c = &b; 你不能这样 int a = 5; int ...
- swift 实践- 09 -- UIImageVIew
import UIKit class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoa ...
- JAVA 语言如何进行异常处理,关键字: throws,throw,try,catch,finally分别代表什么意义? 在try块中可以抛 出异常吗?
Java通过面向对象的方法进行异常处理,把各种不同的异常进行分类, 并提供了良好的接口. 在 Java中,每个异常都是一个对象,它是 Throwable 类或其它子类的实例.当一个方法出 ...
- automaticallyAdjustsScrollViewInsets 详解
automaticallyAdjustsScrollViewInsets 自动缩进 20 像素 默认是 True 项目中如果有UIViewController 和ScrollView 一般都要设置成f ...
- PhpStorm 2018 安装及破解方法
参考教程: https://blog.csdn.net/u012278016/article/details/81772566
- Deal with Warning: mysqli::__construct(): (HY000/2002)
1.安装XAMPP之后,如果之前安装过MySQL或者 apache,启动XAMPP中的响应的服务的时候回出现报错, 出错的原因,具体看报错的原因,如果是端口占用,在配置中修改端口号,如果是提示 “Fo ...