2019-2020 ICPC Asia * Regional Contest

Axis of Symmetry

Binary Tree

Constructing Ranches

Defining Labels

Erasing Numbers

啊啊啊原题没捡到(不补题可太惨了)
看数据范围 我们可以使用n方的算法 就是枚举每一个位置 然后看他是否可以最终留下来
我们首先考虑最简单的 就是这个序列的中位数 我们发现它一定可以留下来
设x为中位数 把小于x的设置为1 大于x的设置为0
那么必然有01相邻的情况 我们每次选这样的三个数 那么0和1会各消去一个 最终必然会得到01x的形式
倘若x不是中位数的话 那么序列中肯定是0多了或者1多了
找到000和111这样的位置(也不一定是000 00100 也可以消掉两个0) 可以通过前缀和来实现
看能不能把序列变成01相等的状态
如果可以那么输出1 否则输出0

#include<bits/stdc++.h>
using namespace std;
const int N = 5e3+10;
int a[N],b[N],n;
bool check(int pos){
	int dif=abs(a[pos]-(n+1)/2);
	for(int i = 1; i <= n; i++)
	if(a[i]<a[pos]) b[i]=0;
	else b[i]=1;
	int flag=(a[pos]<(n+1)/2),now=0,add=0;
	for(int i = 1; i <= n; i++){
		if(i==pos){
			now=0;
			continue;
		}
		if(!b[i]==flag){
			now=max(now-1,0);
		}else{
			now++;
			if(now==3) add++,now-=2;
		}
	}
	return add>=dif;
}
int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		scanf("%d",&n);
		for(int i = 1; i <= n; i++){
			scanf("%d",&a[i]);
		}
		for(int i = 1; i <= n; i++){
			if(check(i)) printf("1");
			else printf("0");
		}
		puts("");
	} 
	return 0;
} 

Falling Objects

Game Design

Hold the Line

Incoming Asteroids

Junior Mathematician

Key Project

上一篇:redis分布式锁


下一篇:javaScript Storage的存取方法封装