計蒜客 39279.Swap-打表找規律 (The 2019 ACM-ICPC China Shannxi Provincial Programming Contest L.) 2019ICPC西安邀

Swaphtml

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

  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).app

Input

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

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

The second line contains nn different numbers.htm

Output

Output the number of different sequences.blog

樣例輸入1

3
2 5 8

樣例輸出1

6

樣例輸入2

4
1 2 3 4

樣例輸出2

4

 

 

找規律,打個表就發現了。ip

打表代碼也貼下面。get

 

代碼:string

  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 */
相關文章
相關標籤/搜索