游隼烈天 游隼烈天
关注数: 3 粉丝数: 12 发帖数: 530 关注贴吧数: 6
求教ZOJ 1082 一道简单的最短路径问题,可就是一直WA,题目是 http://tieba.baidu.com/mo/q/checkurl?url=http%3A%2F%2F210.32.0.220%2Fonlinejudge%2FshowProblem.do%3FproblemId%3D82&urlrefer=1f3487ef60fcfcb54f202bcda6a29cee 下面是我写的一段程序 结果与例题的结果一样,求教高手说下程序哪里错了,还是思想就错了 #include<stdio.h>         #define MAX 100000 int g[256][256],q[256][256],max[256]; int n,re; int alg() { int ma=MAX; int i,j,k,x,m; re=0; for(i=1;i<=n;i++) { if(g[i][0]>=MAX) break; for(x=1;x<=n;x++) { for(m=1;m<=n;m++) { if(i!=m) { if(g[i][m]>=MAX&&g[g[i][0]][m]<MAX) g[i][m]=g[g[i][0]][m]+g[i][g[i][0]]; else if(g[i][m]<MAX&&g[g[i][0]][m]<MAX) { if(g[g[i][0]][m]+g[i][g[i][0]]<g[i][m]) g[i][m]=g[g[i][0]][m]+g[i][g[i][0]]; } } } q[i][g[i][0]]=1; for(k=1;k<=n;k++) if((g[i][k]<g[i][g[i][0]]||q[i][g[i][0]])&&!q[i][k]&&i!=k) g[i][0]=k; if(q[i][g[i][0]]) break; } for(j=1;j<=n;j++) { if(i!=j) { if((g[i][j]>max[i]||max[i]>=MAX)&&g[i][j]<MAX) max[i]=g[i][j]; if(g[i][j]>=MAX) { max[i]=MAX; break; } } } } for(i=1;i<=n;i++) if((max[i]<ma)&&max[i]<MAX) { ma=max[i]; re=i; } return ma; } int main() { int o,w,x,c; int ma; int i,j; while(scanf("%d",&n)==1&&n) { for(i=0;i<256;i++) { max[i]=MAX; for(j=0;j<256;j++) { g[i][j]=MAX; q[i][j]=0;                 } } for(i=1;i<=n;i++) { scanf("%d",&o); for(w=1;w<=o;w++) { scanf("%d%d",&x,&c); g[i][x]=c; } } for(i=1;i<=n;i++) { for(j=1;j<=n;j++) { if((g[i][j]<g[i][0]||g[i][0]>=MAX)&&g[i][j]<MAX&&i!=j) g[i][0]=j; } } ma=alg(); if(n==1) printf("%d 0\n",n); else if(ma<MAX) printf("%d %d\n",re,ma); else printf("disjoint\n"); } }
浙大ACM1205 http://210.32.0.220/show_problem.php?pid=1205Martian Addition--------------------------------------------------------------------------------Time limit: 1 Seconds Memory limit: 32768K Total Submit: 7942 Accepted Submit: 2299 -------------------------------------------------------------------------------- In the 22nd Century, scientists have discovered intelligent residents live on the Mars. Martians are very fond of mathematics. Every year, they would hold an Arithmetic Contest on Mars (ACM). The task of the contest is to calculate the sum of two 100-digit numbers, and the winner is the one who uses least time. This year they also invite people on Earth to join the contest. As the only delegate of Earth, you're sent to Mars to demonstrate the power of mankind. Fortunately you have taken your laptop computer with you which can help you do the job quickly. Now the remaining problem is only to write a short program to calculate the sum of 2 given numbers. However, before you begin to program, you remember that the Martians use a 20-based number system as they usually have 20 fingers. Input:You're given several pairs of Martian numbers, each number on a line. Martian number consists of digits from 0 to 9, and lower case letters from a to j (lower case letters starting from a to present 10, 11, ..., 19). The length of the given number is never greater than 100.Output:For each pair of numbers, write the sum of the 2 numbers in a single line.Sample Input:1234567890abcdefghij99999jjjjj9999900001Sample Output:bdfi02467jiiiij00000
很懵很懵 ProblemThe president of Gridland has hired you to design a program that calculates the length of the shortest traveling-salesman tour for the towns in the country. In Gridland, there is one town at each of the points of a rectangular grid. Roads run from every town in the directions North, Northwest, West, Southwest, South, Southeast, East, and Northeast, provided that there is a neighbouring town in that direction. The distance between neighbouring towns in directions North–South or East–West is 1 unit. The length of the roads is measured by the Euclidean distance. For example, Figure 7 shows 2 × 3-Gridland, i.e., a rectangular grid of dimensions 2 by 3. In 2 × 3-Gridland, the shortest tour has length 6. Figure 7: A traveling-salesman tour in 2 × 3-Gridland.InputThe first line contains the number of scenarios.For each scenario, the grid dimensions m and n will be given as two integer numbers in a single line, separated by a single blank, satisfying 1 < m < 50 and 1 < n < 50.OutputThe output for each scenario begins with a line containing "Scenario #i:", where i is the number of the scenario starting at 1. In the next line, print the length of the shortest traveling-salesman tour rounded to two decimal digits. The output for every scenario ends with a blank line.Sample Input22 22 3Sample OutputScenario #1:4.00Scenario #2:6.00 这是题目,我看了N久N久才明白点,然后写了#include #include main(){int i,n,h,l;float sum;scanf("%d",&n);for(i=1;i<=n;i++){ scanf("%d%d",&h,&l); if(h%2==0)sum=h*l-1+h-1;else sum=h*l-1+(sqrt(2))*(l>h?(h-1):(l-1))+fabs(l-h);printf("Scenario #%d:\n",i);printf("%.2f\n",sum);printf("\n");}}改了N次N次还是错,没辙了,求救现在才懂得英语的重要性啊
1 下一页