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 |
Re:Runtime Error 为什么呀?In Reply To:Runtime Error 为什么呀? Posted by:liuqingfang at 2012-07-10 21:21:53 > #include <iostream> > using namespace std; > > typedef struct > { > int x; > int y; > char what; > int yNo; > }MyStruct; > > MyStruct Conflict[20]; > > > int main() > { > int width,hight,i,j; > char start[7],ends[6]; > char c; > > while(1) > { > cin>>start; > cin>>width; > cin>>hight; > > int m =0; > for(i =0;i<hight;i++) > for(j =0;j<width;j++) > { > cin>>c; > if(c!='E') > { > Conflict[m].what=c; > Conflict[m].y=i; > Conflict[m++].x=j; > } > } > cin>>ends; > > int answer=m; > > int allCans=1; > for(i = 0;i <m;i++) > allCans *=2; > > for(i = 0;i<allCans;i++) > { > int temp =i; > > int quchu =0; > > for(j=0;j<m;j++) > { > Conflict[j].yNo=temp%2; > temp /= 2; > if(Conflict[j].yNo==0) quchu++; > } > > > > if(quchu>=answer) > continue; > > int isOK =1; > > for(int x = 0;x<m;x++) > { > if(Conflict[x].yNo==0) > continue; > > for(int y = x+1;y<m;y++) > { > if(Conflict[y].yNo==0) > continue; > if(Conflict[y].what=='K'||Conflict[x].what=='K') > { > if(abs(Conflict[y].x-Conflict[x].x)<=1&&abs(Conflict[y].y-Conflict[x].y)<=1) > { > isOK = 0; > break; > } > } > if(Conflict[y].what=='Q'||Conflict[x].what=='Q') > { > if(Conflict[y].x==Conflict[x].x ||Conflict[y].y==Conflict[x].y||abs(Conflict[y].y-Conflict[x].y)==abs(Conflict[y].x-Conflict[x].x)) > { > isOK = 0; > break; > } > } > if(Conflict[y].what=='R'||Conflict[x].what=='R') > { > if(Conflict[y].x==Conflict[x].x ||Conflict[y].y==Conflict[x].y) > { > isOK = 0; > break; > } > } > if(Conflict[y].what=='B'||Conflict[x].what=='B') > { > if(abs(Conflict[y].y-Conflict[x].y)==abs(Conflict[y].x-Conflict[x].x)) > { > isOK = 0; > break; > } > } > if(Conflict[y].what=='N'||Conflict[x].what=='N') > { > if(abs(Conflict[y].y-Conflict[x].y)==1&&abs(Conflict[y].x-Conflict[x].x)==2||abs(Conflict[y].y-Conflict[x].y)==2&&abs(Conflict[y].x-Conflict[x].x)==1) > { > isOK = 0; > break; > } > } > } > if(isOK==0) > break; > } > if(isOK) > answer = quchu; > > } > > cout<<"Minimum Number of Pieces to be removed: "<<answer<<endl; > > } > return 0; > } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator