为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

Single丶love 2017-10-16 20:12:11
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 1510 -2110 21-40 1030 -5020 4035 100 -10-25 2240 -40-30 30-10 220 1125 2125 1010 1010 35-30 10Sample Output 1:40 1110 2110 35Sample Input 2:4 13-12 1212 12-12 -1212 -12Sample 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;}关于那个更新的我上面不是写了吗?为什么还不过。。。求大佬帮帮忙。。。。
查看完整描述

目前暂无任何回答

  • 0 回答
  • 0 关注
  • 2746 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信