poj 2253(区间DP)

男娘i 2022-06-04 03:05 364阅读 0赞

原题

思路:求所有路径中最大跳跃距离的最小值, 很诡异的是输出答案如果用G++,.3lf%格式会出错,c++可以过

  1. #include<cstdio>
  2. #include<cmath>
  3. #include<vector>
  4. #include<iostream>
  5. #include<stack>
  6. #include<cstring>
  7. using namespace std;
  8. const double INF=0x3f3f3f3f;
  9. const int maxn=2e2+10;
  10. double mp[maxn][maxn], dis[maxn][maxn], cor[maxn][maxn];
  11. int n;
  12. int main(){
  13. int cas=0;
  14. while(~scanf("%d", &n) && n)
  15. {
  16. for(int i=1; i<=n; i++)
  17. {
  18. scanf("%lf%lf", &cor[i][0], &cor[i][1]);
  19. //cout<<cor[i][0]<<" "<<cor[i][1]<<endl;
  20. }
  21. for(int i=1; i<=n; i++)
  22. {
  23. for(int j=1; j<=n; j++)
  24. {
  25. double x2, y2;
  26. x2=(cor[i][0]-cor[j][0])*(cor[i][0]-cor[j][0]);
  27. y2=(cor[i][1]-cor[j][1])*(cor[i][1]-cor[j][1]);
  28. dis[i][j]=mp[i][j]=sqrt(x2 + y2);
  29. //cout<<mp[i][j]<<" ";
  30. }
  31. //cout<<endl;
  32. }
  33. for(int k=1; k<=n; k++)
  34. for(int i=1; i<=n; i++)
  35. for(int j=1; j<=n; j++)
  36. dis[i][j]=min(dis[i][j], max(dis[i][k], dis[k][j]));
  37. printf("Scenario #%d\n", ++cas);
  38. printf("Frog Distance = %.3lf\n\n", dis[1][2]);
  39. }
  40. return 0;
  41. }

发表评论

表情:
评论列表 (有 0 条评论,364人围观)

还没有评论,来说两句吧...

相关阅读

    相关 POJ2253 Frogger(Floyd)

    题目描述:青蛙A要找青蛙B,路径任选,求所有可能路径中跳的最远的一步,它们之中的最小距离值。 输入要求,第一行为石头数,二三行为起点和终点位置,n-2行为其他石头结点。第一

    相关 poj 2253区间DP

    [原题][Link 1] 思路:求所有路径中最大跳跃距离的最小值, 很诡异的是输出答案如果用G++,.3lf%格式会出错,c++可以过 include<cstdio

    相关 POJ1179 Polygon(区间dp

    题意:多边形游戏是一个单人玩的游戏,开始时有一个由n个顶点构成的多边形。每个顶点被赋予一个整数值,每条边被赋予一个运算符“+”或“\”。所有边依次用整数从1到n编号,游戏第1