看板 C_and_CPP 關於我們 聯絡資訊
WA... 麻煩神人給我指教 以下是程式碼,謝謝 #include <stdio.h> #include <limits.h> #define MAX_L 20 /* max lands */ long long int min(long long int a,long long int b) { if( a > b ) return b; else return a; } int main() { /*freopen("in", "r", stdin); freopen("out", "w", stdout); //*/ long long int lands[MAX_L][MAX_L]; int i, j, k, l; int counter = 0; /* initialize */ for(i=MAX_L-1; i>=0; i--) for(j=MAX_L-1; j>=0; j--) lands[i][j] = LONG_MAX; while( scanf("%d", &k)!=EOF ) { for(j=k-1; j>=0; j--) { scanf("%d", &l); lands[0][l-1] = lands[l-1][0] = 1; } for(i=MAX_L-3; i>=0; i--) { scanf("%d", &k); for(j=k-1; j>=0; j--) { scanf("%d", &l); lands[MAX_L-2-i][l-1] = lands[l-1][MAX_L-2-i] = 1; } } /* Floyd-Warshall */ for(k=MAX_L-1; k>=0; k--) for(i=MAX_L-1; i>=0; i--) for(j=MAX_L-1; j>=0; j--) lands[i][j] = min( lands[i][j], lands[i][k]+lands[k][j] ); /* Floyd-Warshall */ if(counter > 0) printf("\n"); printf("Test Set #%d\n", ++counter); scanf("%d", &k); for(i=k-1; i>=0; i--) { scanf("%d%d", &j, &l); printf("%2d to %2d: %lld\n", j, l, lands[j-1][l-1]); } /* initialize */ for(i=MAX_L-1; i>=0; i--) for(j=MAX_L-1; j>=0; j--) lands[i][j] = LONG_MAX; } return 0; } -- Johannes Krauser II 強暴!強暴!強暴!強暴!強暴!強暴! GO TO D.M.C ◥◣ ◥◣ 強暴!強暴!強暴!強暴!強暴! ▄▂▁▂▃▅▆▅ ▃▄ ∵ ∵ ▃▄▃ シ ▋▊▍ φjeans1020 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.114.210.45
ledia:LONG_MAX 不會相加 overflow 嗎? 03/25 10:50
JLR521:我改成10000還是得到WA 03/25 11:20
JLR521:而且我已經把lands宣告成long long int了,還會overflow喔? 03/25 11:21
ledia:LONG_MAX 有些地方是 8 byte integer max 03/25 11:29
ledia:演算法我沒仔細 check, 但題目說每個 set 要一個空行吧? 03/25 11:29
JLR521:if(counter > 0)printf("\n");就是除了第一筆測資 03/25 11:44
JLR521:開頭都空一行 03/25 11:45
ledia:但是他要的並不是除了第一筆測資開頭都空一行呀 @@||||| 03/25 17:33
ledia:而是每個 set 空一行吧 @@|||| 03/25 17:34
JLR521:ledia老大.......謝謝!!!! 03/25 17:50
JLR521:我是智障................. 03/25 17:50
ledia:沒關係... 我懂... 這種事睡一覺起來會好一點 XDXD 03/25 20:11