Codeforces_Educational Codeforces Round 94 (Rated for Div. 2)

A
https://codeforces.com/contest/1400/problem/A
由于长度为 n-1,所以只要出现连续n个 0(或1),那么答案一定是连续的n个0(或1),若没有连续的n个一样的数,那么随便输出连续n个一样的数都符合题意。

//https://codeforces.com/contest/1400/problem/0
#include <cstdio>
int a[10000],t,n,num,cnt,he;
char ch,lst;
 
void rd(char &xx){
	xx='4';
	while (xx!='1'&&xx!='0') scanf("%c",&xx);
}
 
int main(){
	scanf("%d",&t);
	for (; t--; ){
		scanf("%d",&n);
		cnt=0,he=0;
		for (int i=1,j=2*n-1; i<=j; i++){
			rd(ch);
			if (ch==lst) cnt++; else lst=ch,cnt=1;
			if (cnt==n) he=ch-'0';
		}
		for (int i=1; i<=n; i++) printf("%d",he);
		printf("\n");
	}
}

D
https://codeforces.com/contest/1400/problem/D
在这里插入图片描述
结合图片与最后的注释即可

#include <cstdio>
int L[3500][3500],R[3500][3500],a[3500],n,t;
long long ans;
 
int main(){
	for(scanf("%d",&t); t; t--){
		ans=0;
		scanf("%d",&n);
		for (int i=1; i<=n; i++) scanf("%d",&a[i]);
		for (int i=1; i<=n; i++){
			for (int j=1; j<=n; j++) L[j][i]=L[j][i-1];
			L[a[i]][i]=L[a[i]][i-1]+1;
		}
		for (int i=n; i; i--){
			for (int j=1; j<=n; j++) R[j][i]=R[j][i+1];
			R[a[i]][i]=R[a[i]][i+1]+1;
		}
		for (int j=1; j<n; j++)
			for (int k=j+1; k<n; k++)
				ans=ans+(long long)L[a[k]][j-1]*R[a[j]][k+1];
		printf("%lld\n",ans);
	}
}
 
/*
L[a][b] [1,b]中 a 的个数 
R[a][b] [b,n]中 a 的个数 
*/

猜你喜欢

转载自blog.csdn.net/jackypigpig/article/details/108232093