美文网首页
PAT 甲级1128. N Queens Puzzle (20)

PAT 甲级1128. N Queens Puzzle (20)

作者: 动感新势力fan | 来源:发表于2018-05-24 22:11 被阅读14次
#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 flag = true;
        for(int j = 0; j < n; j++){
            cin >> v[j];
            for(int t = 0; t < j; t++){
                if(v[t] == v[j] || abs(j - t) == abs(v[j] - v[t])){ flag = false; break;}
            }
        }
    cout << (flag == true ? "YES\n" : "NO\n");
    }
    return 0;
}

相关文章

网友评论

      本文标题:PAT 甲级1128. N Queens Puzzle (20)

      本文链接:https://www.haomeiwen.com/subject/vteejftx.html