【每日一题】打卡 8

题目链接:Attachments - 2022 CCPC Henan Provincial Collegiate Programming Contest - CodeforcesklsCodeforces. Programming competitions and contests, programming communityhttps://codeforces.com/gym/103941/attachments【每日一题】打卡 8_第1张图片

 

第一次写出来的代码如下:

#define _CRT_SECURE_NO_WARNINGS 1
#include 
#include 
#include 
#include 
#include
#include
#include
#include
#define FOR(a,b) for(int i=a;i<=b;i++)
#define ROF(a,b) for(int i=a;i>=b;i--)
#define FORj(a,b) for(int j=a;j<=b;j++)
#define ROFj(a,b) for(int j=a;j>=b;j--)
#define FORk(a,b) for(int k=a;k<=b;k++)
#define ROFk(a,b) for(int k=a;k>=b;k--)
#define mem(i,a) memset(i,a,sizeof(i))
#define ll long long
#define inf 0x3f3f3f3f
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define int long long
#define yes cout<<"YES"< 2 || y < 1 || x<1 || x>m||st[y][x])return;	
	st[y][x]=1;
	if (f)return;
	if (pr == 0&&maze[y][x]=='I') {
		dfs(x, y - 1,0);
		dfs(x, y + 1,0);
	}
	if (pr == 1 && maze[y][x] == 'I') {
		dfs(x - 1, y,1);
		dfs(x + 1, y,1);
	}
	if (pr == 0 && maze[y][x] == 'L') {
		dfs(x - 1, y,1);
		dfs(x + 1, y,1);
	}
	if (pr == 1 && maze[y][x] == 'L') {
		dfs(x, y - 1,0);
		dfs(x, y + 1,0);
	}
		st[y][x]=0;
}
void solve() {
	mem(st,0);
     f=0;
	cin >> m >> kx >>ky;
	FOR(1, 2)
	FORj(1, m)cin >> maze[i][j];
//	FOR(1, 2)
//	FORj(1, m)cout<> _;
	while (_--)
		solve();
	return 0;
}

 然而它却T了,经过了一年的找bug的历程,我神奇地发现我特判了一下(在我看来时间复杂度变化不大)之后,它居然AC了,AC代码如下(就多加了俩句):

#define _CRT_SECURE_NO_WARNINGS 1
#include 
#include 
#include 
#include 
#include
#include
#include
#include
#define FOR(a,b) for(int i=a;i<=b;i++)
#define ROF(a,b) for(int i=a;i>=b;i--)
#define FORj(a,b) for(int j=a;j<=b;j++)
#define ROFj(a,b) for(int j=a;j>=b;j--)
#define FORk(a,b) for(int k=a;k<=b;k++)
#define ROFk(a,b) for(int k=a;k>=b;k--)
#define mem(i,a) memset(i,a,sizeof(i))
#define ll long long
#define inf 0x3f3f3f3f
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define int long long
#define yes cout<<"YES"< 2 || y < 1 || x<1 || x>m||st[y][x])return;
	st[y][x]=1;
	if (pr == 0&&maze[y][x]=='I') {
		dfs(x, y - 1,0);
		dfs(x, y + 1,0);
	}
	if (pr == 1 && maze[y][x] == 'I') {
	if(!st[y][x-1])dfs(x - 1, y,1);
		dfs(x + 1, y,1);
	}
	if (pr == 0 && maze[y][x] == 'L') {
	if(!st[y][x-1])	dfs(x - 1, y,1);
		dfs(x + 1, y,1);
	}
	if (pr == 1 && maze[y][x] == 'L') {
		dfs(x, y + 1,0);
		dfs(x, y - 1,0);
	}
	st[y][x]=0;
}
void solve() {

	f=0;
	cin >> m >> kx >>ky;
	for(int i = 0; i <= 2; i ++) {
		for(int j = 0; j <= m; j ++) st[i][j] = 0;
	}
	FOR(1, 2)
	cin >> maze[i]+1;
//	FOR(1, 2)
//	FORj(1, m)cout<> _;
	while (_--)
		solve();
	return 0;
}

后面根据这个特判又调了代码才发现,是数组越界不是T。。。 

这次经历告诉了我们不要完全相信评测机所报的错误~0 —— 0~。

你可能感兴趣的:(深度优先,c++,算法)