关于pta上面的一道题目有某个测试点不过求解答

This time let us consider the situation in the movie "Live and Let Die" in which James Bond, the world's most famous spy, was captured by a group of drug dealers. He was sent to a small piece of land at the center of a lake filled with crocodiles. There he performed the most daring action to escape -- he jumped onto the head of the nearest crocodile! Before the animal realized what was happening, James jumped again onto the next big head... Finally he reached the bank before the last crocodile could bite him (actually the stunt man was caught by the big mouth and barely escaped with his extra thick boot).

Assume that the lake is a 100 by 100 square one. Assume that the center of the lake is at (0,0) and the northeast corner at (50,50). The central island is a disk centered at (0,0) with the diameter of 15. A number of crocodiles are in the lake at various positions. Given the coordinates of each crocodile and the distance that James could jump, you must tell him a shortest path to reach one of the banks. The length of a path is the number of jumps that James has to make.

Input Specification:

Each input file contains one test case. Each case starts with a line containing two positive integers N (≤100), the number of crocodiles, and D, the maximum distance that James could jump. Then N lines follow, each containing the (x,y)location of a crocodile. Note that no two crocodiles are staying at the same position.

Output Specification:

For each test case, if James can escape, output in one line the minimum number of jumps he must make. Then starting from the next line, output the position (x,y) of each crocodile on the path, each pair in one line, from the island to the bank. If it is impossible for James to escape that way, simply give him 0 as the number of jumps. If there are many shortest paths, just output the one with the minimum first jump, which is guaranteed to be unique.

Sample Input 1:

17 15
10 -21
10 21
-40 10
30 -50
20 40
35 10
0 -10
-25 22
40 -40
-30 30
-10 22
0 11
25 21
25 10
10 10
10 35
-30 10

Sample Output 1:

4
0 11
10 21
10 35

Sample Input 2:

4 13
-12 12
12 12
-12 -12
12 -12

Sample Output 2:

0

上面是题目  /////////////////

下面是我的代码//////////////////

#include <stdio.h>

#include <math.h>

typedef struct {

    int x;

    int y;

}Node;

 

Node data[101];

int visited[101];

int resultNow[101], resultMin[101];

int v, r, countMin, countNow;

 

int DFS(int now, int index);

 

int main() {

    scanf("%d%d", &v, &r);

    countMin = 200;

    countNow = 0;

    for (int i = 0; i < v; i++) {

         scanf("%d%d", &data[i].x, &data[i].y);

    }

    int mark = 0;

    if (r >= 35) {

         printf("1\n");

         return 0;

    }

    for (int i = 0; i < v; i++) {

         if (pow(data[i].x, 2) + pow(data[i].y, 2) - 15 * 15 <= r*r)

             if (DFS(i, 0))

                  mark = 1;

    }

 

    if (mark) {

         printf("%d\n", countMin + 1);

         for (int i = 0; i < countMin; i++)

             printf("%d %d\n", data[resultMin[i]].x, data[resultMin[i]].y);

    }

    else

         printf("0\n");

    return 0;

}

 

int DFS(int now, int index) {

    visited[now] = 1;

    countNow++;

    resultNow[index] = now;

    if (50 - abs(data[now].x) <= r || 50 - abs(data[now].y) <= r) {

//更新,要么找到更小的,要么第一跳距离更小

         if (countNow < countMin || countNow == countMin&&pow(data[resultNow[0]].x, 2) + pow(data[resultNow[0]].y, 2) <

             pow(data[resultMin[0]].x, 2) + pow(data[resultMin[0]].y, 2)) {

             countMin = countNow;

             for (int i = 0; i < countMin; i++)

                  resultMin[i] = resultNow[i];

         }

         visited[now] = 0;

         countNow--;

         return 1;

    }

    int mark = 0;

    for (int i = 0; i < v; i++) {

         if (!visited[i] && pow(data[now].x - data[i].x, 2) + pow(data[now].y - data[i].y, 2) <= r*r) {

             mark = DFS(i, index + 1);

         }

    }

    visited[now] = 0;

    countNow--;

    if (mark)

         return 1;

    else

         return 0;

}

//img3.sycdn.imooc.com/59e4a19d0001e3e113720429.jpg


关于那个更新的我上面不是写了吗?为什么还不过。。。

求大佬帮帮忙。。。。

Single丶love
浏览 2747回答 0
0回答
打开App,查看更多内容
随时随地看视频慕课网APP