Saving James Bond+迪杰斯特拉算法
来源:互联网 发布:姚明第一个赛季数据 编辑:程序博客网 时间:2024/05/18 01:10
Saving James Bond
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1258 Accepted Submission(s): 230
Problem Description
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×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 he could escape.If he could,tell him the shortest length he has to jump and the min-steps he has to jump for shortest length.
Assume that the lake is a 100×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 he could escape.If he could,tell him the shortest length he has to jump and the min-steps he has to jump for shortest length.
Input
The input consists of several test cases. Each case starts with a line containing n <= 100, the number of crocodiles, and d > 0, the distance that James could jump. Then one line follows for each crocodile, containing the (x, y) location of the crocodile. Note that x and y are both integers, and no two crocodiles are staying at the same position.
Output
For each test case, if James can escape, output in one line the shortest length he has to jump and the min-steps he has to jump for shortest length. If it is impossible for James to escape that way, simply ouput "can't be saved".
Sample Input
4 1017 027 037 045 01 1020 30
Sample Output
42.50 5can't be saved迪杰斯特拉算法;/*wrong:求路过大神调试*/#include<iostream>#include<cmath>#include<iomanip>using namespace std;#define MAX 102 #define inf 1000000000typedef struct infor{double x , y ;}infor ;int n ,v[MAX];double s[MAX][MAX] ;void shortpath(){int i,j ,k ,step=1 ;double d[MAX];for( i = 0 ; i <= n ; i++)d[i] = s[0][i] ;d[0] = 0 ;v[0] = 1;for( i = 0 ; i<=n; i++){double min1 = inf + 1;for(j= 0 ; j<= n ;j++)if(!v[j] && min1 > d[j]){k= j;min1 = d[j] ;}v[k] = 1;for( j = 0 ; j <= n ; j++)if(!v[j] && (min1 + s[k][j]) < d[j]){d[j] = min1 + s[k][j] ;step ++ ;}}if(d[n] == inf )cout<<"can't be saved"<<endl;elsecout<<fixed<<setprecision(2)<<d[n]<<" "<<step<<endl;}double min(double a, double b){return a>b?b:a;}int main(void){double len ;while(cin>>n>>len){memset(v,0,sizeof(v));int i , j ;infor a[MAX];for( i = 1 ; i <=n ; i++)cin>>a[i].x >> a[i].y ;a[0].x = a[0].y = 0 ;n=n+1 ;a[n].x = a[n].y = 50 ;for( i= 0 ; i <= n ; i++)for( j = 0 ; j <= n ; j++){s[i][j] = s[j][i] = sqrt((a[i].x- a[j].x)*(a[i].x-a[j].x) + (a[i].y-a[j].y)*(a[i].y-a[j].y)); if(i== n)s[i][j] = s[j][i] = min(50 - fabs(a[j].x),50-fabs(a[j].y) );if( j == n )s[i][j] = s[j][i] = min(50 - fabs(a[i].x),50-fabs(a[i].y ));if((i == 0 || j == 0 ) && s[i][j] >= 7.5)s[i][j] = s[j][i] = s[i][j] - 7.5 ;if(i == j)s[i][j] = s[j][i] = 0 ;if(s[i][j] > len)s[i][j] = s[j][i] = inf ;}shortpath();}return 0;}
- Saving James Bond+迪杰斯特拉算法
- hdu1245 Saving James Bond
- Saving James Bond HDU
- Saving James Bond
- Saving James Bond
- Saving James Bond
- HDOJ 1245 Saving James Bond
- hdu 1245 Saving James Bond
- HDU 1245 Saving James Bond
- HDU1245:Saving James Bond(Floyd)
- HDU 1245 Saving James Bond
- HDU1245:Saving James Bond(Floyd)
- Saving James Bond - Easy Version
- Saving James Bond - Hard Version
- Saving James Bond - Easy Version
- HDU-1245-Saving James Bond
- Saving James Bond - Easy Version
- 5-10 Saving James Bond
- 完全编译 rhodium-nand,xdanrdoid的直刷文件
- ubuntu 下安装 tomcat6.0.28
- 如何安装install_flash_player_11_linux.i386.tar.gz
- ssh 反应慢可能的原因
- OpenCV学习笔记(8)—轮廓的匹配
- Saving James Bond+迪杰斯特拉算法
- CentOS 6.3 编译安装 MySQL 5.6.10 并修改MySQL的root用户密码
- 在导航控制器的边框绘制阴影
- 强行重置Mac OS X管理员密码
- C++学习笔记_1:派生类与基类关系
- jquery常用效果控制
- eclipse代码自动提示设置
- 给Mac加上固件密码
- 恢复出厂设置流程概括