CodeForces 430A Points and Segments (easy)(构造)题解
题意:之前愣是没看懂题意...就是给你n个点的坐标xi,然后还规定了Li,Ri,要求给每个点染色,每一组L,R内的点红色和黑色的个数不能相差大于1个,问你能不能染成功,不能输出-1,能就按照输入的顺序输出颜色
思路:我会说我根本没想到怎么做吗?显然只要交替染色相差就不会大于1
代码:
#include<set>
#include<map>
#include<stack>
#include<cmath>
#include<queue>
#include<vector>
#include<string>
#include<cstdio>
#include<cstring>
#include<sstream>
#include<iostream>
#include<algorithm>
typedef long long ll;
using namespace std;
const int maxn = + ;
const int MOD = 1e9 + ;
const int INF = 0x3f3f3f3f;
struct node{
int id, col, i;
bool operator < (const node x) const{
return id < x.id;
}
}a[maxn];
bool cmp(node x, node y){
return x.i < y.i;
}
int main(){
int n, m, c;
scanf("%d%d", &n, &m);
for(int i = ; i <= n; i++) scanf("%d", &a[i].id), a[i].i = i;
for(int i = ; i <= m; i++) scanf("%d%d", &c, &c);
sort(a + , a + n + );
for(int i = ; i <= n; i++) a[i].col = i & ;
sort(a + , a + n + , cmp);
for(int i = ; i <= n; i++){
if(i != ) printf(" ");
printf("%d", a[i].col);
}
printf("\n");
return ;
}
CodeForces 430A Points and Segments (easy)(构造)题解的更多相关文章
- codeforces 430A Points and Segments (easy)(理解能力有待提高……)
题目 //终于看懂题目了,,,, //一条线段里面不是每个坐标上都有要染色的点,所以为了满足条件,只能考虑那些给出坐标的点 //所以就要排序一下了,不能直接根据坐标0 1 0 1…… #include ...
- 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 #245 (Div. 2) A - Points and Segments (easy)
水到家了 #include <iostream> #include <vector> #include <algorithm> using namespace st ...
- codeforces 430 A Points and Segments (easy)
题意:给出n个点,m个区间,需要给这些点涂上蓝色或者红色,使得每个区间里面的点的红色的点的个数与蓝色的点的个数的差值小于1 唉,题目的标题就标注了一个easy= = 最开始做的时候对点还有区间都排序了 ...
- Codeforces 429E - Points and Segments(欧拉回路)
Codeforces 题面传送门 & 洛谷题面传送门 果然我不具备融会贯通的能力/ll 看到这样的设问我们可以很自然地联想到这道题,具体来说我们可以通过某种方式建出一张图,然后根据" ...
- Codeforces 429E Points and Segments
Description 题面 题目大意:有 \(n\) 个区间 \([L_i,R_i]\) ,你要给每一个区间染红蓝,使得每一个位置被红色染过的次数与被蓝色染过的次数差的绝对值不大于\(1\) Sol ...
- Codeforces 576C. Points on Plane(构造)
将点先按x轴排序,把矩形竖着划分成$10^3$个块,每个块内点按y轴排序,然后蛇形走位上去. 这样一个点到下一个点的横坐标最多跨越$10^3$,一共$10^6$个点,总共$10^9$,一个块内最多走$ ...
- 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 ...
随机推荐
- java outterLoop跳出多重循环用法以及详解
List<CommResultMsg> listresult=new ArrayList<CommResultMsg>(); outterLoop :for (int i = ...
- Hello py
https://www.cnblogs.com/AdaminXie/p/8339863.html https://www.cnblogs.com/-clq/p/8340515.html https:/ ...
- X.509证书及CeritificationPath及PKCS
X.509,数字证书标准.X.509用在包含SSL/TLS在内的很多网络协议中,证书内部包含一个public key和一个identity(hostname,organization等). X.509 ...
- Keras 处理 不平衡的数据的分类问题 imbalance data 或者 highly skewed data
处理不平衡的数据集的时候,可以使用对数据加权来提高数量较小类的被选中的概率,具体方式如下 fit(self, x, y, batch_size=32, nb_epoch=10, verbose=1, ...
- XMLHttpRequest对象(Ajax)的状态码(readystate) HTTP状态代码(status)
2018-11-28 14:19:00 来自 :XMLHttpRequest对象(Ajax)的状态码(readystate) HTTP状态代码(status) XMLHttpRequest对象(Aj ...
- Django admin模块无法调用css样式文件
在使用Django Admin开发时,发现admin模块css样式文件丢失,无法调用,使火狐浏览器提示: 此 URL 的资源不是文本: http://127.0.0.1:8000/statics/ad ...
- 配置tomcat的https域名
配置tomcat的https域名: <Connector port=" protocol="org.apache.coyote.http11.Http11NioProtoco ...
- ssh 免登录
1. 生成 ssh 公钥和私钥 xiluhua@vm-xiluhua ~ $ ssh-keygen Generating public/private rsa key pair. Enter file ...
- Linux基础命令---显示树形进程pstree
pstree pstree显示正在运行的进程的树形结构,树以PID为根:如果省略了pid则以init为根.如果指定了用户名,则显示根植于该用户拥有的进程的所有进程树.如果pstree被调用为pstre ...
- 单台主机上DB2 10.5和arcgis 10.4 空间数据库配置
该篇文章重点参考arcgis官网说明:http://enterprise.arcgis.com/zh-cn/server/10.4/publish-services/linux/register-db ...