#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef struct A node;
struct A {
int v;//结点编号
int x;
int y;
};
node tmp[101];
vector<node> edge[101];//edge[i]表示第i号结点能连接的结点
int last=0;//表示是否能跳到岸边
bool visited[100] = { false };
void dfs(int now,int d) {
visited[now] = true;
if (tmp[now].x >= (50 - d) || tmp[now].x <= (d - 50) || tmp[now].y >= (50 - d) || tmp[now].y <= (d - 50)) {
cout << "Yes" << endl;
last = 1;
return;
}
for (auto iter = edge[now].begin(); iter != edge[now].end(); iter++) {
if (!visited[(*iter).v]) {
dfs((*iter).v,d);
}
}
}
int dis(int x, int y) {
return x * x + y * y;
}
int main() {
int n, d;
cin >> n >> d;//n为点个数,d为移动距离
int D = d * d;
for (int i =1 ; i <= n; i++) {
tmp[i].v = i;
cin >> tmp[i].x >> tmp[i].y;
}
tmp[0].v = 0;//小岛为0号结点
tmp[0].x = 0;
tmp[0].y = 0;
for(int i=0;i<=n;i++)
for (int j = 0; i <= n; j++)//存储边的信息
{
if (dis(tmp[i].x - tmp[j].x, tmp[i].y - tmp[j].y) <= D) {
edge[i].push_back(tmp[j]);
edge[j].push_back(tmp[i]);
}
}
for (auto iter = edge[0].begin(); iter != edge[0].end(); iter++) {
memset((void*)visited, 0, sizeof(visited));
dfs((*iter).v,d);
if (last == 1) break;
}
if (last == 0) {
cout << "No" << endl;
}
system("pause");
return 0;
}
问题是 100×100 的正方形中间有一个点为原点,输入n个点的坐标,和最大移动的距离,问能不能跳到正方形的边上
遇到的问题如题,第一次遇到这种问题不知道怎么改
估计是下标越界了,你加个断点,点击调试,马上就知道哪句代码出错了。