Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:提交了30次,才WA!【附】原因

Posted by leehom at 2009-03-27 11:47:34 on Problem 2488
In Reply To:Re:提交了30次,才WA!【附】原因 Posted by:spracle_hao at 2009-03-23 16:15:34
能帮我看看我错在哪里吗?
谢谢!!
#include<iostream>
#include <string.h>
using namespace std;
int n,c,r,sum=0;//c是列;r是行
int map[50][50];
int Xstep[8]={-2, -2, -1, -1,  1, 1,  2,  2};
int Ystep[8]={-1,  1, -2,  2, -2, 2,  -1, 1};
int arr[100][2]; 
bool ok;
void solve(int m,int n,int num)
{
   if(ok)
      return;
   int i,j;
   int a,b;
   arr[num][0]=m;arr[num][1]=n;
   if(num==sum)
   {
       ok=true;
       return;
   }
   for(i=0;i<8;i++)
   {
       a=m+Xstep[i];
       b=n+Ystep[i];
       
       if(a>0 && b>0 && a<=c && b<=r && map[a][b]==0)
       {
           map[a][b]=1;
           solve(a,b,num+1);
           map[a][b]=0;   
       }
       
   }     
}

int main()
{
    cin>>n;
    int x=1;
    while(n--)
    {
        memset(map,0,sizeof(map));//初始化 
        cin>>c>>r;
        sum=c*r;
        map[1][1]=1;
        solve(1,1,1);
        cout<<"Scenario #"<<x<<":"<<endl;
        x=x+1;
        if (ok)
        {
            for(int i=1;i<=sum ;i++)
                 printf("%c%c", arr[i][1] + 'A' - 1 , arr[i][0] + '0' ) ;
        }
        else
            cout<<"impossible";
        cout<<endl<<endl;
    }
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator