码迷,mamicode.com
首页 > 其他好文 > 详细

2017年吉林大学考研初试专业课966第六题

时间:2018-12-21 22:42:54      阅读:251      评论:0      收藏:0      [点我收藏+]

标签:统计   大学   输出   分享   class   algo   clu   数组   math   

 

技术分享图片

 1 #include <iostream>
 2 #include <algorithm>
 3 #include <cmath>
 4 #include <set>
 5 using namespace std;
 6 int main(){
 7     int n;
 8     cin>>n;
 9     int tot;
10     tot=pow(2,n);
11     int a[200];
12     //预处理
13     for(int i=0;i<200;i++){
14         a[i]=1;
15     }
16     for(int i=1;i<=tot/2;i++){
17         a[i]=0;
18     }
19     
20     /*
21      do{
22      }while(a+1,a+1+tot);
23      对0 1数组进行全排列
24      */
25     do{
26         /*
27          判断全排列的每种情况是否符合题意要求的 每三个数拼凑成一个10进制数
28          统计最后生成的不相同数字是否为2^n-2个
29          如果满足情况,输出这种情况,程序结束
30          */
31         int num[1000];
32         for(int i=1;i<=tot;i++){
33             num[i]=a[i];
34         }
35         int j;
36         j=1;
37         for(int i=tot+1;i<=2*tot;i++){
38             num[i]=a[j];
39             j++;
40         }
41         set<int >alln;
42         for(int i=1;i<=tot-1;i++){
43             int tt;
44             tt=0;
45             int kk;
46             kk=0;
47             for(int j=n;j>=1;j--){
48                 tt+=num[i+kk]*pow(2,j-1);
49                 kk++;
50             }
51             alln.insert(tt);
52         }
53         if((int )alln.size()==tot-2){
54             for(int i=1;i<=tot;i++){
55                 cout<<a[i]<<" ";
56             }
57             cout<<endl;
58             break;
59         }
60     }while(next_permutation(a+1, a+tot+1));
61     return 0;
62 }

 

2017年吉林大学考研初试专业课966第六题

标签:统计   大学   输出   分享   class   algo   clu   数组   math   

原文地址:https://www.cnblogs.com/jlbcljb/p/10158996.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!