CodeForces 430A Points and Segments
2014-08-10 19:52
162 查看
Description
Iahub isn't well prepared on geometry problems, but he heard that this year there will be a lot of geometry problems on the IOI selection camp. Scared, Iahub locked himself in the basement and started thinking of new problems of this kind. One of them is
the following.
Iahub wants to draw n distinct points andm segments on the
OX axis. He can draw each point with either red or blue. The drawing is good if and only if the following requirement is met: for each segment[li, ri]
consider all the red points belong to it (ri points), and all the blue points belong to it (bi points);
each segmenti should satisfy the inequality
|ri - bi| ≤ 1.
Iahub thinks that point x belongs to segment[l, r], if inequality
l ≤ x ≤ r holds.
Iahub gives to you all coordinates of points and segments. Please, help him to find any good drawing.
Input
The first line of input contains two integers: n (1 ≤ n ≤ 100) andm (1 ≤ m ≤ 100). The next line containsn
space-separated integers x1, x2, ..., xn (0 ≤ xi ≤ 100)
— the coordinates of the points. The following m lines contain the descriptions of them segments. Each line contains two integersli
andri (0 ≤ li ≤ ri ≤ 100) — the borders of thei-th
segment.
It's guaranteed that all the points are distinct.
Output
If there is no good drawing for a given test, output a single integer -1. Otherwise outputn integers, each integer must be 0 or 1. Thei-th number denotes the color of the
i-th point (0 is red, and 1 is blue).
If there are multiple good drawings you can output any of them.
Sample Input
Input
Output
Input
Output
题目大意:在数轴上给定n个点,m条线段,对于所有线段i,若点j满足li<=j<=ri,则说:点j在线段i上。要求将所给的点红蓝染色,使得对于任意一条线段,在这条线段上的红色点数ri,蓝色点数bi,满足|ri-bi|<=1。
解析:无论线段如何,只要点按照“0101010……”这种方法,从左到右画即可。最后要按照输入时的顺序输出,线段什么的不用考虑。
Iahub isn't well prepared on geometry problems, but he heard that this year there will be a lot of geometry problems on the IOI selection camp. Scared, Iahub locked himself in the basement and started thinking of new problems of this kind. One of them is
the following.
Iahub wants to draw n distinct points andm segments on the
OX axis. He can draw each point with either red or blue. The drawing is good if and only if the following requirement is met: for each segment[li, ri]
consider all the red points belong to it (ri points), and all the blue points belong to it (bi points);
each segmenti should satisfy the inequality
|ri - bi| ≤ 1.
Iahub thinks that point x belongs to segment[l, r], if inequality
l ≤ x ≤ r holds.
Iahub gives to you all coordinates of points and segments. Please, help him to find any good drawing.
Input
The first line of input contains two integers: n (1 ≤ n ≤ 100) andm (1 ≤ m ≤ 100). The next line containsn
space-separated integers x1, x2, ..., xn (0 ≤ xi ≤ 100)
— the coordinates of the points. The following m lines contain the descriptions of them segments. Each line contains two integersli
andri (0 ≤ li ≤ ri ≤ 100) — the borders of thei-th
segment.
It's guaranteed that all the points are distinct.
Output
If there is no good drawing for a given test, output a single integer -1. Otherwise outputn integers, each integer must be 0 or 1. Thei-th number denotes the color of the
i-th point (0 is red, and 1 is blue).
If there are multiple good drawings you can output any of them.
Sample Input
Input
3 3 3 7 14 1 5 6 10 11 15
Output
0 0 0
Input
3 4 1 2 3 1 2 2 3 5 6 2 2
Output
1 0 1
题目大意:在数轴上给定n个点,m条线段,对于所有线段i,若点j满足li<=j<=ri,则说:点j在线段i上。要求将所给的点红蓝染色,使得对于任意一条线段,在这条线段上的红色点数ri,蓝色点数bi,满足|ri-bi|<=1。
解析:无论线段如何,只要点按照“0101010……”这种方法,从左到右画即可。最后要按照输入时的顺序输出,线段什么的不用考虑。
#include <stdio.h> #include <string.h> #include <algorithm> using namespace std; const int N = 110; struct POINT{ int x; int id; int v; }point ; bool cmp1(POINT a,POINT b) { return a.x < b.x; } bool cmp2(POINT a,POINT b) { return a.id < b.id; } int main() { int n,m; while( scanf("%d%d",&n,&m) != EOF) { for(int i = 0; i < n; i++) { scanf("%d",&point[i].x); point[i].id = i; } int a,b; for(int i = 0; i < m; i++) { scanf("%d%d",&a,&b); } sort(point,point+n,cmp1); for(int i = 0; i < n; i++) { point[i].v = i%2; } sort(point,point+n,cmp2); for(int i = 0; i < n; i++) { printf("%d",point[i].v); if(i != n) { printf(" "); } } printf("\n"); } return 0; }
相关文章推荐
- codeforces 482B
- 2016 GDUT Individual Contest2_A题_codeforces 416A(双指针)
- Codeforces 691A Fashion in Berland
- Codeforces 761A-Dasha and Stairs
- codeforces 659A Round House
- CodeForces - 742D Arpa's weak amphitheater and Mehrdad's valuable Hoses (并查集+分组背包)
- codeforces 475D
- CodeForces 620B Grandfather Dovlet’s calculator
- Codeforces 691C Exponential notation
- Codeforces 685E Travelling Through the Snow Queen's Kingdom(DP)
- codeforces 779C Dishonest Sellers
- Codeforces 911D Inversion Counting
- Codeforces 484A - Bits (贪心)
- 【CODEFORCES】 B. Queue
- 【CodeForces】[670D2]Magic Powder - 2
- 【codeforces 764C】Timofey and a tree 题解
- codeforces 813C The Tag Game
- Codeforces 196 B. Infinite Maze(bfs)
- codeforces 484D Kindergarten (dp、贪心)
- codeforces 616E Sum of Remainders (数论,找规律)