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 ...
随机推荐
- ffmpeg 版本升级到 4.0 增加 libaom 库 [AOMedia 的 AV1 视频编码格式]
win10 中交叉编译 libaom 时 注意事项 libaom 源代码 下载 git -c "http.proxy=ip:port" clone https://aomedia. ...
- GPS日常总结
GPS 上电后,每隔一定的时间就会返回一定格式的数据,数据格式为:$信息类型,x,x,x,x,x,x,x,x,x,x,x,x,x每行开头的字符都是'$',接着是信息类型,后面是数据,以逗号分隔开. 1 ...
- Redis的安装、配置及测试
Redis下载地址 https://github.com/MicrosoftArchive/redis/releases(如果需要安装windows服务版本,需要下载msi格式) 或 https:// ...
- python 安装mysql报错
原 安装Python mysqlclient出现“OSError: mysql_config not found”错误 2016年06月01日 12:15:11 wangtaoking1 阅读数:11 ...
- 11)django-ORM(操作增删改查)
ORM从增删改查等方面说明 一:创建数据 #创建数据两种方式1,推荐方式1 UserInfo.objects.create(username=") #方式1变种 user_dict={&qu ...
- 快速理解VirtualBox的四种网络连接方式
VirtualBox中有4中网络连接方式: NAT Bridged Adapter Internal Host-only Adapter VMWare中有三种,其实他跟VMWare 的网络连接方式都是 ...
- Confluence 6 中进行用户管理的优化配置和限制的基本建议
避免跨目录的多个用户名:如果你连接了超过一个的目录服务器,我们建议你需要确定你的用户名在目录服务器中是唯一的.例如:我们不建议你定义一个用户同时在'Directory1' 和 'Directory2' ...
- 【DOS】文件统计命令
1. 统计当前文件夹下文件的个数 ls -l|grep "^-"|wc -l 2. 统计当前文件夹下目录的个数 ls -l|grep "^d"|wc -l 3. ...
- 1709: Fire or Retreat(zzuli)
水题,哎,可是第一次是因为编译错了,vs不知咋了,无奈: 后面几次又因为类型用了int错了,痛苦: 题目描述 在与科技水平远胜于我们的外星人的战斗最后,我们能够用来对外星装甲造成伤害的武器只剩下了…… ...
- 《剑指offer》用两个栈实现队列
本题来自<剑指offer> 用两个栈实现队列 题目: 用两个栈来实现一个队列,完成队列的Push和Pop操作. 队列中的元素为int类型. 思路: 队列定义:先进先出 栈定义:先进后出 要 ...