Data Structures and Algorithms (English) - 7-10 Saving James Bond - Easy Version(25 分)

简介: Data Structures and Algorithms (English) - 7-10 Saving James Bond - Easy Version(25 分)

题目链接点击打开链接

题目大意:在一个 100*100 坐标 以及 中心原点(起点)在(0,0)位置并且半径为 7.5 的圆形上,附近有很多的鳄鱼(可以跳到上面去),问是否可以跳到坐标外(包含边界)。解题思路:第一跳需要特殊处理,接下来就DFS判断该坐标点是否可以跳出成功,或继续DFS下一个可跳的点。

AC 代码

#include<bits/stdc++.h>#include<cmath>#define mem(a,b) memset(a,b,sizeof a)#define ssclr(ss) ss.clear(), ss.str("")#define INF 0x3f3f3f3f#define MOD 1000000007usingnamespacestd;
typedeflonglongll;
structnode{
doublex,y;
intvis;
};
nodeori;
vector<node>vnd;
intn;
doubled;
doublefdis(nodea, nodeb)
{
returnsqrt(pow(a.x-b.x,2)+pow(a.y-b.y,2));
}
voiddfs(inti)
{
vnd[i].vis=1;
if(50-abs(vnd[i].x)<=d||50-abs(vnd[i].y)<=d)
    {
puts("Yes");
exit(0);
    }
for(intj=0;j<n;j++)
if(!vnd[j].vis&&fdis(vnd[j],vnd[i])<=d) dfs(j);
}
intmain()
{
nodend;
vector<int>vid;
scanf("%d%lf",&n,&d);
for(inti=0;i<n;i++)
    {
scanf("%lf%lf",&nd.x,&nd.y);
nd.vis=0;
vnd.push_back(nd);
    }
if(7.5+d>=50)
    {
puts("Yes");
return0;
    }
for(inti=0;i<n;i++)
if(fdis(vnd[i],ori)<=d+7.5) vid.push_back(i);
for(inti=0;i<vid.size();i++)
if(!vnd[vid[i]].vis) dfs(vid[i]);
puts("No");
return0;
}
目录
相关文章
《40 Must Know Questions to test a data scientist on Dimensionality Reduction techniques》电子版地址
40 Must Know Questions to test a data scientist on Dimensionality Reduction techniques
96 0
《40 Must Know Questions to test a data scientist on Dimensionality Reduction techniques》电子版地址
|
存储 容器
Data Structures and Algorithms (English) - 7-18 Hashing - Hard Version(30 分)
Data Structures and Algorithms (English) - 7-18 Hashing - Hard Version(30 分)
219 0
Data Structures and Algorithms (English) - 7-18 Hashing - Hard Version(30 分)
|
机器学习/深度学习 算法
Data Structures and Algorithms (English) - 7-28 Review of Programming Contest Rules(30 分)
Data Structures and Algorithms (English) - 7-28 Review of Programming Contest Rules(30 分)
209 0
Data Structures and Algorithms (English) - 7-28 Review of Programming Contest Rules(30 分)
Data Structures and Algorithms (English) - 7-11 Saving James Bond - Hard Version(30 分)
Data Structures and Algorithms (English) - 7-11 Saving James Bond - Hard Version(30 分)
176 0
Data Structures and Algorithms (English) - 7-8 File Transfer(25 分)
Data Structures and Algorithms (English) - 7-8 File Transfer(25 分)
110 0
Data Structures and Algorithms (English) - 6-8 Percolate Up and Down(20 分)
Data Structures and Algorithms (English) - 6-8 Percolate Up and Down(20 分)
104 0
Data Structures and Algorithms (English) - 6-15 Iterative Mergesort(25 分)
Data Structures and Algorithms (English) - 6-15 Iterative Mergesort(25 分)
186 0
Data Structures and Algorithms (English) - 7-9 Huffman Codes(30 分)
Data Structures and Algorithms (English) - 7-9 Huffman Codes(30 分)
101 0
Data Structures and Algorithms (English) - 6-14 Count Connected Components(20 分)
Data Structures and Algorithms (English) - 6-14 Count Connected Components(20 分)
140 0
Data Structures and Algorithms (English) - 6-7 Isomorphic(20 分)
Data Structures and Algorithms (English) - 6-7 Isomorphic(20 分)
126 0