codeforces 430 A Points and Segments (easy)

题意:给出n个点,m个区间,需要给这些点涂上蓝色或者红色,使得每个区间里面的点的红色的点的个数与蓝色的点的个数的差值小于1

唉,题目的标题就标注了一个easy= = 最开始做的时候对点还有区间都排序了,模拟来做,可是错了

后来发现不管区间怎么样,只要红色和蓝色交替涂色,

就一定能满足“使得每个区间里面的点的红色的点的个数与蓝色的点的个数的差值小于1 ”这个条件

有点像上次做的cf交替输出奇数偶数那个A题

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include <cmath>
 5 #include<stack>
 6 #include<vector>
 7 #include<map>
 8 #include<set>
 9 #include<queue>
10 #include<algorithm>
11 using namespace std;
12
13 typedef long long LL;
14 const int INF = (1<<30)-1;
15 const int mod=1000000007;
16 const int maxn=1005;
17
18 struct node{
19     int x,y,z;
20 } a[maxn];
21
22 int cmp(node n1,node n2){
23     if(n1.x!=n2.x) return n1.x<n2.x;
24     return n1.y<n2.y;
25 }
26
27 int main(){
28     int n,m;
29     scanf("%d %d",&n,&m);
30     for(int i=1;i<=n;i++){
31         scanf("%d",&a[i].x);
32         a[i].y=i;
33         a[i].z=0;
34     }
35
36     sort(a+1,a+n+1,cmp);
37
38     while(m--){
39         int u,v;
40         cin>>u>>v;
41     }
42
43     for(int i=1;i<=n;i++){
44         if(i%2) a[a[i].y].z=1;
45         else a[a[i].y].z=0;
46     }
47
48     for(int i=1;i<=n;i++)
49     printf("%d ",a[i].z);
50     return 0;
51 }

时间: 2024-08-07 00:07:17

codeforces 430 A Points and Segments (easy)的相关文章

Codeforces Round #245 (Div. 2) A - Points and Segments (easy)

水到家了 #include <iostream> #include <vector> #include <algorithm> using namespace std; struct Point{ int index, pos; Point(int index_ = 0, int pos_ = 0){ index = index_; pos = pos_; } bool operator < (const Point& a) const{ return p

Codeforces 430A Points and Segments (easy)

题意:让你染色点,要求在给出的区间内|红色个数-蓝色个数|<=1 思路:排序后依次交替染色就能达到效果 #include <iostream> #include <cstring> #include <algorithm> #include <cstdio> #include <vector> using namespace std; const int MAXN = 110; int arr[MAXN]; int n,m,x,y; int

codeforces 430A Points and Segments (easy)(理解能力有待提高……)

题目 //终于看懂题目了,,,, //一条线段里面不是每个坐标上都有要染色的点,所以为了满足条件,只能考虑那些给出坐标的点 //所以就要排序一下了,不能直接根据坐标0 1 0 1…… #include <cstdio> #include <cstring> #include <algorithm> using namespace std ; struct tt { int a,b; }aa[110]; int cmp(tt x,tt y) { return x.a<

Codeforces 347B - Fixed Points

题意:给定一个序列,现有一种操作:两个数的位置互换.问最多操作一次,序列 [元素位置i]  与 [元素Ai] 相等的最多个数? 根据题意,最多个数为 : [操作之前[元素位置i]  与 [元素Ai] 相等的个数] +  [调换两个 [元素位置i]  与 [元素Ai] 不相等 的元素 使某个 [元素位置i]  与 [元素Ai] 相等的个数]. 举个例子: 0 1 2 4 3 这个序列,调换后面两个元素,正好使每个 [元素位置i]  与 [元素Ai] 相等. 也就是说,调换的时候,不用考虑 [元素位

lightoj-1088 - Points in Segments(二分法)

1088 - Points in Segments PDF (English) Statistics ForumTime Limit: 2 second(s) Memory Limit: 32 MBGiven n points (1 dimensional) and q segments, you have to find the number of points that lie in each of the segments. A point pi will lie in a segment

LightOJ 1088 Points in Segments 二分查找

1088 - Points in Segments PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB Given n points (1 dimensional) and q segments, you have to find the number of points that lie in each of the segments. A point pi will lie in a segme

【CF429E】Points and Segments 欧拉回路

[CF429E]Points and Segments 题意:给你数轴上的n条线段$[l_i,r_i]$,你要给每条线段确定一个权值+1/-1,使得:对于数轴上的任一个点,所有包含它的线段的权值和只能是+1,-1或0. $n\le 10^5$ 题解:首先,我们用扫描线,整个数轴被分成若干个小区间.对于一个小区间,如果有偶数条线段包含它,则它的权值只能是0,否则可以是+1/-1.我们可以在所有权值为+1/-1的小区间处人为的增加一条线段,这样的话我们只需要让所有小区间权值都是0就行了. 嗯...每

CodeForces A. Points in Segments

http://codeforces.com/contest/1015/problem/A You are given a set of nn segments on the axis OxOx, each segment has integer endpoints between 11 and mm inclusive. Segments may intersect, overlap or even coincide with each other. Each segment is charac

Codeforces Round #501 (Div. 3) A Points in Segments

翻译 现在有一个数轴,上面会有\(M\)个点,标号为\(1\)到\(N\),现在给你在数轴上的条\(N\)线段的起始与终止的点,问哪几个点没有被这样线段覆盖,从小到大输出. 思路 签到题目.感觉几乎和一道题一样:校门外的树,撞题是很尴尬.思路差不多,即为开一个数组,全部赋值为\(0\),输入的线段的时候,将其起点与终点的全部的点赋值为\(1\),最后跑一下看看那些为\(0\)的点就完事了. Code #include<iostream> using namespace std; int boo