您的位置:首页 > 其它

蓝桥杯第六题,也是全排列。

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;  
}  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: