计蒜客 39279.Swap-打表找规律 (The 2019 ACM-ICPC China Shannxi Provincial Programming Contest L.) 2019ICPC西安邀请赛现场赛重现赛

Swap

There is a sequence of numbers of length nn, and each number in the sequence is different. There are two operations:

  1. Swap the first half and the last half of the sequence (if nn is odd, the middle number does not change)
  1. Swap all the numbers in the even position with the previous number (the position number starts from 11, and if⁡⁡ nn is odd, the last number does not change)

Both operations can be repeated innumerable times. Your task is to find out how many different sequences may appear (two sequences are different as long as the numbers in any one position are different).

Input

Each test file contains a single test case. In each test file:

The first line contains an integer nn, indicating the length of the sequence (1 \le n \le 10000)(1n10000).

The second line contains nn different numbers.

Output

Output the number of different sequences.

样例输入1

3
2 5 8

样例输出1

6

样例输入2

4
1 2 3 4

样例输出2

4

 

 

找规律,打个表就发现了。

打表代码也贴下面。

 

代码:

  1 //L-找规律
  2 #include<bits/stdc++.h>
  3 using namespace std;
  4 const int maxn=1e4+10;
  5 
  6 int a[maxn];
  7 
  8 int main()
  9 {
 10     int n;
 11     scanf("%d",&n);
 12     for(int i=1;i<=n;i++){
 13         scanf("%d",&a[i]);
 14     }
 15     if(n>=1&&n<=4&&n!=3){
 16         printf("%d\n",n);
 17         return 0;
 18     }
 19     else if(n==3){
 20         printf("%d\n",n*2);
 21         return 0;
 22     }
 23     if(n%2==0){
 24         if((n/2)%2==0){
 25             printf("4\n");
 26         }
 27         else{
 28             printf("%d\n",n);
 29         }
 30     }
 31     else{
 32         if((n-3)%4==0){
 33             printf("12\n");
 34         }
 35         else{
 36             printf("%d\n",n*2);
 37         }
 38     }
 39 }
 40 
 41 
 42 /*
 43 1
 44 2
 45 6
 46 4
 47 10
 48 6
 49 12
 50 4
 51 18
 52 10
 53 12
 54 4
 55 26
 56 14
 57 12
 58 4
 59 34
 60 18
 61 12
 62 4
 63 */
 64 
 65 /*
 66 打表找规律
 67 打表的代码
 68 
 69 #include<bits/stdc++.h>
 70 using namespace std;
 71 const double PI=acos(-1.0);
 72 const int maxn=1e5+10;
 73 
 74 char a[maxn];
 75 
 76 int main()
 77 {
 78     for(int k=1;k<=20;k++){
 79         int n=k;
 80         memset(a,0,sizeof(a));
 81         for(int i=1;i<=n;i++){
 82             a[i]='a'+i-1;
 83         }
 84         int num=0;
 85         int cnt=50;
 86         map<string,int> mp;
 87         string s;
 88         while(cnt--){
 89             for(int i=1;i<n;i+=2){
 90                 swap(a[i],a[i+1]);
 91             }
 92             s.clear();
 93             for(int i=1;i<=n;i++){
 94                 s+=a[i];
 95             }
 96             if(mp[s]==0) num++,mp[s]=1;
 97             int ret;
 98             if(n%2==1) ret=n/2+1;
 99             else ret=n/2;
100             for(int i=1;i<=n/2;i++){
101                 swap(a[i],a[i+ret]);
102             }
103             s.clear();
104             for(int i=1;i<=n;i++){
105                 s+=a[i];
106             }
107             if(mp[s]==0) num++,mp[s]=1;
108         }
109         cout<<num<<endl;
110     }
111 }
112 
113 */

 

posted @ 2019-08-01 16:59  ZERO-  阅读(434)  评论(0编辑  收藏  举报