Saving James Bond - Easy Version(25 分)深搜

9人阅读 评论(0) 收藏 举报
分类:

题意:人在一个方形湖中间的孤岛上,直径15(半径7.5),人可以跳d的距离,方形湖,边长50。周边有n个鳄鱼,人可以通过逐个跳到鳄鱼上实现逃生。
题解:n小于100,直接dfs.
代码:

#include<bits/stdc++.h>
using namespace std;
struct node{
    double x,y;
}fish[105];
/*bool cmp(node a,node b){
    return a.x*a.x+a.y*a.y<=b.x*b.x+b.y*b.y;
} */
bool vis[105];
int n;
double d;
bool end(int x){//完成逃生
    return (fish[x].x+d>=50||fish[x].x-d<=-50||fish[x].y+d>=50||fish[x].y-d<=-50);
}
bool judge(int a,int b){//可以进行跳跃
    return ((fish[a].x-fish[b].x)*(fish[a].x-fish[b].x)+(fish[a].y-fish[b].y)*(fish[a].y-fish[b].y)<=d*d);
}
bool dfs(int x){
    vis[x]=true;
    if(end(x)){
        return true;
    }
    else for(int i=0;i<n;i++){
        if(!vis[i]&&judge(x,i)){
            if(dfs(i))return true;//往下探索,再往上传递 
        }
    }
    return false;
}
int main(){
    ios::sync_with_stdio(false);
    //freopen("1.txt","r",stdin);
    cin>>n>>d;
    int first;
    for(int i=0;i<n;i++){
        cin>>fish[i].x>>fish[i].y;
        vis[i]=false;
    }
    //sort(fish,fish+n,cmp);
    int flag=0;
    for(int i=0;i<n;i++){
        if((fish[i].x*fish[i].x+fish[i].y*fish[i].y)<=((7.5+d)*(7.5+d))&&!vis[i]){
            if(!vis[i]&&dfs(i)){
                printf("Yes\n");
                flag=1;
                break;
            }
        }
    }
    if(!flag)cout<<"No\n";
    return 0;
}
查看评论

06-图2. Saving James Bond - Easy Version (25)

06-图2. Saving James Bond - Easy Version (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判...
  • Jimko_Penng
  • Jimko_Penng
  • 2015-04-16 19:22:17
  • 945

06-图2. Saving James Bond - Easy Version

This time let us consider the situation in the movie “Live and Let Die” in which James Bond, the wor...
  • qq_22902423
  • qq_22902423
  • 2015-05-21 01:27:14
  • 485

Saving James Bond - Easy Version

题目: This time let us consider the situation in the movie "Live and Let Die" in which James Bond...
  • Phenixfate
  • Phenixfate
  • 2015-01-04 23:58:08
  • 867

05-图2. Saving James Bond - Easy Version (25).zip

  • 2015年06月23日 09:54
  • 438KB
  • 下载

06-图4. Saving James Bond - Hard Version (30).zip

  • 2015年06月19日 15:43
  • 577KB
  • 下载

07-图5 Saving James Bond - Hard Version (30分)

This time let us consider the situation in the movie "Live and Let Die" in which James Bond, the wor...
  • xijujie
  • xijujie
  • 2016-11-06 21:46:10
  • 586

07-图4. Saving James Bond - Hard Version (30)

dfs
  • xinag578
  • xinag578
  • 2015-05-06 22:39:55
  • 1461

PAT--Saving James Bond - Hard Version

这题算是经典BFS了,不贴代码,只说两件事。 用例四没过说明,“If there are many shortest paths, just output the one with the mini...
  • grooowing
  • grooowing
  • 2015-04-15 20:41:35
  • 841

06-图4. Saving James Bond - Hard Version (30)

题目来源: http://www.patest.cn/contests/mooc-ds/06-%E5%9B%BE4 解: import java.util.ArrayList; import...
  • ch717828
  • ch717828
  • 2015-05-31 18:47:22
  • 734

05-图2. Saving James Bond - Easy Version (25)

1 边界和湖心小岛分别算一个节点,连接所有距离小于D的鳄鱼,时间复杂度O(N2) 2 判断每个连通图的节点中是否包含边界和湖心小岛,是则Yes否则No 3 冗长混乱的函数参数 #include ...
  • qq_19672579
  • qq_19672579
  • 2015-06-03 00:16:20
  • 694
    个人资料
    持之以恒
    等级:
    访问量: 1172
    积分: 217
    排名: 76万+
    文章存档