QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#61401#2615. Surround the CattichecTL 0ms0kbC++142.7kb2022-11-12 20:34:082022-11-12 20:34:09

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-11-12 20:34:09]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2022-11-12 20:34:08]
  • 提交

answer

#include <bits/stdc++.h>
#define up 100
using namespace std;
#define mkp make_pair
#define pb push_back
mt19937 mt(20080820);
int vist[1005][1005], flag = 6 * 9;
int f[405][405], wz[1005][1005];
int gs = 0;
bool check(int x,int y){
	if(max(abs(x),abs(y))==9)return 1;
	if(abs(x-y)==9)return 1;
	return 0;
}
vector<pair<int, int>>v1, v2;
void del1(int x,int y){
	for(auto cc=v1.begin();cc!=v1.end();cc++){
		auto cu=*cc;
		if(cu.first==x&&cu.second==y){v1.erase(cc);break;}
	}
}
void del2(int x,int y){
	for(auto cc=v2.begin();cc!=v2.end();cc++){
		auto cu=*cc;
		if(cu.first==x&&cu.second==y){v2.erase(cc);break;}
	}
}
void opt(int x,int y){
	if(!vist[x+up][y+up]){
		vist[x+up][y+up]=1;
		if(check(x,y))flag--;
	}
	del1(x,y);del2(x,y);
	printf("%d %d\n",x,y);
}
void add(int x,int y,int xx,int yy){
	int a=wz[x+up][y+up],b=wz[xx+up][yy+up];
	if(a&&b)f[a][b]=f[b][a]=1;
}
int dis(int x,int y,int xx,int yy){
	int a=wz[x+up][y+up],b=wz[xx+up][yy+up];
	if(a&&b)return f[a][b];
	return 1e9;
}
int main(){
	int tot=0;
	for(int i=-9;i<=9;i++){
		int L=-9,R=9;
		if(L<0)R=9+i;
		else L=-9+i;
		for(int j=L;j<=R;j++){
			v1.pb(mkp(i,j));
			wz[i+up][j+up]=++tot;
			if(check(i,j))v2.pb(mkp(i,j));
		}
	}
	memset(f,63,sizeof f);
	for(int i=1;i<=tot;i++)f[i][i]=0;
	for(auto vv:v1){
		int X=vv.first,Y=vv.second;
		add(X,Y,X,Y+1);
		add(X,Y,X+1,Y);
		add(X,Y,X+1,Y+1);
	}
	for(int k=1;k<=tot;k++)
		for(int i=1;i<=tot;i++)
			for(int j=1;j<=tot;j++)
				f[i][j]=min(f[i][j],f[i][k]+f[k][j]);
	int cx,cy;scanf("%d%d",&cx,&cy);
	srand(time(NULL));
	int xx=7;opt(xx,xx);
	while(1){
		if(scanf("%d%d",&cx,&cy)==EOF)return 0;
		if(cx>cy&&!vist[xx+up][0+up]){opt(xx,0);continue;}
		if(cy<0&&!vist[0+up][-xx+up]){opt(0,-xx);continue;}
		if(cx<0&&!vist[-xx+up][-xx+up]){opt(-xx,-xx);continue;}
		if(cx<cy&&!vist[-xx+up][0+up]){opt(-xx,0);continue;}
		if(cy>0&&!vist[0+up][xx+up]){opt(0,xx);continue;}
		if(cx>0&&!vist[xx+up][xx+up]){opt(xx,xx);continue;}
		if(!flag){
			auto dy=v1[mt()%v1.size()];
			while(dy.first==cx&&dy.second==cy)dy=v1[mt()%v1.size()];
			opt(dy.first,dy.second);
			continue;
		}
		int mx=1e9;
		for(auto cu:v2){
			int dd=dis(cx,cy,cu.first,cu.second);
			mx=min(mx,dd);
		}
		vector<pair<int, int>>g;
		for(auto cu:v2){
			int dd=dis(cx,cy,cu.first,cu.second);
			if(dd=mx)g.pb(cu);
		}
		vector<pair<int,int>>gg;
		mx=1e9;
		for(auto cu:g){
			int dd=0;
			for(auto uc:g)dd+=dis(cu.first,cu.second,uc.first,uc.second);
			if(mx>dd)mx=dd;
		}for(auto cu:g){
			int dd=0;
			for(auto uc:g)dd+=dis(cu.first,cu.second,uc.first,uc.second);
			if(mx==dd)gg.pb(cu);
		}
		auto dy=gg[mt()%gg.size()];
		opt(dy.first, dy.second);
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Time Limit Exceeded

input:

0 0

output:


result: