Codeforces 534A Exam 水

來源:互聯網
上載者:User

標籤:

題意:給你1-n,問你最多能安排幾個數相鄰數字不相鄰的位置。

解題思路:插空法。

解題代碼:

 1 // File Name: a.cpp 2 // Author: darkdream 3 // Created Time: 2015年04月13日 星期一 00時00分57秒 4  5 #include<vector> 6 #include<list> 7 #include<map> 8 #include<set> 9 #include<deque>10 #include<stack>11 #include<bitset>12 #include<algorithm>13 #include<functional>14 #include<numeric>15 #include<utility>16 #include<sstream>17 #include<iostream>18 #include<iomanip>19 #include<cstdio>20 #include<cmath>21 #include<cstdlib>22 #include<cstring>23 #include<ctime>24 #define LL long long25 26 using namespace std;27 int n ;28 int main(){29     scanf("%d",&n);30     if(n == 1 || n== 2)31     {32         printf("1\n1\n");33         return 0 ; 34     }35     if(n == 3 )36     {37      printf("2\n1 3\n");38      return 0 ; 39     }40     if(n== 4)41     {42         printf("4\n3 1 4 2\n");43         return 0 ; 44     }45     if(n% 2== 0)46     {47       printf("%d\n",n);48       for(int i = 1;i <= n/2 ;i ++)49           printf("%d %d ",i,i+n/2);50     }else{51       printf("%d\n",n);52       for(int i = 1;i <= n/2 ;i ++)53           printf("%d %d ",i,i+n/2+1);54       printf("%d\n",n/2+1);55     }56 return 0;57 }
View Code

 

Codeforces 534A Exam 水

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.