codeforce #627 div3

A. Yet Another Tetris Problem

Code

#include <bits/stdc++.h>
using namespace std;
const int N=110;
int a[N];
void work(){
	int n;
	scanf("%d",&n);
	int maxv=-1;
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		maxv=max(maxv,a[i]);
	}
	bool ok=1;
	for(int i=1;i<=n;i++){
		if((maxv-a[i])%2)
			ok=0;
	}
	if(ok)
		puts("YES");
	else
		puts("NO");
}
int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		work();
	}
}

B. Yet Another Palindrome Problem

Code

#include <bits/stdc++.h>
using namespace std;
const int N=5010;
int a[N];
void work(){
	int n;
	scanf("%d",&n);
	unordered_map<int,int>p;
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	bool ok=0;
	for(int i=1;i<=n;i++){
		if(!p[a[i]]) {
			p[a[i]]=i;
			continue;
		}
		if(i-p[a[i]]>1){
			ok=1;
			break;
		}
	}
	if(ok)
		puts("YES");
	else
		puts("NO");
}
int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		work();
	}
}

C. Frog Jumps

Code

#include <bits/stdc++.h>
using namespace std;
const int N=2e5+10;
char a[N];
void work(){
	scanf("%s",a+1);
	int n=strlen(a+1);
	if(strlen(a+1)==1 && a[1]=='L'){
		puts("2");
		return;
	}
	int last=0;
	int res=-1;
	for(int i=1;i<=n;i++){
		if(a[i]=='R')  {
			res=max(res,i-last);
			last=i;
		}
	}
	res=max(res,n+1-last);
	printf("%d\n",res);
}
int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		work();
	}
}

D. Pair of Topics

Code

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N=2e5+10;
int n;
int main(){
	cin>>n;
	vector<ll>a(n);
	vector<ll>b(n);
	vector<ll>c(n);
	for(int i=0;i<n;i++)
		cin>>a[i];
	for(int i=0;i<n;i++)
		cin>>b[i];
	for(int i=0;i<n;i++)
		c[i]=a[i]-b[i];
	sort(c.begin(),c.end());
	ll ans=0;
	for(int i=0;i<n;i++){
		if(c[i] <= 0) continue;
		int pos=lower_bound(c.begin(),c.end(),-c[i]+1)-c.begin();
		ans+=i-pos;
	}
	cout<<ans<<endl;
}
posted @ 2020-05-19 23:10  Hyx'  阅读(142)  评论(0)    收藏  举报