求调
查看原帖
求调
947029
Chen_Three楼主2024/11/21 20:30
#include<bits/stdc++.h>
using namespace std;
#define ll long long
struct node{
	int dir, x, y;
}Farm, Cow;
int memory_Farm[100000], memory_Cow[100000], dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1}, used[15][15];
int get_memory(node s){
	return s.dir * 400 + s.x * 20 + s.y;
}
void Farmmove(){
	int tx = Farm.x + dx[Farm.dir], ty = Farm.y + dy[Farm.dir];
	if(tx < 1 && tx > 10 && ty < 1 && ty > 10 && used[tx][ty] == -1) Farm.dir = (Farm.x + 1) % 4;
	else Farm.x = tx, Farm.y = ty;
	memory_Farm[get_memory(Farm)]++;
}
void Cowmove(){
	int tx = Cow.x + dx[Cow.dir], ty = Cow.y + dy[Cow.dir];
	if(tx < 1 && tx > 10 && ty < 1 && ty > 10 && used[tx][ty] == -1) Cow.dir = (Cow.x + 1) % 4;
	else Cow.x = tx, Cow.y = ty;
	memory_Cow[get_memory(Cow)]++;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t = 0;
	for(int i = 1; i <= 10; i++){
		string s;
		cin >> s;
		for(int j = 1; j <= 10; j++){
			char ch;
			ch = s[j - 1];
			if(ch == '*') used[i][j] = -1;
			if(ch == 'F') Farm = (node){0, i, j}, memory_Farm[get_memory(Farm)]++;
			if(ch == 'C') Cow = (node){0, i, j}, memory_Cow[get_memory(Cow)]++;
		}
	}
	//cout << "????";
	while(t < 2000000){
		t++;
		Farmmove();
		Cowmove();
		if(Farm.x == Cow.x && Farm.y == Cow.y) {
			cout << t; 
			return 0;
		}
	}
	cout << 0;
	return 0;
}

2024/11/21 20:30
加载中...