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 |
presentation error!各位大牛帮我看看格式哪儿有问题啊,各位大牛 #include<stdio.h> #include<stdlib.h> #include<string.h> #define N 6 char WR[]="Can't be divided.\n"; char SC[]="Can be divided.\n"; int marbles[N]={0}; int marbleA[N]={0}; //分成AB两堆 int marbleB[N]={0}; int canBeChangeInB(int changeData) //回溯找是否能在B中找到组合的和等于changeData的大小,能则返回1,否则返回0 { int i; for(i=N-1;i>=0;--i) { if(marbleB[i]==0) { continue; } if(changeData==(i+1)) { return 1; } if(changeData-(i+1)>0) { --marbleB[i]; if(canBeChangeInB(changeData-(i+1))) return 1; ++marbleB[i]; } } return 0; } int TryMakeEven(int dev) { int i; int sum=0; for(i=N-1;i>=0;--i) { if(marbleA[i]==0) { continue; } if(canBeChangeInB((i+1)+dev)) { return 1; } } return 0; } void findAns(void) { int sum=0; int dev=0; int i; for(i=0;i<N;++i) { sum+=marbles[i]*(i+1); } if(sum%2==1) { printf(WR); return; } dev=sum/2; for(i=N-1;i>=0;--i) //计算A中还差多少 { for(;;) { if(marbles[i]==0) { break; } if(dev-(i+1)>0) { dev-=(i+1); ++marbleA[i]; --marbles[i]; } else if(dev-(i+1)==0) { printf(SC); return; } else { marbleB[i]=marbles[i]; break; } } } if(dev==0) { printf(SC); return; } //如果A端还不够,则用A中的某一个和B中的两个或者两个以上的调换 if( TryMakeEven(dev)) { printf(SC); return; } else { printf(WR); return; } } int main(void) { int i=1; while((scanf("%d %d %d %d %d %d",&marbles[0],&marbles[1],&marbles[2],&marbles[3],&marbles[4],&marbles[5]))!=EOF) { if(marbles[0]==0&&marbles[1]==0&&marbles[2]==0&&marbles[3]==0&&marbles[4]==0&&marbles[5]==0) return 1; printf("Collection #%d:\n",i); findAns(); memset(marbleA,0,N*sizeof(int)); memset(marbleB,0,N*sizeof(int)); ++i; } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator