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 |
各位大牛们,看看我这是怎么错的,提供几组数据吧#include <iostream> #include <memory> using namespace std; int t[1005]; char s[1005]; //得到数据i的上一个操作是什么 void output(int x,int data); int main() { bool exist[1005]; //记录i这个数据是否已经产生 int str[1005],str0[1005],n,k,m,data,i,j; //得到结果i的上一个数据是什么 while(scanf("%d %d %d",&n,&k,&m)==3&&!(n==0&&k==0&&m==0)) { int num=0,length=0,length0=1; memset(exist,0,sizeof(exist)); data=((n+1)+k*1000)%k; str0[0] = (n+k*1000)%k; exist[str0[0]]=1; while(1) { int d; num++; for(i=0;i<length0;i++) { d=(str0[i]+m)%k; if(exist[d]==0) { exist[d]=1; str[length++]=d; s[d]='+'; t[d]=str0[i]; } if(d==data) break; d=(str0[i]-m+k*1000)%k; if(exist[d]==0) { exist[d]=1; str[length++]=d; s[d]='-'; t[d]=str0[i]; } if(d==data) break; d=(str0[i]*m)%k; if(exist[d]==0) { exist[d]=1; str[length++]=d; s[d]='*'; t[d]=str0[i]; } if(d==data) break; d=(str0[i]%m)%k; if(exist[d]==0) { exist[d]=1; str[length++]=d; s[d]='%'; t[d]=str0[i]; } if(d==data) break; //??? } if(d==data) { printf("%d\n",num); output((n+k*1000)%k,data); printf("\n"); break; } else { if(length==0) { printf("0\n"); break; } for(i=0;i<length;i++) str0[i]=str[i]; length0=length; length=0; } } } return 0; } void output(int x,int data) { if(x!=data) { output(x,t[data]); printf("%c",s[data]); } else return ; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator