萌新求助。
  • 板块灌水区
  • 楼主Sukilin
  • 当前回复1
  • 已保存回复1
  • 发布时间2023/8/21 10:16
  • 上次更新2023/11/3 02:18:45
查看原帖
萌新求助。
959201
Sukilin楼主2023/8/21 10:16

以下代码在 P1518 提交后结果不容乐观。

我下载了 #1 数据,在 DEVC++ 中运行是正确的。

#include<bits/stdc++.h>
#define len 10
#define maxl 19
#define maxt 1000000
using namespace std;
char mp[maxl][maxl];
int dx[5]={-1,0,1,0};
int dy[5]={0,1,0,-1};
int tzz,mcx,mcy,mfx,mfy,ans;
char p;
bool tz[maxt];//c.x+c.y*10+f.x*100+f.y*1000+c.face*10000+f.face*40000
struct cow{
	int x;
	int y;
	int face;
}c;
struct farm{
	int x;
	int y;
	int face;
}f;
int main(){
	c.face=0;
	f.face=0;
	for(int i=0;i<=len;i++){
		mp[0][i]=mp[i][0]='*';
	}
	for(int i=0;i<=len;i++){
		mp[11][i]=mp[i][11]='*';
	}
	for(int i=1;i<=len;i++){
		for(int j=1;j<=len;j++){
			mp[i][j]=getchar();
			if(mp[i][j]=='C'){
				c.x=i;
				c.y=j;
			}
			if(mp[i][j]=='F'){
				f.x=i;
				f.y=j;
			}
		}
		if(i<len)	p=getchar();
	}
	while(114514){
		if(f.x==c.x&&f.y==c.y){
			cout<<ans<<endl;
			return 0;
		}
		tzz=c.x+c.y*10+f.x*100+f.y*1000+c.face*10000+f.face*40000;
		if(tz[tzz]){
			cout<<0<<endl;
			return 0;
		}
		tz[tzz]=true;
		mcx=c.x+dx[c.face];
		mfx=f.x+dx[f.face];
		mcy=c.y+dy[c.face];
		mfy=f.y+dy[f.face];
		if(mp[mcx][mcy]=='*')	c.face=(c.face+1)%4;
		else{
			c.x=mcx;
			c.y=mcy;
		}
		
		if(mp[mfx][mfy]=='*')	f.face=(f.face+1)%4;
		else{
			f.x=mfx;
			f.y=mfy;
		}
		ans++;
	}
	
	return 0;
}
2023/8/21 10:16
加载中...