美文网首页
1128 N Queens Puzzle(20 分)

1128 N Queens Puzzle(20 分)

作者: zjh3029 | 来源:发表于2018-08-25 16:34 被阅读0次
    #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;
    }
    

    相关文章

      网友评论

          本文标题:1128 N Queens Puzzle(20 分)

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