POJ 2253 解题报告
来源:互联网 发布:人的审美观差异知乎 编辑:程序博客网 时间:2024/06/16 10:28
看了discuss,这道题似乎用很多方法都能accept:多源最短路径(Floyd),单源最短路径(Dijkstra, SPFA),或最小生成树(prime)。
我这里用的是spfa,稍稍改变下条件:
if (max(jump[u], weight[u][v]) < jump[v])
即更新从源到任意点的最大jump(即路径中的一跳)中的最小值。
thestoryofsnow2253Accepted480K16MSC++2167B/* ID: thestor1 LANG: C++ TASK: poj2253 */#include <iostream>#include <fstream>#include <cmath>#include <cstdio>#include <cstring>#include <limits>#include <string>#include <vector>#include <list>#include <set>#include <map>#include <queue>#include <stack>#include <algorithm>#include <cassert>using namespace std;const int MAXN = 200;// maximum distance between two pointsconst double INF = 1415.000; // sqrt(1000^2 + 1000^2)class Point{public:int x, y;Point(){Point(0, 0);}Point (int x, int y){this->x = x;this->y = y;}inline Point operator -(const Point &p) const {return Point(x - p.x, y - p.y);}double dis(){return sqrt((double)(x * x + y * y));}};// source is points[0], sink is points[1]void shortestPathFasterAlgorithm(Point points[], int n, double jump[], double weight[][MAXN], bool isInQueue[], int prev[]){int source = 0;for (int i = 0; i < n; ++i){jump[i] = INF;}jump[source] = 0;queue<int> que;que.push(source);memset(isInQueue, false, n * sizeof(bool));isInQueue[source] = true;memset(prev, -1, n * sizeof(int));while (!que.empty()){int u = que.front();que.pop();isInQueue[u] = false;for (int v = 0; v < n; ++v){if (max(jump[u], weight[u][v]) < jump[v]){jump[v] = max(jump[u], weight[u][v]);prev[v] = u;if (!isInQueue[v]){que.push(v);isInQueue[v] = true;}}}}}int main(){Point points[MAXN];double jump[MAXN], weight[MAXN][MAXN];bool isInQueue[MAXN];int prev[MAXN];int n, no = 1;const int sink = 1;while (scanf("%d", &n) && n){for (int i = 0; i < n; ++i){scanf("%d%d", &points[i].x, &points[i].y);}for (int i = 0; i < n; ++i){for (int j = 0; j < n; ++j){weight[i][j] = (points[i] - points[j]).dis();}}shortestPathFasterAlgorithm(points, n, jump, weight, isInQueue, prev);printf("Scenario #%d\n", no);no++;printf("Frog Distance = %.3f\n\n", jump[sink]);}return 0;}
0 0
- POJ 2253 解题报告
- POJ - 2253 Frogger解题报告
- poj数百篇解题报告
- poj 1141解题报告
- poj 1001解题报告
- poj 1011 解题报告
- poj 1087 解题报告
- poj 2153解题报告
- poj 2051解题报告
- POJ 1167 解题报告
- poj 1026 解题报告
- POJ 1077 解题报告
- POJ 1042 解题报告
- POJ 1095 解题报告
- POJ 1159解题报告
- poj 2312解题报告
- POJ 1001解题报告
- POJ 1002解题报告
- 【练习】面向对象系列(005)——在自定义窗口中画矩形、直线、椭圆、涂鸦
- SimpleDateFormat使用详解
- xampp phpmyadmin错误的处理
- js函数封装,使一个obj的透明度渐变,淡入淡出(兼容IE)
- Android中有四大组件activity、service、content provider、broadcast receiver
- POJ 2253 解题报告
- Array的分元操作
- Spark Shuffle初探
- 【BZOJ 3676】 [Apio2014]回文串
- 【BZOJ 3677】 [Apio2014]连珠线
- 【BZOJ 4011】 [HNOI2015]落忆枫音
- 【BZOJ 4010】 [HNOI2015]菜肴制作
- c/c++线程--1
- 啊会死啊网易哦去哦额偶去