PAT 甲级 1128. N Queens Puzzle (20) 【STL】
题目链接
https://www.patest.cn/contests/pat-a-practise/1128
思路 
可以 对每一个皇后 都判断一下 它的 行,列 ,左右对角线上 有没有皇后  
深搜解决
但是这样太麻烦
其实我们可以想到
要符合要求的摆放 
就是做到 每一行 每一列 每一条对角线 上 都是只有一个皇后的
每一行 就不用判断了
然后可以用 map 标记 该列 该对角线上 是否是已经有皇后的
如果已经有 那么就flag = 0
如果没有 就标记
然后 左对角线 上的特点就是 每个元素的 j - i 是相等的 
右对角线上的特点是 i + j  是相等的
AC代码
#include <cstdio>
#include <cstring>
#include <ctype.h>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <stack>
#include <set>
#include <numeric>
#include <sstream>
#include <iomanip>
#include <limits>
#define CLR(a) memset(a, 0, sizeof(a))
#define pb push_back
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair<string, int> psi;
typedef pair<string, string> pss;
const double PI = 3.14159265358979323846264338327;
const double E = exp(1);
const double eps = 1e-30;
const int INF = 0x3f3f3f3f;
const int maxn = 1e5 + 5;
const int MOD = 1e9 + 7;
int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        int n, num;
        int flag = 1;
        cin >> n;
        map <int, int> l, m, r;
        for (int i = 1; i <= n; i++)
        {
            scanf("%d", &num);
            if (m[num] || l[num - i] || r[num + i])
                flag = 0;
            m[num] = 1;
            l[num - i] = 1;
            r[num + i] = 1;
        }
        if (flag)
            printf("YES\n");
        else
            printf("NO\n");
    }
}
PAT 甲级 1128. N Queens Puzzle (20) 【STL】的更多相关文章
- PAT甲级 1128. N Queens Puzzle (20)
		1128. N Queens Puzzle (20) 时间限制 300 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue The & ... 
- PAT 甲级 1128 N Queens Puzzle
		https://pintia.cn/problem-sets/994805342720868352/problems/994805348915855360 The "eight queens ... 
- PAT甲级——A1128 N Queens Puzzle【20】
		The "eight queens puzzle" is the problem of placing eight chess queens on an 8 chessboard ... 
- PAT甲题题解-1128. N Queens Puzzle (20)-做了一个假的n皇后问题
		博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6789810.html特别不喜欢那些随便转载别人的原创文章又不给 ... 
- PAT 1128 N Queens Puzzle
		1128 N Queens Puzzle (20 分) The "eight queens puzzle" is the problem of placing eight ch ... 
- PAT 1128 N Queens Puzzle[对角线判断]
		1128 N Queens Puzzle(20 分) The "eight queens puzzle" is the problem of placing eight chess ... 
- PAT甲级:1152 Google Recruitment (20分)
		PAT甲级:1152 Google Recruitment (20分) 题干 In July 2004, Google posted on a giant billboard along Highwa ... 
- 1128 N Queens Puzzle (20 分)
		The "eight queens puzzle" is the problem of placing eight chess queens on an 8 chessboard ... 
- PAT 甲级 1041 Be Unique (20 分)
		1041 Be Unique (20 分) Being unique is so important to people on Mars that even their lottery is desi ... 
随机推荐
- django常用第三方app大全
			djangoapp 资源大全 最近经常在这个版面看到Django相关扩展的介绍,而其一个扩展写一个帖子,觉得没太必要吧. 以前整理的django资源列表,从我的wiki上转过来的. 要找django资 ... 
- 删除UTF-8 BOM头的GUI小工具
			经常看到PHP群里有人因为UTF-8的BOM头出现这样那样的问题,给出的一个PHP删除BOM头的程序,新手也不会用,所以用wxpython写了一 个GUI,直接选择文件夹路径,就可以将该文件夹下所有指 ... 
- MFC 消息类型
			标准(窗口)消息:窗口消息一般与窗口内部运作有关,如创建窗口,绘制窗口,销毁窗口,通常,消息是从系统发到窗口,或从窗口发到系统.发送函数SendMessage()或者PostMessage().除WM ... 
- 2017.2.21 activiti实战--第十三章--流量数据查询与跟踪(一)查询接口介绍及运行时数据查询
			学习资料:<Activiti实战> 第十三章 流量数据查询与跟踪 本章讲解运行时与历史数据的查询方法.主要包含三种:标准查询,Native查询,CustomSql查询. 13.1 Quer ... 
- bit、位、byte、字节、B、KB、字符与网速
			一.存储单位bit和Byte 1.bit(比特) bit就是位,也叫比特位,是数据存储的最小单位.简写为小写字母“b” 二进制的一位,每个0或1是一个bit 2.Byte(字节) Byte是字节,也有 ... 
- js 淘宝评分
			<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content ... 
- 《学习bash》笔记--调试shell程序
			在shell中,最简单的调试助手时输出语句echo,能够通过把很多echo语句放到代码中进行调试,但必须花费足够的时间以定位 要查看的信息.可能必须通过很多的输出才干发现要查找的信息. 1.set选项 ... 
- C++的标准模板库STL中实现的数据结构之顺序表vector的分析与使用
			摘要 本文主要借助对C++的标准模板库STL中实现的数据结构的学习和使用来加深对数据结构的理解.即联系数据结构的理论分析和详细的应用实现(STL),本文是系列总结的第一篇,主要针对线性表中的顺序表(动 ... 
- TP5结合聚合数据API查询天气
			php根据城市查询天气情况看到有人分享java的查询全国天气情况的代码,于是我想分享一个php版本的查询天气接口.免费查询天气的接口有很多,比如百度的apistore的天气api接口,我本来想采用这个 ... 
- 谷歌浏览器插件-html页面js事件查看器
			谷歌浏览器插件-html页面js事件查看器 1.下载 下载地址:http://files.cnblogs.com/files/graceup/VisualEvent.zip 解压得到文件:Visual ... 
