hdu 2145(迪杰斯特拉)
zz's Mysterious Present
Time Limit: 10000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 1652 Accepted Submission(s): 371
are m people in n cities, and they all want to attend the party which
hold by zz. They set out at the same time, and they all will choose the
best way they think, but due to someone take a ride, someone drive, and
someone take a taxi, they have different speed. Can you find out who
will get zz's mysterious present? The first one get the party will get
the present . If there are several people get at the same time, the one
who stay in the city which is farther from the city where is zz at
begin will get the present. If there are several people get at the same
time and the distance from the city he is at begin to the city where zz
is, the one who has the larger number will get the present.
first line: three integers n, m and k. m is the total number of the
people, and n is the total number of cities, and k is the number of the
way.(0<n<=300, 0<m<=n, 0<k<5000)
The second line to
the (k+1)th line: three integers a, b and c. There is a way from a to
b, and the length of the way is c.(0<a,b<=n, 0<c<=100)
The (k+2)th line: one integer p(0<p<=n), p is the city where zz is.
The (k+3)th line: m integers. the ith people is at the place p[i] at begin.(0<p[i]<=n)
The (k+4)th line: m integers. the speed of the ith people is speed[i];(0<speed[i]<=100)
All the ways are directed.
1 2 2
1 3 3
2 3 1
3
2
1
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <iostream>
#include <stdlib.h>
#include <math.h>
using namespace std;
const double eps = 1e-;
const int N = ;
const int INF = ;
int graph[N][N];
int p[N];
int speed[N];
int n,m,k;
int low[N];
bool vis[N];
double result[N];
int dijkstra(int s){
for(int i=;i<=n;i++){
low[i] = graph[s][i];
vis[i] = false;
}
low[s] = ;
vis[s] = true;
for(int i=;i<n;i++){
int Min = INF;
for(int j=;j<=n;j++){
if(Min>low[j]&&!vis[j]){
Min = low[j];
s = j;
}
}
vis[s] = true;
for(int j=;j<=n;j++){
if(low[j]>low[s]+graph[s][j]&&!vis[j]){
low[j] = low[s]+graph[s][j];
}
}
}
int flag = false;
///这里只要判断m个人就行了..
for(int i=;i<=m;i++){
if(low[p[i]]<INF) flag =true;
}
if(!flag) return INF;
int id = ;
for(int i=;i<=m;i++){
result[i] = low[p[i]]*1.0/speed[i];
if(result[id]>result[i]) id = i;
else if(fabs(result[id]-result[i])<eps){
if(low[p[id]]<=low[p[i]]) id = i;
}
}
return id;
}
int main()
{
while(scanf("%d%d%d",&n,&m,&k)!=EOF){
for(int i=;i<=n;i++){
for(int j=;j<=n;j++) {
if(i==j) graph[i][j] = ;
else graph[i][j] = INF;
}
}
for(int i=;i<k;i++){
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
graph[b][a] = min(c,graph[b][a]); ///全部反向
}
int s;
scanf("%d",&s);
for(int i=;i<=m;i++){
scanf("%d",&p[i]);
}
for(int i=;i<=m;i++){
scanf("%d",&speed[i]);
}
int id = dijkstra(s);
if(id>=INF) printf("No one\n");
else printf("%d\n",id);
}
}
hdu 2145(迪杰斯特拉)的更多相关文章
- hdu 1142(迪杰斯特拉+记忆化搜索)
A Walk Through the Forest Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Jav ...
- HDU 3339 In Action(迪杰斯特拉+01背包)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=3339 In Action Time Limit: 2000/1000 MS (Java/Others) ...
- HDU 2544最短路 (迪杰斯特拉算法)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=2544 最短路 Time Limit: 5000/1000 MS (Java/Others) Me ...
- HDU 3790(两种权值的迪杰斯特拉算法)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=3790 最短路径问题 Time Limit: 2000/1000 MS (Java/Others) ...
- HDU 1874畅通工程续(迪杰斯特拉算法)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1874 畅通工程续 Time Limit: 3000/1000 MS (Java/Others) ...
- hdu 1595 find the longest of the shortest(迪杰斯特拉,减去一条边,求最大最短路)
find the longest of the shortest Time Limit: 1000/5000 MS (Java/Others) Memory Limit: 32768/32768 ...
- hdu 3339 In Action(迪杰斯特拉+01背包)
In Action Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- HDU 2680 最短路 迪杰斯特拉算法 添加超级源点
Choose the best route Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- hdu 1874 畅通工程续(迪杰斯特拉优先队列,floyd,spfa)
畅通工程续 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Subm ...
随机推荐
- Codeforces Round #464 (Div. 2) E. Maximize!
题目链接:http://codeforces.com/contest/939/problem/E E. Maximize! time limit per test3 seconds memory li ...
- [项目2] 10mins
1.准备工作 M层:生成虚假数据 from django.db import models from faker import Factory # Create your models here. c ...
- 洛谷P1424小鱼的航程改进版
题目链接https://www.luogu.org/problemnew/show/P1424
- laravel5.2总结--关联关系
参考文章 http://laravelacademy.org/post/1095.html http://laravelacademy.org/post/1174.html http://d.lar ...
- 图说不为人知的IT传奇故事-2-IBM咬不动的胡桃
此系列文章为“图说不为人知的IT传奇故事”,各位大忙人可以在一分钟甚至几秒内了解把握整个内容,真可谓“大忙人的福利”呀!!希望各位IT界的朋友在钻研技术的同时,也能在文学.历史上有所把握.了解这些故事 ...
- ios开发学习笔记002-运算符
运算符 C语言有34种运算符,常见的有加减乘除. 算术运算符 1.加 10+2 2.减 20-2 3.乘 12*2 4.除 10/2 5.取余 10%3 = 1; 10%-3 = 1; -10%3 = ...
- 我对于js注入的理解
资料:http://blog.csdn.net/gisredevelopment/article/details/41778671 js注入就是在前端利用使用js的地方 在这其中注入你写的js代码 使 ...
- 理解机器为什么可以学习(三)---Theory of Generalization
前边讨论了我们介绍了成长函数和break point,现在继续讨论m是否成长很慢,是否能够取代M. 成长函数就是二分类的排列组合的数量.break point是第一个不能shatter(覆盖所有情形) ...
- Leetcode 558.四叉树交集
四叉树交集 四叉树是一种树数据,其中每个结点恰好有四个子结点:topLeft.topRight.bottomLeft 和 bottomRight.四叉树通常被用来划分一个二维空间,递归地将其细分为四个 ...
- 使用CORS解决flask前端页面跨域问题
from flask import Flask from flask_cors import CORS app = Flask(__name__) CORS(app) @app.route(" ...