当前位置: 代码迷 >> 综合 >> PAT甲级题目1128 N Queens Puzzle
  详细解决方案

PAT甲级题目1128 N Queens Puzzle

热度:82   发布时间:2024-02-01 03:59:08.0

代码:

#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main() {int k, n;cin >> k;for (int i = 0; i < k; i++) {cin >> n;vector<int> v(n);bool result = true;for (int j = 0; j < n; j++) {cin >> v[j];for (int t = 0; t < j; t++) {if (v[j] == v[t] || abs(v[j]-v[t]) == abs(j-t)) {result = false;break;}}}cout << (result == true ? "YES\n" : "NO\n");}return 0;
}