QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#90354#2615. Surround the CatCSUTL 0ms0kbC++142.7kb2023-03-22 19:30:252023-03-22 19:30:27

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-22 19:30:27]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2023-03-22 19:30:25]
  • 提交

answer

#include<bits/stdc++.h>
#define LL long long
#define mk make_pair
#define pii pair<int,int>
#define fi first
#define se second
using namespace std;
const int N = 21;
const int base = 10;
bool book[N][N],inq[N][N],c[N][N];
int dis[N][N];
const int dx[6] = {1,-1,0,0,1,-1},dy[6] = {0,0,1,-1,1,-1};
set <pii> s;
bool flag = 0;
inline int read(){
	int v = 0,c = 1;char ch = getchar();
	while(!isdigit(ch)){
		if(ch == '-') c = -1;
		ch = getchar();
	}
	while(isdigit(ch)){
		v = v * 10 + ch - 48;
		ch = getchar();
	}
	return v * c;
}
inline void bfs(int x,int y){
	memset(dis,0x3f,sizeof(dis));
	memset(inq,0,sizeof(inq));
	queue <pii> q;
	flag = 0;
	q.push(mk(x,y));
	dis[x + base][y + base] = 0;
	inq[x + base][y + base] = 1;
	while(!q.empty()){
		pii k = q.front();
		q.pop();
		for(int i = 0;i < 6;++i){
			int xx = k.fi + dx[i];
			int yy = k.se + dy[i];
			if(inq[xx + base][yy + base]) continue;
			dis[xx + base][yy + base] = dis[k.fi + base][k.se + base] + 1;
			if(!book[xx + base][yy + base]){
				inq[xx + base][yy + base] = 1;
				q.push(mk(xx,yy));
				flag = 1;
			}
		}
	}
}

inline pii check_margin(int x,int y){
	for(int i = 0;i < 6;++i){
		int xx = x + dx[i];
		int yy = y + dy[i];
		if(book[xx + base][yy + base] && !c[xx + base][yy + base]) return mk(xx,yy);
	}
	return mk(10,10);
}

int main(){
	for(int i = 0;i <= 9;++i){
	//	s.insert(mk(i,i - 9));
		if((i != 9 && (i & 1)) || i == 8) s.insert(mk(i,i - 9));
		if((i != 9 && (i & 1)) || i == 8) s.insert(mk(i,9));
		book[i + base][i - 9 + base] = 1;
		book[i + base][9 + base] = 1;
	}
	for(int i = 0;i >= -9;--i){
		if((i != -9 && ((-i) & 1)) || i == -8) s.insert(mk(i,i + 9));
		if((i != -9 && ((-i) & 1)) || i == -8) s.insert(mk(i,-9));
		book[i + base][i + 9 + base] = 1;	
		book[i + base][-9 + base] = 1;
	}
	for(int i = 0;i <= 9;++i){
		if((i != 9 && (i & 1)) || i == 8) s.insert(mk(9,i));
		if((i != 9 && (i & 1)) || i == 8) s.insert(mk(-9,-i));
		book[9 + base][i + base] = 1;
		book[-9 + base][-i + base] = 1;	
	}

	int cx = 0,cy = 0,lx = 0,ly = 0;
	while(1){
		scanf("%d%d",&cx,&cy); 
		pii k = check_margin(cx,cy);
		if(k == mk(10,10)){
			bfs(cx,cy);
			int mindis = 0x3f3f3f3f;
			for(auto x : s){
				if(c[x.fi + base][x.se + base]) continue;
				int d = dis[x.fi + base][x.se + base];
				if(d < 1e6){
					if(d < mindis) mindis = d,k = x;	
				}
			}
			
			if(mindis < 1e6){
				c[k.fi + base][k.se + base] = 1; 
				printf("%d %d\n",k.fi,k.se);
			}
			else{
				printf("%d %d\n",lx,ly);
				c[lx + base][ly + base] = 1;  
			}
			
		}
		else printf("%d %d\n",k.fi,k.se);	
		fflush(stdout);
		if(flag) lx = cx,ly = cy;
		else break;		
	}
    return 0;
}




详细

Test #1:

score: 0
Time Limit Exceeded

input:

0 0
-1 -1
-2 -1
-3 -1
-4 -1
-5 -2
-6 -2
-7 -2
-7 -3
-7 -2
-7 -3
-7 -4
-7 -3
-7 -4
-7 -3
-7 -4
-7 -3
-7 -2
-7 -1
-7 -2
-7 -1
-7 0
-6 1
-7 0
-6 1
-5 2
-6 1
-5 2
-6 1
-5 2
-4 3
-3 4
-2 5
-1 6
0 7
1 7
2 7
3 7
4 7
5 7
6 7
7 7
7 6
7 5
7 4
7 3
7 2
7 1
7 0
6 -1
5 -2
4 -3
3 -4
2 -5
1 -6
0 -7
-1 -7
-2 -7
-3 -...

output:

-9 -8
-9 -7
-9 -5
-9 -3
-9 -1
-8 1
-7 2
-8 -9
-7 -9
-5 4
-5 -9
-3 -9
-3 6
-1 -9
-1 8
1 -8
1 9
3 9
5 9
3 -6
5 -4
7 9
8 9
7 -2
9 3
9 5
9 7
9 8
8 -1
9 1
-5 2
-4 3
-3 4
-2 5
-1 6
0 7
1 7
2 7
3 7
4 7
5 7
6 7
7 7
7 6
7 5
7 4
7 3
7 2
7 1
7 0
6 -1
5 -2
4 -3
3 -4
2 -5
1 -6
0 -7
-1 -7
-2 -7
-3 -7
-4 -7
-5 -7
...

result: