[每日一题2020.06.07]codeforces Round #627 (Div. 3)

problem A

/*
 * Author: RoccoShi
 * Time: 2020-06-07 19:37:51
*/

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin >> t;
    while(t--){
    	int n, x, y, ans = 0;
    	cin >> n;
    	cin >> x;
    	n-=1;
    	while(n--)
    	{
    		cin >> y;
    		if(abs(y-x)%2!=0)
    			ans = 1;
    	}
    	if(ans == 1) cout << "NO" << endl;
    	else 
    		cout << "YES" << endl;
    }
    return 0;

problem B

/*
 * Author: RoccoShi
 * Time: 2020-06-07 19:37:51
*/

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
int a[5005];


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t; cin >> t;
    while (t--)
    {
    	int n; cin >> n;
    	int ans = 0;
    	for(int i = 0; i < n; ++i)
    	{
    		cin >> a[i];
    	}
    	int i = 0, j = n - 1;
    	while(i != n-2 && n >= 3)
		{
			if(a[j] == a[i])
				ans++;
			if(ans >= 1)break;
			j--;
			if(j == i + 1){
				i++;
				j = n - 1;
			}
		}
    	if(ans >= 1)
    		cout << "YES" << endl;
    	else
    		cout << "NO" << endl;
    }
    return 0;
}

problem C

/*
 * Author: RoccoShi
 * Time: 2020-06-07 19:37:51
*/

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    int t;cin >> t;
    while( t-- ){
    	int seq = 0, step = 1;
    	cin >> s;
    	for( int i = 0; i < s.size(); ++i){
    		if(s[i] == 'L')
    			seq++;
    		else if(s[i] == 'R')
    			seq = 0;
    		if(step - seq <= 0)
    			step++;
    	}
    	cout << step << endl;
    }
    return 0;
}

problem D

sort + 双指针

/*
 * Author: RoccoShi
 * Time: 2020-06-07 19:37:51
*/

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

ll a[200005];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
	ll n;
	cin >> n;
	ll b;
	ll tmp = 0, sum = 0, j = 0;
	for(ll i = 0; i < n; ++i)
	{
		cin >> a[i];
	}
	for(ll i = 0; i < n; ++i)
	{
		cin >> b;
		a[i] -= b;
	}
	sort(a, a + n);
	for(ll i = n-1; i > 0; --i){
		if(a[i] <= 0)
			break;
		while(a[i] + a[j] <= 0){
			j++;
		}
		sum += (i - j);
		tmp = 0;
	}
	cout << sum << endl;
    return 0;
}
原文地址:https://www.cnblogs.com/roccoshi/p/13062581.html