本文主要是介绍Codeforces Round #182 (Div. 2)A(水题),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
题目链接:http://codeforces.com/contest/302/problem/A
解题思路:
只要通过重新排列使区间内和为0即是1,否则是0.
完整代码:
#include <algorithm>
#include <iostream>
#include <cstring>
#include <complex>
#include <cstdio>
#include <string>
#include <cmath>
#include <vector>
using namespace std;
typedef long long LL;
const int MOD = int(1e9)+7;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-9;
const double PI = acos(-1.0); //M_PI;
const int maxn = 1000001;
int a[maxn];
vector<int> v;
int main()
{#ifdef DoubleQfreopen("in.txt","r",stdin);#endifstd::ios::sync_with_stdio(false);std::cin.tie(0);int n , m;while(cin >> n >> m){int x = 0 , y = 0;for(int i = 1 ; i <= n ; i ++){cin >> a[i];if(a[i] == 1)x ++;elsey ++;}int l , r;v.clear();for(int i = 0 ; i < m ; i ++){cin >> l >> r;int k = r - l + 1;if(k % 2 != 0)v.push_back(0);else{if(k / 2 <= x && k / 2 <= y)v.push_back(1);elsev.push_back(0);}}for(int i = 0 ; i < v.size() ; i ++)cout << v[i] << endl;}
}
这篇关于Codeforces Round #182 (Div. 2)A(水题)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!