| ||||||||||
| 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 | |||||||||
WA 大牛帮帮忙!!!#include <stdio.h>
int main()
{
int m, n, p[51], i, j, q, count, k, t, amount = 1;
while(scanf("%d %d", &m, &n)==2 && m){
for(i=1; i<= n; i++)
scanf("%d", &p[i]);
for(i=n; i>1; i--)
for(j=1; j<i; j++)
if(p[j]>p[j+1]){
t = p[j];
p[j] = p[j+1];
p[j+1] = t;
}
/* for(i=1; i<=n; i++)
printf("%d ", p[i]); */
q = m * n;
i = n;
count = 0;
while(i){
j = q - p[i];
if(j >= i)
break;
k = 1;
while((p[i]-p[i-1]) == 1){
k ++;
i --;
}
if(k-j > 0){
count += (k-j);
q = p[i] - 1;
i --;
}
else{
q = p[i] - (j-k);
i -= (j-k+1);
}
}
printf("Case %d: %d\n", amount++, count);
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator