1128 N Queens Puzzle(20 分)

#include
#include
#include
#include
#include
#include 
using namespace std;


int main()
{
    int M,N,a;
    vector 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;
}

你可能感兴趣的:(1128 N Queens Puzzle(20 分))