题目1140:八皇后
来源:互联网 发布:高斯面膜 知乎 编辑:程序博客网 时间:2024/04/29 17:47
#include <iostream>#include <algorithm>#include <queue>#include <vector>#include <cstring>#include <stack>#include <string>#include <string.h>#include <stdio.h>#include <cmath>#include <map>#include <functional>#include <set>#include <limits.h>#include <math.h>#include <ctype.h>using namespace std;//1140int d[9];int n,t;vector<string> v;void tran(){ string t; for(int i=1;i<=8;i++) t+=char(d[i]+'0'); v.push_back(t);}bool check(int i,int x){ for(int j=1;j<x;j++) if(i==d[j] || abs(i-d[j])==abs(x-j)) return false; return true;}void queen(int x) //放第n列{ if(x>8) { tran(); return ; } for(int i=1;i<=8;i++)//第x列要放在i行 { if(!check(i,x)) continue; d[x]=i; queen(x+1); }} int main(){ queen(1); while(cin>>n) { while(n--) { cin>>t; cout<<v[t-1]<<endl; } } return 0;}/************************************************************** Problem: 1140 User: cust123 Language: C++ Result: Accepted Time:10 ms Memory:1520 kb****************************************************************/
0 0
- 题目1140:八皇后
- 题目1140:八皇后
- 题目1140:八皇后
- 回溯_题目1140:八皇后
- 九度 oj 题目1140:八皇后
- 八皇后的题目
- 【LeetCode】N-Queens && 【九度】题目1140:八皇后
- [递归经典题目]八皇后问题
- 1140_八皇后
- 九度OJ 1140:八皇后 (八皇后问题)
- 深搜-jobdu-1140八皇后
- 八皇后
- 八皇后
- 八皇后
- 八皇后
- 八皇后
- 八皇后
- 八皇后
- SDP描述h264
- 小程序常见问题汇总,方便自己看
- stm32f051精确延时的实现
- Struts2的配置文件
- linux安装redis
- 题目1140:八皇后
- MTK Kernel启动流程源码解析 4 start_kernel 上
- 仿网易新闻标签选择器(可拖动)-TabMoveLayout
- Adjacent Bit Counts
- BLE 配对流程
- Oracle 11G 安装图解
- Android 隐藏虚拟按键及状态栏
- java.lang.ClassNotFoundException: org.gjt.mm.mysql.Driver错误在eclipse中的解决方法
- 统计 sqlServer grouping with Rollup