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 |
这两个程序有什么不同吗,为什么一个AC,一个就WA了呢,求指教!!首先写的WA了: #include <stdio.h> #include <stdlib.h> #include <string.h> int main() { int n, t, maxx, pos; int r[1006]={0}; int i, j, x, y, s; while (scanf("%d%d",&n,&t) != EOF) { for (i=0; i<n; i++) scanf("%d",&r[i]); s = 0; pos = -1; while (t--) { x = s % (n-1); y = s / (n-1); i = 0; while (x) { if (i != pos) { r[i] += 1; x--; } i++; } maxx = -1; for (i=0; i<n ;i++) { r[i] += y; if(r[i] > maxx) { maxx = r[i]; pos = i; } } printf("%d\n",pos+1); s = r[pos]; r[pos] = 0; } } return 0; } 又写了一个,AC了: #include <stdio.h> int main() { int r[1006]={0}; int n, t, maxx, pos; int x, y, i, j; while (scanf("%d%d",&n ,&t) != EOF) { for (i = 0; i < n; i++) scanf("%d", &r[i]); while (t--) { maxx = -1; for (i = 0; i < n ; i++) if (r[i] > maxx) { maxx = r[i]; pos = i; } printf("%d\n",pos+1); x = r[pos] % (n-1); y = r[pos] / (n-1); i = 0; while (x) { if(i != pos) { r[i] += 1; x--; } i++; } for (i = 0 ; i < n ; i++) r[i] += y; r[pos] = 0; } } return 0; } 请高手指教一下,为什么啊? Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator