题解 | #「Nhk R1 A」Initiale Dorimu#

「Nhk R1 A」Initiale Dorimu

https://ac.nowcoder.com/acm/contest/11184/A

C 题有问题呀

出个hack数据

4 4
8
3 4
3 3
3 2
3 1
1 0
1 1
1 2
1 3

他说只能向上向右, 但是这个数据需要向上向右向下向右向上才能到达 但是ac的代码出Yes


#include <bits/stdc++.h>

using namespace std;
typedef long long LL;
typedef pair<int, int > PII;

const int N = 1e5;

int n, m, k;
map<PII , bool > mp, st;

struct Node
{
	int x, y;
	bool operator < (const Node & t) const{
		return x < t.x;
	}
}p[N], q[N];

bool bfs(int pos)
{
	int tt = -1, hh = 0;
	q[++ tt] = p[pos];
	
	while(tt >= hh)
	{
		auto t = q[hh ++];
		int nx = t.x, ny = t.y;
		st[{nx, ny}] = true;
		if(ny == 0 || nx == m)
		{
			return true;
		}
		
		if(mp[{nx+1, ny+1}] && !st[{nx+1, ny+1}]) 
			q[++ tt] = {nx+1, ny+1};
		if(mp[{nx+1, ny}] && !st[{nx+1, ny}]) 
			q[++ tt] = {nx+1, ny};
		if(mp[{nx+1, ny-1}] && !st[{nx+1, ny-1}]) 
			q[++ tt] = {nx+1, ny-1};
		if(mp[{nx, ny+1}] && !st[{nx, ny+1}]) 
			q[++ tt] = {nx, ny+1};
		if(mp[{nx, ny-1}] && !st[{nx, ny-1}]) 
			q[++ tt] = {nx, ny-1};
		if(mp[{nx-1, ny+1}] && !st[{nx-1, ny+1}])
			q[++ tt] = {nx-1, ny+1};
		if(mp[{nx-1, ny}] && !st[{nx-1, ny}])
			q[++ tt] = {nx-1, ny};
		if(mp[{nx-1, ny-1}] && !st[{nx-1, ny-1}])
			q[++ tt] = {nx-1, ny-1};
	}
	return false;
}

int main()
{
	cin >> n >> m >> k;
	for(int i = 1; i <= k; i ++)
	{
		cin >> p[i].x >> p[i].y;
		mp[{p[i].x, p[i].y}] = true;
	}
	
	sort(p+1, p+1+k);
	
	bool is = false;
	for(int i = 1; i <= k; i ++)
	{
		if(!st[{p[i].x, p[i].y}] && (p[i].x == 0 || p[i].y == n) && bfs(i))
		{
			is = true; // 表示可以封死
			break;
		}
	}
	if(!is) puts("Yes");
	else puts("No");
	return 0;
}
/*
4 4
4
2 0
2 1
2 2
2 3

*/
全部评论
你这个hack数据没问题我tm傻了,这你拿谁代码都是Yes叭
点赞 回复 分享
发布于 2022-01-01 20:46
AC的代码很多不是正解, 只要std没问题就行
点赞 回复 分享
发布于 2021-12-31 13:23
数据水了, 正解是不会错的
点赞 回复 分享
发布于 2021-12-31 13:20
不过你这个数据确定没问题吗
点赞 回复 分享
发布于 2021-12-31 11:04
c题数据有锅,很多代码都可以hack
点赞 回复 分享
发布于 2021-12-31 10:29

相关推荐

沉淀去了,8月是不是机会会多一点,。打招呼300+,就一个小厂面试,聊了十分钟天就让我去了,暑假继续沉淀了,到八月九月冲了
丰川打工祥:我目前的体感是,双非本+一段小厂实习,基本约不到中厂的面。已经开始第二段小厂了。可能的确是最近hc太少了。
点赞 评论 收藏
分享
野猪不是猪🐗:我assume that你must技术aspect是solid的,temperament也挺good的,however面试不太serious,generally会feel style上不够sharp
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务