Title Link: Hdu 4849 wow! Such city!
The main topic: There are N cities, given the formula to calculate the distance between 22 cities, and then 0 to 1~n-1 City, the shortest path to die the minimum value m.
Problem-solving ideas: First, according to the formula to find the distance C matrix, pay attention to the middle of 3 times may explode long long, and then use the bare Dijstra algorithm to find the shortest way.
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace STD;typedef Long LongllConst intMaxd =1005;Const intMAXN = Maxd * MAXD;Constll INF =0x3f3f3f3f3f3f3f3f;intN, M;ll X[MAXN], Y[MAXN], Z[maxn];ll C[maxd][maxd], D[maxd];voidInit_distant () { for(inti =1; I < n * N; i++) {if(I >=2) {X[i] = (12345+ x[i-1] *23456+ x[i-2] *34567+ (x[i-1] * x[i-2] %5837501) *45678) %5837501; Y[i] = (56789+ y[i-1] *67890+ y[i-2] *78901+ (y[i-1] * y[i-2] %9860381) *89012) %9860381; } Z[i] = (X[i] *90123+ y[i])%8475871+1; } for(inti =0; i < N; i++) { for(intj =0; J < N; J + +) {if(i = = j) C[I][J] =0;ElseC[I][J] = Z[i*n+j]; }}}ll Dijstra () {intV[maxd];memset(V,0,sizeof(v)); for(inti =0; i < N; i++) D[i] = INF; d[0] =0; ll ans = INF; for(inti =0; i < N; i++) {intU =0; ll dis = INF; for(intj =0; J < N; J + +) {if(D[j] < dis && v[j] = =0) {u = j; dis = d[j]; }} V[u] =1;if(D[u]% m < ans && u) ans = d[u]% m; for(intj =0; J < N; J + +) {if(D[u] + c[u][j] < D[j]) d[j] = D[u] + c[u][j]; } }returnAns;}intMain () { while(scanf("%d%d%lld%lld%lld%lld", &n, &m, &x[0], &x[1], &y[0], &y[1]) ==6) {init_distant ();printf("%lld\n", Dijstra ()); }/ * while (CIN >> N >> M >> x[0] >> x[1] >> y[0] >> y[1]) {init_distant ( ); cout << Dijstra () << Endl; } */ return 0;}