Q9.9 N queens

PAT甲级 1128 N Queens Puzzle 摘要 本文介绍了N皇后问题的判定方法。题目要求在N×N棋盘上放置N个皇后,确保它们互不攻击(即不在同一行、列或对角线上)。输入给出K个测试用例,每个用例包含一个皇后位置序列。程序需要判断该序列是否为有效解。通过检查行冲突和对角线冲突来验证解的正确性,最终输出"YES"或"NO"。示例输入包含4个测试用例,对应输出为"YES","NO","NO","YES"。 阅读详情

Q: Write an algorithm to print all ways of arranging eight queens on a chess board so that none of them share the same row, column or diagonal.

A: 经典的8皇后问题。DFS

#include <iostream>
#include <string>
#include <vector>
using namespace std;

void dfs(vector<int> &colum, vector<int> &main_diag, vector<int> &anti_diag, int row, vector<vector<string> > &res, vector<int> &path) {
	const int N = path.size();
	if (row == N) {
		vector<string> cur;
		for (int i = 0; i < N; i++) {
			string s(N,'.');
			s[path[i]] = 'Q';
			cur.push_back(s);
			cout<<s<<endl;
		}
		cout<<endl;
		res.push_back(cur);
		return ;		
	}
	
	for (int i = 0; i < N; i++) {
		bool ok = colum[i] == 0 && main_diag[row+i] == 0 && anti_diag[row+N-i] == 0;
		if (!ok) continue;
		path[row] = i;
		colum[i] = main_diag[row+i] = anti_diag[row+N-i] = 1;
		dfs(colum, main_diag, anti_diag, row+1, res, path);
		colum[i] = main_diag[row+i] = anti_diag[row+N-i] = 0;
	}
}

vector<vector<string> > n_queen(const int n) {
	vector<int> colum(n, 0);
	vector<int> main_diag(2*n, 0);
	vector<int> anti_diag(2*n, 0);
	vector<vector<string> > res;
	vector<int> path(n, 0);
	dfs(colum, main_diag, anti_diag, 0, res, path);
	return res;
}

int main() {
	n_queen(8);
	return 0;
}


3分钟学会SQL中的断点去重技术,轻松搞定连续重复数据去重问题? 传感器采集的温度数据中,存在连续重复的值,需仅在数值变化时保留记录(例如:温度从 25°C 变为 26°C 时记录一次)。:判断逻辑,current_value!若当前温度与前一行的温度不同(或为第一条记录),则保留该行。的技术,常用于时间序列或状态日志中。:将连续相同值的记录合并,只保留断点处的记录。保留断点处的记录(即温度变化时的第一条)。原始数据表 sensor_data。最终仅保留值变化的断点记录。获取前一行的温度值。 阅读详情

相关推荐

用Matlab机器人工具箱搞定六轴机械臂建模:从DH参数到3D可视化(附完整代码)

本文详细介绍了如何使用Matlab机器人工具箱进行六轴机械臂建模,涵盖从DH参数转换到3D可视化的完整流程。通过正运动学验证、逆解计算和工作空间分析等实战案例,帮助开发者快速掌握机械臂建模技巧,并提供性能优化建议和完整代码示例。

weixin_28733637的博客 361

Q9

Your database is running in archivelog mode. Examine the parameters for your database instance:LOG_ARCHIVE_DEST_l = 'LOCATION=/disk1/arch MANDATORY’LOG_ARCHIVE_DEST_2 = 'LOCATION=/disk2/arch’LOG_ARCHI...

u012887743的博客 540

RK3568平台 麦克风PDM接口录音_rk pdm配置

在RK平台,Android的Audio HAL层中一般会都会有导出录音播放数据的功能。如播放的,是会直接送到声卡中的,对于播放出现问题的情况,可以从分析导出的音频数据是否正常,可以基本知道,是在应用、解码出现的问题,还是送到声卡过程中出现问题。当点开app进行录音的时候会调用到static int start_input_stream(struct stream_in *in)。音频在PDM接口输入,不经过编解码芯片直接到RK主芯片,RK主芯片自带PCM编解码功能。以下软件能播放保存下来的pdm文件。

2401_83817122的博客 2343

LeetCode //C - 51. N-Queens

【代码】LeetCode //C - 51. N-Queens。

Made in Code 1107

Ego-Planner实战避坑指南:从环境搭建到仿真运行

本文详细介绍了在Windows系统下,通过WSL2搭建Ego-Planner无人机路径规划算法开发环境的完整流程与实战避坑指南。内容涵盖ROS Noetic安装、第三方依赖库(如Ceres Solver)编译冲突解决、Realsense SDK版本降级处理,以及Gazebo仿真与真机调试的常见问题,旨在帮助开发者高效完成环境配置并成功运行仿真。

weixin_29232507的博客 700

GVINS数据采集(u-blox fp9 + D435i)

1、配置千寻的RTK账号 采集数据当天购买千寻的RTK账号,然后在Window下,输入账号和密码 (具体的步骤如之前面连接所示),查看u-center软件上的信息,确保接收机可以收到RTK信息; 2、查看Linux系统下u-blox是否可以正常接受GPS信号和RTK数据流 1、GPS信号信息 // 打开端口 1 cd ublox_f9p/src // 或者在终端1下也可以 source devel/setup.bash r.....................

努力努力努力 2609

N-queens Problem

The n-queen problem refers to placing n queens on an n×n chessboard so that the queens cannot attack each other, that is, any two queens cannot be on the same row, column or slope. Now given an integer n, please output all chess pieces that meet the condit

m0_63851309的博客 292

YOLOv8-Pose 姿态识别 RK3588 实战:从模型训练到 RKNN 部署,精度与推理速度双提升

本教程从YOLOv8-pose模型的姿态识别训练,到RK3588的边缘量化部署,为你打造了一套“高精度+高实时性+低成本”的人体姿态分析解决方案。无论是健身动作纠正、智能安防行为检测,还是工业人员姿态监控,这套技术都能直接复用——你只需替换数据集与业务逻辑,即可快速落地专属的边缘AI姿态识别系统。如果你在实践中遇到任何卡点,欢迎随时交流。记住,人体姿态识别的价值在于“关键点准、推理快、部署易”,而这三者的平衡,正是你通过本教程能掌握的核心能力。

FJN110的博客 364

PAT 甲级 1128  N Queens Puzzle

1128 N Queens Puzzle (20 point(s)) The "eight queens puzzle" is the problem of placing eight chess queens on an 8×8 chessboard so that no two queens threaten each other. Thus, a solution requires tha...

漫浸天空的雨色的备忘录~ 727

激光雷达的64线,32线,16线,你弄懂了吗?

激光雷达的 64 线、32 线、16 线是指激光雷达系统中能够同时发射和接收激光脉冲的激光线的数量5。

谢谢大家的关注和点赞!这里只有纯纯的知识干货,没有一句废话。希望能实实在在帮到大家~要是觉得有用,别忘了给我点支持哟,你 2637

基于Blender软件对Matterport3D数据集场景可视化

使用Blender软件对 Matterport3D 中的室内场景进行可视化。

qq_44100524的博客 290

1128 N Queens Puzzle (20)

【代码】1128 N Queens Puzzle (20)

2401_88085478的博客 884

GD32F130之USART多机通信

简介 在多机通信中,一个从机应该只接收它需要接收的数据,且只应该在它需要接收数据时才检测串口。而始终接收RX线上的数据对从机来说是一种负担。 多机通信硬件设计 远距离方案:RS485 板级方案: 静默模式 静默模式有什么作用? 答:如果 USART 处于静默模式,所有的接收状态标志位将不会被置位。 如何进入静默模式? 答:软件可以通过将 USART_CMD 寄存器中MMCMD 位置 1 使 USART 进入静默模式。 如何从静默模式中唤醒? 答:有两种方式可选,①检测到总线

luliplus的博客 301

LeetCode --- 51. N-Queens

题目链接:N-Queens The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other. Given an integer n, return all distinct solutions to the n-queens

makuiyu的专栏 2761

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

pat 1128N Queens Puzzle

原题链接:https://www.patest.cn/contests/pat-a-practise/1128 N Queens Puzzle The "eight queens puzzle" is the problem of placing eight chess queens on an 8×8 chessboard so that no two queens thre

messenger的博客 320

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

1128 N Queens Puzzle (20分) N皇后 问题

1128 N Queens Puzzle (20分) The "eight queens puzzle" is the problem of placing eight chess queens on an 8×8 chessboard so that no two queens threaten each other. Thus, a solution requires that no two queens share the same row, column, or diagonal. The eig

小渣渣的博客 462

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

[LintCode] N-Queens

N-Queens The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other. Given an integer n, return all distinct solutions to the n-queens puzz...

weixin_34249367的博客 133

51. N-Queens

题目: Then-queenspuzzle is the problem of placingnqueens on ann x nchessboard such that no two queens attack each other. Given an integern, returnall distinct solutions to then-queens puzzle. Each solution contains a distinct board configuration ...

weixin_49991368的博客 181

PAT 1128 N Queens Puzzle

原题链接:1128 N Queens Puzzle (20分) 关键词:模拟 题目大意: N-皇后问题是在n*n的棋盘上摆上n个皇后,要求任意两个皇后不在同一行、同一列、同一斜线上。 本题给出了几个可能,问你是否是N-皇后问题的解。

cwtnice的博客 159

1128 N Queens Puzzle

The “eight queens puzzle” is the problem of placing eight chess queens on an 8×8 chessboard so that no two queens threaten each other. Thus, a solution requires that no two queens share the same row, ...

无名小白的博客 219

1128 N Queens Puzzle (20 分)

1128 N Queens Puzzle (20 分) The "eight queens puzzle" is the problem of placing eight chess queens on an 8×88\times 88×8 chessboard so that no two queens threaten each other. Thus, a solution require...

acm_zh的博客 293

N-Queens

N-Queens 1 public class Solution { 2 public static ArrayList<String[]> solveNQueens(int n) { 3 // Start typi...

abiding97192的博客 81

1128. N Queens Puzzle (20)

时间限制 300 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue The "eight queens puzzle" is the problem of placing eight chess queens on an 8×8 chessboard so that no two queens threaten...

SourDumplings的博客 162
上一篇: Q9.8 Combine Sum
下一篇: Q9.10 To build the tallest stack
「已注销」
博客等级 码龄15年 5粉丝 218原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值