• 06-图2 Saving James Bond


    不是我说,pats是真的坑 少个<math.h>头文件我以为代码错了,卡了我半小时
    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 whether or not he can escape.

    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, print in a line “Yes” if James can escape, or “No” if not.

    Sample Input 1:
    14 20
    25 -15
    -25 28
    8 49
    29 15
    -35 -2
    5 28
    27 -29
    -8 -28
    -20 -35
    -25 -20
    -13 29
    -30 15
    -35 40
    12 12

    Sample Output 1:
    Yes

    Sample Input 2:
    4 13
    -12 12
    12 12
    -12 -12
    12 -12

    Sample Output 2:
    No

    #include<iostream>
    #include<math.h>
    using namespace std;
    #define diameter 15.00
    #include<queue>
    struct Node             //鳄鱼信息
    {
    	double x;
    	double y;
    	bool visited = false;
    	bool safe = false;
    	bool jump = false;
    }node[100];
    int n;//鳄鱼数量 
    double r;//跳跃最大距离
    bool judge = false;
    
    double getlength(double x1, double y1, double x2, double y2)
    {
    	return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
    }
    bool getsafe(double x,double y)
    {
    	if (abs(x - 50) <= r || abs(x + 50) <= r || abs(y - 50) <= r || abs(y + 50) <= r)
    		return true;
    	else return false;
    }
    bool getjump(double x, double y)
    {
    	if (getlength(x, y, 0, 0) <= r + diameter / 2)
    		return true;
    	else return false;
    }
    void inition()
    {
    	cin >> n >> r;
    	for (int i = 0; i < n; i++) {
    		cin >> node[i].x >> node[i].y;
    		if (getsafe(node[i].x, node[i].y))
    			node[i].safe = true;
    		if (getjump(node[i].x, node[i].y))
    			node[i].jump = true;
    	}
    }
    void bfs(int i)
    {
    	node[i].visited = true;
    	queue<Node>q;
    	q.push(node[i]);
    	while (!q.empty()) {
    		Node tem = q.front();
    		q.pop();
    		int j;
    		if (tem.safe) {
    			judge = true;
    			return;
    		}
    		for (j = 0; j < n; j++) {
    			if (!node[j].visited && getlength(tem.x, tem.y, node[j].x, node[j].y) <= r) {
    				node[j].visited = true;
    				q.push(node[j]);
    			}
    		}
    	}
    }
    int main()
    {
    	inition();
    	for (int i = 0; i < n; i++) {
    		if (node[i].jump) {
    			bfs(i);
    		}
    	}
    	if (judge)
    		cout << "Yes";
    	else
    		cout << "No";
    	return 0;
    }
    
    
    
  • 相关阅读:
    MongoDB的安全写入GetLastError
    mysql更新字段部分内容,连接条件过滤
    markdown 语法练习(样式输出)
    markdown 语法练习
    数据科学家访谈录 摘录(二)
    使用docker容器,创建镜像
    docker contioner报错:locale.Error: unsupported locale setting
    psql: FATAL: database "" does not exist 解决步骤
    ubuntu下docker 安装、使用mysql
    ubuntu使用crontab启动定时任务
  • 原文地址:https://www.cnblogs.com/Hsiung123/p/13109997.html
Copyright © 2020-2023  润新知