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 |
样例过了但一直WA,求大神帮忙看看#include<iostream> #include<algorithm> #include<cstring> #include<queue> #include<vector> #define FAST ios::sync_with_stdio(0),cin.tie(0),cout.tie(0) #define endl "\n" using namespace std; typedef long long ll; int vis[30][30]; int n,m; int step; bool flag; vector<char>s; void DFS(int x, int y, int sum) { if(sum==n*m) { flag=1; return ; } vis[0][0]=1; int dx[8]={-1,1,-2,2,-2,2,-1,1}, dy[8]={-2,-2,-1,-1,1,1,2,2}; for(int i=0;i<8;i++) { int xx=x+dx[i], yy=y+dy[i]; if(xx>=0&&xx<n&&yy>=0&&yy<m&&!vis[xx][yy]) { vis[xx][yy]=1; s.push_back(char(xx+'A')); s.push_back(char(yy+'1')); DFS(xx,yy,sum+1); if(flag) return ; vis[xx][yy]=0; s.erase(s.end()-1); s.erase(s.end()-1); } } flag=0; return ; } int main() { FAST; int t; cin>>t; for(int i=1;i<=t;i++) { s.clear(); memset(vis,0,sizeof(vis)); s.push_back('A'); s.push_back('1'); flag=0; step=0; cin>>m>>n; cout<<"Scenario #"<<i<<":"<<endl; DFS(0,0,1); if(flag) { for(int i=0;i<s.size();i++) cout<<s[i]; cout<<endl; } else cout<<"impossible"<<endl; cout<<endl; } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator