PAT甲级1128题(八皇后)


1.题目介绍

1128

2.考察点,难度

模拟现实类,数组操作,难度易

3.解题代码

#include<cstdio>
#include<cmath>
using namespace std;

int main()
{
	int K, n;
	scanf("%d", &K);
	for (int i = 0; i < K; i++){
		bool issolution = true;
		scanf("%d", &n);
		int seq[n+1] = {0};
		for (int j = 1; j < n+1; j++) scanf("%d", seq+j);
		for (int j = 1; j < n+1 && issolution; j++){
			for (int k = 1; k < j; k++){
				if (seq[j] == seq[k] || abs(seq[j]-seq[k]) == abs(j-k)){
					issolution = false;
					break;
				}
			}
		}
		printf("%s", issolution ? "YES\n" : "NO\n");
	}
	return 0;
}

文章作者: Peyton
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 Peyton !
  目录