Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
哪位大牛帮忙说一下9月9号的月赛G题(3377)的思路,我思路貌似和Contest Report中一样,很郁闷!(附了我的源代码)附我的源代码: #include <stdio.h> #define N 1000005 typedef struct { long direction; long point; }node; long str[2][N] = {0}; long sum[N] = {0}; long over[N] = {0}; long l[N] = {0}; long main() { long n,i,t; node start,end;/*定义起点终点结构*/ scanf("%ld",&n);/*输入当前规模*/ while(n) { scanf("%ld %ld %ld %ld",&start.direction,&start.point,&end.direction,&end.point);/*输入起点终点*/ for(i = 0;i < n;i ++) scanf("%ld",&str[0][i]);/*输入北面的码头间需要的时间*/ for(i = 0;i <= n;i ++) scanf("%ld",&over[i]);/*输入自西向东的过河所需要的时间*/ for(i = 0;i < n;i ++) scanf("%ld",&str[1][i]);/*输入南面的码头间需要的时间*/ if(start.point > end.point)/*如果起点在终点的东面,交换起点和终点*/ { t = start.direction; start.direction = end.direction; end.direction = t; t = start.point; start.point = end.point; end.point = t; } for(i = n - 1;;i --)/*将终点那条边替换为最短的*/ { if(i < end.point) break; if(over[i] > over[i + 1] + str[0][i] + str[1][i]) over[i] = over[i + 1] + str[0][i] + str[1][i]; } for(i = 1;;i ++)/*将起点那条边替换为最短的*/ { if(i > start.point) break; if(over[i] > over[i - 1] + str[0][i - 1] + str[1][i - 1]) over[i] = over[i - 1] + str[0][i - 1] + str[1][i - 1]; } i = start.point; l[i] = over[i];/*l[i]表示从起点开始到对岸的第i个码头所要的最短时间*/ sum[i] = 0;/*sum[i]表示从起点开始到起点同岸的第i个码头所要的最短时间*/ for(i = i + 1;i <= end.point;i ++)/*动态规划求sum[i],l[i]*/ { l[i] = l[i - 1] + str[end.direction][i - 1]; if(sum[i - 1] + str[start.direction][i - 1]+ over[i] < l[i]) l[i] = sum[i - 1] + str[start.direction][i - 1]+ over[i]; sum[i] = sum[i - 1] + str[start.direction][i - 1]; if(l[i - 1] + str[end.direction][i - 1] + over[i] < sum[i]) sum[i] = l[i - 1] + str[end.direction][i - 1] + over[i]; } printf("%ld\n",l[end.point]); scanf("%ld",&n); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator