POJ 2253 Frogger
来源:互联网 发布:apache文件服务器搭建 编辑:程序博客网 时间:2024/04/30 09:14
点击打开链接
题意:
有n个两个青蛙想见面,两个青蛙之间有n个石头,他必须一个一个跳过去。找到他女朋友。
问你他能找到他女朋友的情况下,最少的跳跃极限距离是多少。
题解:
建个图,跑一边spfa,就行了。
卧槽,我错的好惨啊,竟然是 因为我输出的是lf
改成f就过了。!!!!
double f;G++提交C++提交本机gcc测试最安全的方法输入scanf("%lf", &f);scanf("%lf", &f);scanf("%lf", &f);cin >> f;输出printf("%f", f);printf("%lf", f);printf("%lf", f);cout << f;
大概就是这么多了,希望大家避免这种错误的发生。
#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>#include <queue>#include <cmath>using namespace std;const int inf=0xffffff;const int maxn=222;int cnt,n;struct no{ int x,y;}a[maxn];struct node{ int to,nxt; double w;}edge[maxn*maxn];int head[maxn];int vis[maxn];double dis[maxn];void addedge(int x,int y,double val){ edge[++cnt].to=y; edge[cnt].w=val; edge[cnt].nxt=head[x]; head[x]=cnt;}double pow(int x){ return x*x*1.0;}void spfa(int s){ for(int i=1;i<=n;++i) dis[i]=inf; queue <int> q; memset(vis,false,sizeof(vis)); q.push(s); dis[s]=0; while(!q.empty()) { int u=q.front(); q.pop(); vis[u]=false; for(int i=head[u];i!=-1;i=edge[i].nxt) { int v=edge[i].to; if(dis[v]>max(edge[i].w,dis[u])) { dis[v]=max(edge[i].w,dis[u]); if(!vis[v]) { vis[v]=true; q.push(v); } } } }}int main(){ int ca=1; while(scanf("%d",&n)&&n){ cnt=0; memset(head,-1,sizeof(head)); for(int i=1;i<=n;++i){ scanf("%d %d",&a[i].x,&a[i].y); for(int j=1;j<i;++j){ double s=pow(a[i].x-a[j].x)+pow(a[i].y-a[j].y); addedge(i,j,sqrt(s)); addedge(j,i,sqrt(s)); } } spfa(1); printf("Scenario #%d\nFrog Distance = ",ca++); printf("%.3f\n\n",dis[2]); } return 0;}
0 0
- poj 2253 - Frogger --- SPFA
- poj 2253 - Frogger --- dijkstra
- POJ 2253 Frogger
- poj 2253 Frogger
- poj 2253 Frogger
- poj 2253 Frogger
- POJ 2253 Frogger Floyd
- poj 2253 : Frogger (dijkstra)
- Poj 2253 Frogger
- POJ 2253 Frogger
- poj 2253 Frogger
- poj 2253 Frogger
- poj 2253 Frogger
- poj 2253 Frogger
- poj-2253-Frogger
- POJ 2253 Frogger
- POJ 2253 Frogger
- POJ 2253 Frogger
- linux下FTP服务器搭建
- QT小程序:QString
- 因特尔CPU i5和i7的区别在哪里,你知道ma?
- vuex学习实践笔记
- python-jenkins安装教程
- POJ 2253 Frogger
- 伪数组的概念
- WEB前端面试题—20170405
- 借贷记账法
- 递归递推练习―K―强化斐波那契
- tensorflow(1) 共享变量
- 编程题--给定一个字符串数组,判断每个字符出现次数
- 蓝桥杯 煤球数目
- 浅谈Promise