标签:res rip code namespace key this less while --
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 1384 Accepted Submission(s): 597
#include <bits/stdc++.h> #define inf 0x3f3f3f3f #define met(a,b) memset(a,b,sizeof a) #define pb push_back #define mp make_pair #define rep(i,l,r) for(int i=(l);i<=(r);++i) #define inf 0x3f3f3f3f using namespace std; typedef long long ll; const int N = 6e4+50;; const int M = 255; const int mod = 19260817; const int mo=123; const double pi= acos(-1.0); typedef pair<int,int>pii; typedef pair<ll,int>P; int n,s; ll dis[6][N]; ll k,edg[6][6],m,ans; void dij(int s){ priority_queue<P,vector<P>,greater<P> >q; for(int i=0;i<4;i++){ for(int j=0;j<=m;j++){ dis[i][j]=1e18; } } q.push(P(0LL,s)); while(!q.empty()){ ll w=q.top().first; int u=q.top().second; q.pop(); if(u==s){ if(w<k){ ans=min(ans,w+((k-w-1)/m+1)*m); } else ans=min(ans,w); } for(int i=0;i<4;i++){ if(!edg[u][i])continue; ll d=w+edg[u][i]; if(dis[i][d%m]>d){ dis[i][d%m]=d; q.push(P(d,i)); } } } } int main(){ int T; scanf("%d",&T); while(T--){ ans=1e18; scanf("%lld",&k); for(int i=0;i<4;i++){ scanf("%lld",&edg[i][(i+1)%4]); edg[(i+1)%4][i]=edg[i][(i+1)%4]; } m=2*min(edg[1][0],edg[1][2]); ans=((k-1)/m+1)*m; dij(1); printf("%lld\n",ans); } return 0; }
HDU 6071 Lazy Running (同余最短路 dij)
标签:res rip code namespace key this less while --
原文地址:http://www.cnblogs.com/jianrenfang/p/7599448.html