PersonalCorpus 版 (精华区)
Your C++ program has solved Ok the problem 402 (M*A*S*H)
in 0.040 seconds using as much as 404 kbytes of virtual memory.
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#include <math.h>
#include <ctype.h>
void main()
{
#ifndef ONLINE_JUDGE
freopen("c:\\uva\\input402.txt","r",stdin);
freopen("c:\\uva\\output402.txt","w",stdout);
#endif
int p[51],x,n,i,j,k,tot=0,fin;
int c[20];
while (scanf("%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d\n",&n,
&x,&c[0],&c[1]
,&c[2],&c[3],&c[4],&c[5],&c[6],&c[7],&c[8],&c[9],&c[10],&c[11],
&c[12]
,&c[13],&c[14],&c[15],&c[16],&c[17],&c[18],&c[19])==22) {
tot++;
printf("Selection #%d\n",tot);
memset(p,0,sizeof(p));
j=0; fin=0;
while ((x<n)&&(j<20)) {
k=0;
for (i=0;i<n;i++) {
if (p[i]==0) k++;
if (k==c[j]) {
p[i]=1;
k=0;
x++;
if (x==n) break;
}
}
j++;
}
for (i=0;i<n;i++) if (p[i]==0) { printf("%d",i+1); i++; break;
}
for (;i<n;i++) if (p[i]==0) printf(" %d",i+1);
printf("\n\n");
}
}
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:2.389毫秒