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

想哭的冲动 帮帮我 输入4 4咋会变成这样

Posted by vince4053040 at 2010-02-01 21:03:48 on Problem 2488
#include<iostream>
using namespace std;

#define MAX 50
int mark[MAX][MAX];
int knight_hang[MAX];
int knight_lie[MAX];
int x, y;
void dfs(int i, int j, int p, int q)
{
	if(i < 0 || i >= p || j < 0 || j >= q || mark[i][j] == 1)
		return ;
	mark[i][j] = 1;
	//printf("%c%d", j + 65, i + 1);
	knight_hang[x ++] = i;
	knight_lie[y ++] = j;
	dfs(i + 2, j - 1, p, q);                   //天呐 字典顺序 不想活了。。。。
	dfs(i - 2, j - 1, p, q);
	dfs(i + 1, j - 2, p, q);
	dfs(i - 1, j - 2, p, q);
	dfs(i + 2, j + 1, p, q);	
	dfs(i - 2, j + 1, p, q);
	dfs(i + 1, j + 2, p, q);
	dfs(i - 1, j + 2, p, q);	
}

int main()
{
	int i, j, p, q;
	int N;
	cin >> N;
	for(j = 1; j <= N; j ++) {
		memset(mark, 0, sizeof(mark));
		memset(knight_hang, 0, sizeof(knight_hang));
		memset(knight_lie, 0, sizeof(knight_lie));
		x = y = 0;
		cin >> p >> q;
		dfs(0, 0, p, q);
		cout << "Scenario #" << j << ":" << endl;
		//cout << x << endl;
		if(x == p * q) 
			for(i = 0; i < x; i ++) {
				printf("%c", knight_lie[i] + 65);
				printf("%d", knight_hang[i] + 1);
			}
		else
			cout << "impossible";
		cout << endl;
		cout << 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