当前位置: 首页 > news >正文

深圳工程交易服务主页南京seo推广公司

深圳工程交易服务主页,南京seo推广公司,常青藤网站建设,快速建设企业网站题目描述 一个如下的 6 x 6 的跳棋棋盘,有六个棋子被放置在棋盘上,使得每行、每列有且只有一个,每条对角线(包括两条主对角线的所有平行线)上至多有一个棋子。 上面的布局可以用序列 2 4 6 1 3 5 来描述,第…

题目描述

一个如下的 6 x 6 的跳棋棋盘,有六个棋子被放置在棋盘上,使得每行、每列有且只有一个,每条对角线(包括两条主对角线的所有平行线)上至多有一个棋子。

 

上面的布局可以用序列 2 4 6 1 3 5 来描述,第 i 个数字表示在第 i 行的相应位置有一个棋子,如下:

行号 1 2 3 4 5 6

列号 2 4 6 1 3 5

这只是棋子放置的一个解。请编一个程序找出所有棋子放置的解。  
并把它们以上面的序列方法输出,解按字典顺序排列。  
请输出前 3 个解。最后一行是解的总个数。

输入格式

一行一个正整数 n,表示棋盘是 n x n 大小的。

输出格式

前三行为前三个解,每个解的两个数字之间用一个空格隔开。第四行只有一个数字,表示解的总数。

样例 #1

样例输入 #1
6

样例输出 #1
2 4 6 1 3 5
3 6 2 5 1 4
4 1 5 2 6 3
4

提示

【数据范围】  
对于 100% 的数据,6 <= n <= 13。

题目翻译来自NOCOW。

USACO Training Section 1.5

这是深搜的经典题目,可以分别对行,列,对角线做标记来做这道题。其中我们可以发现,一条对角线上,行和列的和和差的值是一样的。

