90分求助:#6错误 写挂了55555...
查看原帖
90分求助:#6错误 写挂了55555...
159548
Zachary_Cloud楼主2021/6/5 15:59

RT.RT. 调炸了。求帮助

#6 Input

17 20
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0
0 0 1 0 0 0 1 0 1 0 1 0 1 0 1 0 0 1 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 1 0 0 0 1 0 0 0 0 0 0 0 1 0 0 1 0 0
0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0
0 0 1 0 0 0 1 0 0 0 0 0 0 0 1 0 0 1 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 1 0 0 0 1 0 1 0 1 0 1 0 1 0 0 1 0 0
0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
16 4 4 16 N

Output

12

Code output

13

Code

%:include <bits/stdc++.h>
using namespace std;

%:define F(i,a,b) for(register int i=a,i%:%:_end=b;i<=i%:%:_end;++i)
%:define D(i,a,b) for(register int i=a,i%:%:_end=b;i>=i%:%:_end;--i)
%:define WRITE_TIME printf("%.4f", (double)clock() / CLOCKS_PER_SEC)
%:define openFile(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout)
%:define closeFile() fclose(stdin),fclose(stdout)

typedef long long ll;
//static char buf[100000],*p1=buf,*p2=buf;
//%:define gc p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
//inline ll read() {ll res=0,w=0; char c=gc; while (!isdigit(c)) w|=c=='-',c=gc; while (isdigit(c)) res=(res<<1)+(res<<3)+(c^48),c=gc;if (w) res=-res;return res;}
//inline void write(ll x) {static int sta[50],top=0;if (x<0) putchar('-'),x=-x;do sta[top++]=x%10,x/=10;while (x); while (top) putchar(sta[--top]+48);}

inline ll read() {ll res = 0, w = 0; char ch = 0;while (!isdigit(ch)) w |= ch == '-', ch = getchar();while (isdigit(ch)) res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar();return w ? -res : res;}
inline void write(ll x) {if (x < 0) putchar('-'), x = -x;if (x > 9) write(x / 10);putchar(x % 10 + '0');}

//#include <sys/mman.h>
//#include <sys/stat.h>
//char* p;
//inline int read() {int x = 0, r = 1;while (*p < 48) {if (*p == '-') r = -r; p++;}while (*p >= 48) x = (x << 3) + (x << 1) + *p - 48, p++;return x * r;}
//inline void write(int x) {char s[20]; int c=0;do {s[c++]=x%10; x/=10; } while(x);for (int i = c-1; i >= 0; --i) putchar_unlocked(s[i] + 48);putchar(' ');}
//inline void init() {struct stat in;fstat(0, &in);p = (char*)mmap(0, in.st_size, 1, 2, 0, 0);}

inline void writeln(ll x) {write(x); putchar('\n');}
inline void writesp(ll x) {write(x); putchar(' ');}

int n, m, start_x, start_y, finish_x, finish_y, p;
int a[100][100], vis[100][100], v[100][100][4];
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

inline void bfs() {
	queue<int> x, y, d, o;
	x.push(start_x);
	y.push(start_y);
	d.push(p);
	o.push(0);
	vis[start_x][start_y] = 1;
	v[start_x][start_y][p] = 1;
	while (!x.empty()) {
//		puts("Fido_orz");
		int X = x.front(), Y = y.front();
		if (X == finish_x && Y == finish_y) {
			write(o.front());
			exit(0);
		}
		int bef = d.front() - 1, las = d.front() + 1;
		if (bef < 0) bef = 3;
		if (!v[X][Y][bef]) {v[X][Y][bef] = 1; x.push(X); y.push(Y); d.push(bef); o.push(o.front() + 1);}
		if (las > 3) las = 0;
		if (!v[X][Y][las]) {v[X][Y][las] = 1; x.push(X); y.push(Y); d.push(las); o.push(o.front() + 1);}
		int xx = X, yy = Y;
		F(i, 1, 3) {
			xx += dx[d.front()]; yy += dy[d.front()];
			if (xx < 1 || xx >= n || yy < 1 || yy >= m || vis[xx][yy]) break;
			if (a[xx][yy] || a[xx][yy + 1] || a[xx + 1][yy] || a[xx + 1][yy + 1]) break;
			vis[xx][yy] = 1; v[xx][yy][d.front()] = 1;
			x.push(xx); y.push(yy); d.push(d.front()); o.push(o.front() + 1);
		}
		x.pop(); y.pop(); d.pop(); o.pop();
	} 
}

signed main() {
	n = read(), m = read();
	F(i, 1, n) F(j, 1, m) a[i][j] = read();
	start_x = read(), start_y = read();
	finish_x = read(), finish_y = read();
	char c = getchar();
	while (c != 'E' && c != 'S' && c != 'W' && c != 'N') c = getchar();
	if (c == 'E') p = 0;
	else if (c == 'S') p = 1;
	else if (c == 'W') p = 2;
	else p = 3;
	bfs();
	puts("-1");
	return 0;
}
2021/6/5 15:59
加载中...