POJ 2253 Frogger题目意思就是求所有路径中最大路径中的最小值。

#include<iostream>
#include<cstdio>
#include<string.h>
#include <utility>//make_pair的头文件
#include<math.h>
using namespace std;
const int maxn=;
double map[maxn][maxn];
int n;
typedef struct pair<int,int> PAIR_IF;
double max(int a,int b)
{
if(a>b)
return a;
else
return b;
}
void floyd()
{
for(int v=;v<=n;v++)
for(int i=;i<=n;i++)
for(int j=;j<=n;j++)
if(map[i][j]>max(map[i][v],map[v][j]))
map[i][j]=max(map[i][v],map[v][j]);
printf("Frog Distance = %.3f\n\n",map[][]); }
double dis(PAIR_IF p1,PAIR_IF p2)
{
return (sqrt((double)(p1.first-p2.first)*(p1.first-p2.first)+(p2.second-p1.second)*(p2.second-p1.second))); }
int main()
{
std::ios::sync_with_stdio(false);//用这个语句,取消cin,cout与stdio的同步,就是提速,效率基本与scanf和printf一致。
int a,b;
PAIR_IF p[maxn];
int t=;
while(cin>>n&&n!=)
{
for(int i=;i<=n;i++)
{
cin>>a>>b;
p[i]=make_pair(a,b);
}
for(int i=;i<=n;i++)
{
for(int j=i;j<=n;j++)
{
if(i==j)
map[i][j]=;
map[j][i]=map[i][j]=dis(p[i],p[j]);
}
}
cout<<"Scenario #"<<t<<endl;
floyd();
t++;
}
return ;
}

poj3660Cow Contest(判断绝对顺序)题目意思是给出牛的数量n和牛之间的胜负关系m,让你求出可确定排名的牛的数量

列如:输入:

5 5(5头牛  5关系)
4 3(牛4可打败牛3)

4 2(牛4可打败牛2)
3 2(牛3可打败牛2)
1 2(牛1可打败牛2)
2 5(牛2可打败牛5)

输出:2(牛1和牛5可确定排名)

代码:

#include <iostream>
#include <string.h>
#include <algorithm>
#include <stdio.h>
using namespace std;
const int MAXN=;
int win[MAXN][MAXN];
int main()
{
int n,m;
while(scanf("%d%d",&n,&m)!=EOF)
{
memset(win,,sizeof(win));
int u,v;
while(m--)//m种关系
{
scanf("%d%d",&u,&v);
win[u][v]=; //u可以直接打败v
}
for(int k=;k<=n;k++) //i间接打败j
for(int i=;i<=n;i++)
for(int j=;j<=n;j++)
if(win[i][k]&&win[k][j])
win[i][j]=;
int ans=;//记录有几头牛可以确定排名
int j;
for(int i=;i<=n;i++)
{
for(j=;j<=n;j++)//与所有牛都有关系就能够确定绝对顺序
{
if(i==j)
continue;
if(win[i][j]==&&win[j][i]==)
break;//关系不确定
}
if(j>n)
ans++;
}
printf("%d\n",ans);
}
return ;
}

POJ 2253 Frogger ,poj3660Cow Contest(判断绝对顺序)(最短路,floyed)的更多相关文章

  1. poj 2253 Frogger (最长路中的最短路)

    链接:poj 2253 题意:给出青蛙A,B和若干石头的坐标,现青蛙A想到青蛙B那,A可通过随意石头到达B, 问从A到B多条路径中的最长边中的最短距离 分析:这题是最短路的变形,曾经求的是路径总长的最 ...

  2. 最短路(Floyd_Warshall) POJ 2253 Frogger

    题目传送门 /* 最短路:Floyd算法模板题 */ #include <cstdio> #include <iostream> #include <algorithm& ...

  3. POJ. 2253 Frogger (Dijkstra )

    POJ. 2253 Frogger (Dijkstra ) 题意分析 首先给出n个点的坐标,其中第一个点的坐标为青蛙1的坐标,第二个点的坐标为青蛙2的坐标.给出的n个点,两两双向互通,求出由1到2可行 ...

  4. POJ 2253 Frogger(dijkstra 最短路

    POJ 2253 Frogger Freddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fion ...

  5. POJ 2253 Frogger

    题目链接:http://poj.org/problem?id=2253 Frogger Time Limit: 1000MS   Memory Limit: 65536K Total Submissi ...

  6. poj 2253 Frogger 最小瓶颈路(变形的最小生成树 prim算法解决(需要很好的理解prim))

    传送门: http://poj.org/problem?id=2253 Frogger Time Limit: 1000MS   Memory Limit: 65536K Total Submissi ...

  7. poj 2253 Frogger (dijkstra最短路)

    题目链接:http://poj.org/problem?id=2253 Frogger Time Limit: 1000MS   Memory Limit: 65536K Total Submissi ...

  8. POJ 2253 ——Frogger——————【最短路、Dijkstra、最长边最小化】

    Frogger Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Stat ...

  9. POJ 2253 Frogger Floyd

    原题链接:http://poj.org/problem?id=2253 Frogger Time Limit: 1000MS   Memory Limit: 65536K Total Submissi ...

随机推荐

  1. java调.NET webapi时间戳报错问题

    JAVA时间戳长度是13位,如:1294890876859 PHP .NET时间戳长度是10位, 如:1294890859 主要最后三位的不同,JAVA时间戳在.NETPHP中使用,去掉后三位,如:1 ...

  2. vCenter Server Heartbeat

    1.简介 vCenter Server Heartbeat为VMware vCenter Server提供关键任务高可用性,保护虚拟基础架构免受硬件.网络.配置等的影响,基于Windows的服务,可为 ...

  3. .NET基础 (02).NET运行机制

    .NET运行机制1 .NET程序被编译成什么形式的代码2 JIT是如何工作的3 简述程序集的加载机制4 如何配置程序集的版本策略 1 .NET程序被编译成什么形式的代码 .NET程序在编写完成后,会经 ...

  4. spring mvc 入门程序

    入门程序 1.环境准备 myeclipse Spring jar 2.前端控制器设置 (web.xml) 所有的*.action请求通过org.springframework.web.servlet. ...

  5. 【Android学习】Service&Boradcast初步

    Service初步 掌握Service概念 掌握Service分类 Service开发能力具备 了解Service和intentService类的区别 重点难点 StartService和BoundS ...

  6. jquery插件中(function ( $, window, document, undefined )的作用

    在jquery插件中我们经常看到以下这段代码 ;(function ( $, window, document, undefined ){ //函数体内具体代码 })(jQuery, window,d ...

  7. CSS与jQuery补漏

    1.position属性 这个属性定义建立元素布局所用的定位机制.任何元素都可以定位,不过绝对或固定元素会生成一个块级框,而不论该元素本身是什么类型.相对定位元素会相对于它在正常流中的默认位置偏移. ...

  8. jQuery获取各种input输入框的值

    1.获取一组radio单选框的值(name属性为一组的radio的name属性) var q1 = $("input[name=element_name]:checked").va ...

  9. EF6使用Mysql的一些问题(code first)

    首先,添加nuget Mysql.Data ; Mysql.Data.Entity ; 添加配置文件connectionStrings <add name="conn" co ...

  10. DEV 之 有些控件不允许拖动。

    DEV 之 有些控件不允许拖动.  设置一个参数即可解决问题