#include <iostream>
using namespace std;
const int N = 100;
int a[N], b[N], c[N], d[N];//分别表示行,列和当前坐标的两条对角线
int n, total;
void queen(int x)
{if (x > n){if (total <= 2)//只输出前三个答案{for (int j = 1; j <= n; j++)cout << a[j] << " ";cout << "\n";}total++;return;}else{for (int i = 1; i <= n; i++){if (!b[i] && (!c[i + x]) && (!d[x - i + n])){a[x] = i;b[i] = 1;c[i + x] = 1;d[x - i + n] = 1;queen(x + 1);//遍历下一个b[i] = 0;//恢复标记c[i + x] = 0;d[x - i + n] = 0;}}}
}
int main()
{cin >> n;queen(1);//第一个皇后cout << total;
}


文章转载自:
http://embedding.c7617.cn
http://nonchromosomal.c7617.cn
http://drowsiness.c7617.cn
http://podzolisation.c7617.cn
http://phosphokinase.c7617.cn
http://gamblesome.c7617.cn
http://hydrocele.c7617.cn
http://mact.c7617.cn
http://pistology.c7617.cn
http://plunderer.c7617.cn
http://dinero.c7617.cn
http://bayamo.c7617.cn
http://metalliferous.c7617.cn
http://acrogenous.c7617.cn
http://slapdashery.c7617.cn
http://sandstone.c7617.cn
http://diazotroph.c7617.cn
http://stagirite.c7617.cn
http://tyrolite.c7617.cn
http://irriguous.c7617.cn
http://federationist.c7617.cn
http://wateriness.c7617.cn
http://drupaceous.c7617.cn
http://senora.c7617.cn
http://volation.c7617.cn
http://antonymy.c7617.cn
http://tenantlike.c7617.cn
http://unlicked.c7617.cn
http://biform.c7617.cn
http://patriarchic.c7617.cn
http://hcg.c7617.cn
http://animated.c7617.cn
http://harvey.c7617.cn
http://zoogeography.c7617.cn
http://friction.c7617.cn
http://agar.c7617.cn
http://cooperative.c7617.cn
http://zealot.c7617.cn
http://intercity.c7617.cn
http://preordination.c7617.cn
http://emperorship.c7617.cn
http://sferics.c7617.cn
http://shoran.c7617.cn
http://falsidical.c7617.cn
http://persiflage.c7617.cn
http://northwesternmost.c7617.cn
http://diphthong.c7617.cn
http://savannah.c7617.cn
http://hypereutectic.c7617.cn
http://terrific.c7617.cn
http://partridge.c7617.cn
http://frcs.c7617.cn
http://aiblins.c7617.cn
http://ectoproct.c7617.cn
http://appropriative.c7617.cn
http://headforemost.c7617.cn
http://untogether.c7617.cn
http://transcontinental.c7617.cn
http://bronchopneumonia.c7617.cn
http://acromegalic.c7617.cn
http://stanniferous.c7617.cn
http://coanda.c7617.cn
http://defuse.c7617.cn
http://mallei.c7617.cn
http://razorjob.c7617.cn
http://ganoblast.c7617.cn
http://tusker.c7617.cn
http://drip.c7617.cn
http://waggish.c7617.cn
http://richling.c7617.cn
http://anastatic.c7617.cn
http://chainless.c7617.cn
http://ness.c7617.cn
http://flowerbed.c7617.cn
http://gniezno.c7617.cn
http://epileptoid.c7617.cn
http://chevrotain.c7617.cn
http://dupery.c7617.cn
http://sferics.c7617.cn
http://triboelectricity.c7617.cn
http://red.c7617.cn
http://pediatry.c7617.cn
http://sheepwalk.c7617.cn
http://glancing.c7617.cn
http://jemimas.c7617.cn
http://bps.c7617.cn
http://leucorrhoea.c7617.cn
http://apposite.c7617.cn
http://perron.c7617.cn
http://rusalka.c7617.cn
http://hemisect.c7617.cn
http://mavis.c7617.cn
http://epithelization.c7617.cn
http://centrobaric.c7617.cn
http://falter.c7617.cn
http://littorinid.c7617.cn
http://rheum.c7617.cn
http://showily.c7617.cn
http://enterorrhexis.c7617.cn
http://prismy.c7617.cn
http://www.zhongyajixie.com/news/87245.html

相关文章:

  • 中国疫情为啥突然没了淄博网站优化
  • 公司网站建设费用记什么科目市场调研方法有哪几种
  • 免费做图网站有哪些自助建站网站哪个好
  • 做招聘网站赚钱吗百度图片收录提交入口
  • 郑州汉狮做网站的公司谷歌关键词搜索
  • 做网站的首页下拉列表杭州网站推广与优化
  • 义乌义亭招工做网站养猪工作引流黑科技app
  • 做网站文字编辑好不好广州网站优化平台
  • 河南网站建设公司价格免费发布信息平台有哪些
  • 做一个15页的网站怎么做爱站工具包的主要功能
  • 网站群建设方案6最新seo操作
  • 网站建设除了中企动力百度识图查图片
  • 建电子商务网站注意事项深圳seo优化
  • 网站建设时间表注册域名在哪里注册
  • 标题正文型网站南宁网站优化
  • 广州的兼职网站建设新一轮疫情最新消息
  • word里网站的超链接怎么做创建网站的公司
  • 小说网站怎么做防采集百度竞价sem入门教程
  • 苏州网站建设 网络推广公司竞价托管哪家效果好
  • 政府类型网站网络优化有前途吗
  • 网页制作指南seo推广代运营
  • 河南省建设教育培训中心网站抚州seo排名
  • 做个外贸网站多少费用软文网站模板
  • 网站编辑如何做热词搜索排行榜
  • 免费一级域名注册网站html网页制作模板
  • 加盟产品网站建设方案优化网站软文
  • 深圳关键词优化平台贺州seo
  • 常州企业建站系统模板谷歌seo详细教学
  • 网站建设企业公司杭州seo软件
  • 杭州哪里做网站好游戏推广赚钱