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

求大神帮忙看下哪里错了【样例都没过

Posted by abcdefgzzzz at 2016-01-29 10:50:37 on Problem 2488
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
typedef pair<int, int>pii;
const int maxn = 70;
pii pa[maxn],dr[10];
int v[maxn][maxn];
int d[2]={1,-1}, r[2]={2,-2};
int n,p,q;
bool cmp(pii a, pii b)
{
    if(a.first == b.first) return a.second < b.second;
    else return a.first < b.first;
}
int dfs(int cnt, int a, int b)
{
    if(cnt == p*q){
        for(int i = 0; i < cnt; i++)
            cout<<(char)(pa[i].first+'A')<<pa[i].second+1;
        cout<<endl<<endl;
        return 1;
    }

       v[a][b] = 1;
       pa[cnt++] = make_pair(a, b);
        int k = 0, na, nb;
       for(int i = 0; i < 2; i++){
        for(int j = 0; j < 2; j++){
            na = a + d[i], nb =  b+ r[j];
            if(0 <= na && na < q && 0 <=  nb && nb < p)
                 if(!v[na][nb]) dr[k++] = make_pair(na, nb);
            na = a + r[i], nb = b+ d[j];
            if(0 <= na && na < q && 0 <=  nb && nb < p)
                 if(!v[na][nb]) dr[k++] = make_pair(na, nb);
            }
        }
        sort(dr, dr+k, cmp);
        for(int i = 0; i < k; i ++) {
            if(dfs(cnt, dr[i].first, dr[i].second)) {  v[dr[i].first][dr[i].second]=0;return 1;}

        }
    return 0;
}
int main (void)
{
   cin>>n;
   for(int i = 0; i < n; i++){
        memset(v, 0, sizeof(v));
        cin>>p>>q;
        cout<<"Scenario #"<<i+1<<":"<<endl;
        if(p*q == 1) cout<<"A1"<<endl<<endl;
       else  if(!dfs(0, 0, 0)) cout<<"impossible"<<endl<<endl;

   }
   return 0;
}

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