HDU4849

一道简单的dijkstra 写了好久。。。了个大去  果然代码太弱了

#include<iostream>
#include<cstdlib>
#include<cstring>
#define INF 0x3f3f3f3f
#define MAXM 1009
using namespace std;
long long x[MAXM*MAXM],y[MAXM*MAXM],z[MAXM*MAXM];
long long s[MAXM],dist[MAXM];
long long map[MAXM][MAXM];
long long m,n;
int i,j,k;
void dijkstra(int v0){
for(i=0;i<n;i++){
dist[i]=map[v0][i];
s[i]=0;
}
s[v0]=1;dist[v0]=0;
for(i=0;i<n-1;i++){
long long min=INF;
long long u=v0;
for(j=0;j<n;j++){
if(!s[j]&&dist[j]<min){
u=j;min=dist[j];
}
}
s[u]=1;
for(k=0;k<n;k++){
if(!s[k] && map[u][k]<INF && dist[u]+map[u][k]<dist[k]){
dist[k]=dist[u]+map[u][k];
}
}
}
}
int main(){
while(cin>>n>>m){
cin>>x[0]>>x[1]>>y[0]>>y[1];
for(i=2;i<n*(n+1);i++){
x[i]=(12345+x[i-1]*23456+x[i-2]*34567+x[i-1]*x[i-2]*45678)%5837501;
y[i]=(56789+y[i-1]*67890+y[i-2]*78901+y[i-2]*y[i-1]*89012)%9860381;
z[i]=(x[i]*90123+y[i])%8475871+1;
}
z[0]=(x[0]*90123+y[0])%8475871+1;
z[1]=(x[1]*90123+y[1])%8475871+1;
for(i=0;i<n;i++){
for(j=0;j<n;j++){
if(i==j)
map[i][j]=0;
else 
map[i][j]=z[i*n+j];
}
}
long long c;
long long mint=INF;
dijkstra(0);
for(i=1;i<n;i++){
c=dist[i]%m;
if(c<mint)
mint=c;
}
cout<<mint<<endl;
}
return 0;
}

HDU4849,布布扣,bubuko.com

时间: 2024-12-30 09:17:35

HDU4849的相关文章

hdu4849 Wow! Such City!(最短路dijkstra)

转载请注明出处:http://blog.csdn.net/u012860063?viewmode=contents 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4849 Problem Description Doge, tired of being a popular image on internet, is considering moving to another city for a new way of life. In his co

HDU-4849 Wow! Such City! (单源最短路)

Problem Description Doge, tired of being a popular image on internet, is considering moving to another city for a new way of life. In his country there are N (2 ≤N≤ 1000) cities labeled 0 . . . N - 1. He is currently in city 0. Meanwhile, for each pa

hdu 4849 最短路 西安邀请赛 Wow! Such City!

http://acm.hdu.edu.cn/showproblem.php?pid=4849 会有很多奇怪的Wa的题,当初在西安就不知道为什么wa,昨晚做了,因为一些Sb错误也wa了很久,这会儿怎么写都会AC.... 收获: 1.还是基本都构思好在去敲代码,因为当时没过,昨晚心里有阴影,敲得很慢,而且最开始各种取模以防止漏掉,太保守了......以后一定先估算是不是需要取模防止TLE,当然时间够的话还是适当多取个模防止莫名其妙的错误.. 2.如果出错,注意参数是不是对的,最开始写好之后,因为m和

140725模拟赛总结

A:hdu4847    字符串匹配第一想法是KMP,写了好长时间结果还TLE了-_-||,实际上用个简单的枚举判断就能解决.因为待验证的字符串"doge"很小.写A题的时候还被输入卡了半天.Tips1:输入至文件结尾(eof)的常用方法:     while (cin>>a)        //最常用的     while (cin.getline(s,30))    //按行读入前30个字符.空格也读入    getline(cin,s)        //和getli