コード例 #1
0
int solve_nsnipers(int *battlefield, int n){
	if (battlefield == NULL || n < 4) return 0;
	flag = false;
	int k = 0;
	arr1 = (int *)calloc(n, sizeof(int));
	b = (int *)calloc(n, sizeof(int));
	sniper(0, n);
	for (int i = 0; i < n; i++)
	{
		*((battlefield + i*n) + b[i]) = 1;
	}
	return 1;
}
コード例 #2
0
int sniper(int *board, int col, int N)
{
	int i;
	if (col >= N)
		return 1;
	for (i = 0; i < N; i++)
	{
		if (isSafe(board, i, col, N))
		{
			board[(i*N)+col] = 1;
			if (sniper(board, col + 1, N))
				return 1;
			board[(i*N)+col] = 0;
		}
	}
	return 0;
}
コード例 #3
0
void sniper(int k, int n)
{

	for (int i = 0; i < n; i++)
	{
		if (path(k, i, n))
		{
			arr1[k] = i;
			if (k == n - 1){
				flag = true;
				for (i = 0; i < n; i++)
				{
					b[i] = arr1[i];
				}
				return;
			}

			if (flag == false)
				sniper(k + 1, n);

		}
	}

}
コード例 #4
0
int solve_nsnipers(int *battlefield, int n){
	int *board, count = 0;
	if ((battlefield == NULL) || (n <= 3))
		return 0;
	return sniper(battlefield, 0, n);
}