蓝桥杯第六题,也是全排列。
2016-04-09 13:58
253 查看
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
int a[10];
int cot=0;
bool check(int i,int j){
return abs(a[i]-a[j])!=1;
}
bool check(){
return (check(0,1)&&check(0,3)&&check(0,4)&&check(0,5)&&check(1,2)
&&check(1,4)&&check(1,5)&&check(1,6)&&check(2,5)&&check(2,6)&&check(3,4)&&check(3,7)&&
check(3,8)&&check(4,5)&&check(4,7)&&check(4,8)&&check(4,9)
&&check(5,6)&&check(5,8)&&check(5,9)&&check(6,9)&&check(7,8)&&check(8,9));
}
int main(){
for(int i=0;i<10;i++)
a[i]=i;
do{
cot=cot+check();
}while(next_permutation(a, a + 10));
cout << cot <<endl;
return 0;
}
#include <iostream>
#include <algorithm>
using namespace std;
int a[10];
int cot=0;
bool check(int i,int j){
return abs(a[i]-a[j])!=1;
}
bool check(){
return (check(0,1)&&check(0,3)&&check(0,4)&&check(0,5)&&check(1,2)
&&check(1,4)&&check(1,5)&&check(1,6)&&check(2,5)&&check(2,6)&&check(3,4)&&check(3,7)&&
check(3,8)&&check(4,5)&&check(4,7)&&check(4,8)&&check(4,9)
&&check(5,6)&&check(5,8)&&check(5,9)&&check(6,9)&&check(7,8)&&check(8,9));
}
int main(){
for(int i=0;i<10;i++)
a[i]=i;
do{
cot=cot+check();
}while(next_permutation(a, a + 10));
cout << cot <<endl;
return 0;
}
相关文章推荐
- 解决tableView左侧有一小段空缺,…
- cell延迟显示,效果好像一个一个加…
- 查找UINavigationController中指定…
- iOS:textfield切换显隐时发生的问…
- 10018---solrserver Extension
- Linux环境下socket通信
- 【综述】3D智能数字化与3D打印:"中国制造"向"中国智造"转变的机遇
- [疯狂Java]SQL库函数:行函数、组函数、select分组、筛选组
- 去掉空格和回车
- 微信相关
- 常用宏定义(代码适配,设置颜色,…
- 隐藏多于的空白cell
- 修改nav返回按钮样式,并且设施返…
- json转字典
- 查找指定字符串变色
- 去掉UINavigationController返回按…
- MenuViewController
- delegate为nil的原因
- mysql 时间类型小结
- CGContextRef类画图形、文字、图片