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 ...
随机推荐
- python爬虫 ----文章爬虫(合理处理字符串中的\n\t\r........)
import urllib.request import re import time num=input("输入日期(20150101000):") def openpage(u ...
- python base64加密文本内容(2)
上面一篇简单进行了base64加密 但安全系数非常低,只需要用网上的在线base64解码就能破解 这里我们可以自己修改一下base64加密后的字符串,在解码的时候只需要先提前将修改的内容还原就可以了 ...
- html5-css渐变应用小实例,按钮
.but1{ padding: 10px 20px; font-size: 16px; text-shadow: 2px 2px 3px rgba(0,0,0,0.8); bo ...
- Real Time Credit Card Fraud Detection with Apache Spark and Event Streaming
https://mapr.com/blog/real-time-credit-card-fraud-detection-apache-spark-and-event-streaming/ Editor ...
- tetrahedron (公式)
我是直接搬运了某大佬的代码,毕竟我不清楚如何计算这个东西. 其中四点共面的求法就是体积为0,然后圆心和半径就公式了. #include<cstdio> #include<iostre ...
- bash shell 编程练习
原始文件: find /etc -name passwd 2>&1 | tee ee.log 1. cat -n 把 e.log 的文档内容加上行号后输入 e2.log 这个文档里: x ...
- HOG基本原理
图像识别,图像预处理,HOG算法介绍. 转自: https://blog.csdn.net/gy429476195/article/details/50156813
- android dumpsys
dumpsys dumpsys is a tool that runs on Android devices and provides information about system service ...
- 常用正则表达式爬取网页信息及HTML分析总结
Python爬取网页信息时,经常使用的正则表达式及方法. 1.获取<tr></tr>标签之间内容 2.获取<a href..></a>超链接之间内容 3 ...
- 怎样从外网访问内网Apache HTTP Server
本地安装了一个Apache HTTP Server,只能在局域网内访问,怎样从外网也能访问到本地的Apache HTTP Server呢?本文将介绍具体的实现步骤. 1. 准备工作 1.1 安装并启动 ...