摘要: n-皇后问题是指将 n 个皇后放在 n∗n 的国际象棋棋盘上,使得皇后不能相互攻击到,即任意两个皇后都不能处于同一行、同一列或同一斜线上。 现在给定整数n,请你输出所有的满足条件的棋子摆法。 #include<bits/stdc++.h> using namespace std; int p[100 阅读全文
posted @ 2020-12-29 16:56 君与 阅读(42) 评论(0) 推荐(0) 编辑
摘要: 给定一个整数n,将数字1~n排成一排,将会有很多种排列方法。 现在,请你按照字典序将所有的排列方法输出。 #include<bits/stdc++.h> using namespace std; int n,p[10]; bool k[10]; void out() { for(int i=1;i< 阅读全文
posted @ 2020-12-29 16:47 君与 阅读(64) 评论(0) 推荐(0) 编辑
摘要: #include<bits/stdc++.h> #define ll long long using namespace std; int m; int n,p[20]; int sum,ans; int main() { scanf("%d%d",&n,&m); for(int i=1;i<=m; 阅读全文
posted @ 2020-12-29 16:40 君与 阅读(70) 评论(0) 推荐(0) 编辑
摘要: #include<bits/stdc++.h> using namespace std; typedef long long LL; LL exgcd(LL a,LL b,LL &x,LL &y) { if(!b) { x=1,y=0; return a; } LL d=exgcd(b,a%b,y, 阅读全文
posted @ 2020-12-29 16:15 君与 阅读(51) 评论(0) 推荐(0) 编辑
摘要: 壹——最大公约数 欧几里得算法: gcd(x,y)=gcd(y,x%y); 边界条件:if(y==0)return x; #include<bits/stdc++.h> using namespace std; int a,b; inline int gcd(int x,int y) { if(!y 阅读全文
posted @ 2020-12-29 13:09 君与 阅读(59) 评论(0) 推荐(0) 编辑