1128 N Queens Puzzle(20 分)

2018-08-25  本文已影响0人  zjh3029
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<algorithm>
#include <set>
using namespace std;


int main()
{
    int M,N,a;
    vector<int> v;

    cin >> M;
    for (int i = 0; i < M; i++)
    {
        cin >> N;
        v.clear();
        for (int j = 0; j < N; j++)
        {
            cin >> a;
            v.push_back(a);
        }
        bool flag = false;
        for (int i = 0; i < v.size(); i++)
        {
            for (int j = i+1; j < v.size(); j++)
            {
                if (abs(i - j) == abs(v[i] - v[j]) || abs(v[i]-v[j])==0)
                {
                    cout << "NO" << endl;
                    //cout << "i=" << i << "  j=" << j << endl;
                    flag = true;
                    break;
                }
            }
            if (flag==true) break;
        }
        if (flag == false)  cout << "YES" << endl;
    }
    system("pause");
    return 0;
}
上一篇下一篇

猜你喜欢

热点阅读