标签: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