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<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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator