记录编号 121153 评测结果 AAAAAAAA
题目名称 最小密度路径 最终得分 100
用户昵称 GravatarHouJikan 是否通过 通过
代码语言 C++ 运行时间 0.079 s
提交时间 2014-09-18 16:03:08 内存使用 1.98 MiB
显示代码纯文本
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <list>
#include <vector>
#include <ctime>
#include <iterator>
#include <functional>
#define pritnf printf
#define scafn scanf
#define scnaf scanf
#define For(i,j,k) for(int i=(j);i<=(k);(i)++)
using namespace std;
typedef long long LL;
typedef unsigned int Uint; 
const int INF=0x7ffffff;
//==============struct declaration==============

//==============var declaration=================
const int MAXN=80;
int n,m;
int dist[MAXN][MAXN][MAXN];
//==============function declaration============

//==============main code=======================
int main()
{  
  string FileName="path";//程序名 
  string FloderName="COGS";//文件夹名 
  freopen((FileName+".in").c_str(),"r",stdin);
  freopen((FileName+".out").c_str(),"w",stdout);
#ifdef DEBUG  
  system(("cp C:\\Users\\Administrator\\Desktop\\"+FloderName+"\\standard.cpp C:\\Users\\Administrator\\Desktop\\"+FloderName+"\\submit.txt").c_str());
  clock_t Start_Time=clock();
#endif    
  scanf("%d%d",&n,&m);
  For(i,1,n)
    For(j,1,n)
      For(k,0,n)
        dist[i][j][k]=INF;
  For(i,1,m)
  {
    int s,e,t;
    scanf("%d%d%d",&s,&e,&t);
    dist[s][e][1]=min(dist[s][e][1],t);
  }   
  For(t,2,n)
    For(k,1,n)
      For(i,1,n)
        For(j,1,n)
        {
          if (dist[i][k][t-1]>100000||dist[k][j][1]>100000) continue;
          if (dist[i][j][t]>dist[i][k][t-1]+dist[k][j][1])
            dist[i][j][t]=dist[i][k][t-1]+dist[k][j][1];
        }
  int q;
  scanf("%d",&q);
  For(i,1,q)
  {
    int s,e;
    double res=1000000000;
    scanf("%d%d",&s,&e);
    For(j,0,n)
      if (dist[s][e][j]<=10000000&&double(dist[s][e][j])/double(j)<res)
        res=double (dist[s][e][j])/double(j);
    if (res<10000000.000)
      printf("%.3lf\n",res);
    else
      pritnf("OMG!\n");
  }
  
#ifdef DEBUG  
  clock_t End_Time=clock();
  printf("\n\nTime Used: %.4lf Ms\n",double(End_Time-Start_Time)/CLOCKS_PER_SEC);
#endif    
  return 0;
}
//================fuction code====================