码迷,mamicode.com
首页 > 其他好文 > 详细

Codeforces 430A Points and Segments (easy)

时间:2014-05-15 02:53:54      阅读:205      评论:0      收藏:0      [点我收藏+]

标签:style   blog   class   code   c   int   

题意:让你染色点,要求在给出的区间内|红色个数-蓝色个数|<=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 main(){
	scanf("%d%d", &n, &m);
	vector<pair<int, int> > v;
	for (int i = 0; i < n; i++){
		scanf("%d", &x);
		v.push_back(make_pair(x, i));
	}
	sort(v.begin(), v.end());
	for (int i = 0; i < m; i++)
		scanf("%d%d", &x, &y);
	for (int i = 0; i < n; i++){
		if (i % 2 == 0)
			arr[v[i].second] = 0;
		else arr[v[i].second] = 1;
	}
	for (int i = 0; i < n; i++){
		if (i > 0)
			printf(" ");
		printf("%d", arr[i]);
	}
	printf("\n");
	return 0;
}



Codeforces 430A Points and Segments (easy),布布扣,bubuko.com

Codeforces 430A Points and Segments (easy)

标签:style   blog   class   code   c   int   

原文地址:http://blog.csdn.net/u011345136/article/details/25800453

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!