生活随笔
收集整理的這篇文章主要介紹了
07-图4. Saving James Bond - Hard Version (30)
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
本題測(cè)試點(diǎn)5是從小島范圍內(nèi)可以直接跳到岸邊……
測(cè)試點(diǎn)4是驗(yàn)證步數(shù)第一跳最小的情況,剛開(kāi)始沒(méi)有考慮回溯,所以錯(cuò)了……
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
const int inf=
1<<
30;
struct node
{
double x,y;
} a[
100+
5];
int n,vis[
100+
5],b[
100+
5],ans[
100+
5],cnt;
double d,ansfirst,nowfirst;
int dis(node d1,node d2)
{
if(d*d<(d1.x-d2.x)*(d1.x-d2.x)+(d1.y-d2.y)*(d1.y-d2.y))
return 0;
return 1;
}
int first(
int d1)
{
if(
sqrt(a[d1].x*a[d1].x+a[d1].y*a[d1].y)>d+
7.5)
return 0;
else return 1;
}
double first1(
int d1)
{
return sqrt(a[d1].x*a[d1].x+a[d1].y*a[d1].y)-
7.5;
}
int safe(node d1)
{
if(d1.x>=
50-d)
return 1;
if(d1.y>=
50-d)
return 1;
if(d1.x<=-
50+d)
return 1;
if(d1.y<=-
50+d)
return 1;
return 0;
}
void dfs(
int d1,
int now)
{
int i;
if(safe(a[d1])){
if(now<cnt){
for(i=
0; i<now; i++)ans[i]=b[i];cnt=now;ansfirst=nowfirst;}
else if(now==cnt&&ansfirst>nowfirst){
for(i=
0; i<now; i++)ans[i]=b[i];cnt=now;ansfirst=nowfirst;}
return ;}
else{
for(i=
1; i<=n; i++){
if(!vis[i]&&dis(a[d1],a[i])){vis[i]=
1;b[now]=i;dfs(i,now+
1);vis[i]=
0;}}}
return;
}
int main()
{
int i;
while(~
scanf(
"%d%lf",&n,&d)){a[
0].x=a[
0].y=
0;
for(i=
1; i<=n; i++){
scanf(
"%lf%lf",&a[i].x,&a[i].y);}
if(d+
7.5>=
50){
printf(
"1\n");
return 0;}ansfirst=(
double)inf;cnt=inf;
memset(ans,
0,
sizeof(ans));
for(i=
1; i<=n; i++){
memset(vis,
0,
sizeof(vis));
if(!vis[i]&&first(i)){nowfirst=first1(i);
if(safe(a[i])){
if(ansfirst>nowfirst){ans[
0]=i;cnt=
1;ansfirst=nowfirst;}}vis[i]=
1;
memset(b,
0,
sizeof(b));b[
0]=i;dfs(i,
1);}}
if(cnt==inf)
printf(
"0\n");
else{
printf(
"%d\n",cnt+
1);
for(i=
0; i<cnt; i++){
printf(
"%.0f %.0f\n",a[ans[i]].x,a[ans[i]].y);}}}
return 0;
}
版權(quán)聲明:本文為博主原創(chuàng)文章,未經(jīng)博主允許不得轉(zhuǎn)載。http://xiang578.top/
轉(zhuǎn)載于:https://www.cnblogs.com/xryz/p/4848004.html
總結(jié)
以上是生活随笔為你收集整理的07-图4. Saving James Bond - Hard Version (30)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。