1. 程式人生 > >Codeforces 877 C Slava and tanks

Codeforces 877 C Slava and tanks

題目地址
題意:給你一家飛機,以及一個1*n的地圖,每個格子裡面有若干個坦克,每個坦克要被轟炸兩次才能毀滅,如果坦克受到了傷害的話,他就會移向旁邊的格子,問你轟炸多少次才能把所有坦克消滅掉。
思路:很容易想到我們先轟炸偶數的序號的格子(因為可能會比奇數格少一個),然後所有坦克就會到奇數格了,然後我們再轟炸一邊奇數格,這樣的話,原來在奇數格的坦克就都會到偶數格上去,原本在偶數格的就會被消滅,最後我們在轟炸一邊偶數格就把所有坦克消滅了。

#include <iostream>
#include <cstring>
#include <string>
#include
<queue>
#include <vector> #include <map> #include <set> #include <cmath> #include <cstdio> #include <algorithm> #include <iomanip> #define N 10 #define M 2000010//雙倍 #define LL __int64 #define inf 0x3f3f3f3f3f3f3f3f #define lson l,mid,ans<<1 #define rson mid+1,r,ans<<1|1
#define getMid (l+r)>>1 #define movel ans<<1 #define mover ans<<1|1 using namespace std; const LL mod = 1000000007; const double eps = 0.001; int main() { cin.sync_with_stdio(false); int n, a, b; while (cin >> n) { a = n / 2; b = n - a; cout << a * 2 + b << endl; for
(int i = 2; i <= n; i+=2) { cout << i << " "; } for (int i = 1; i <= n; i += 2) { cout << i << " "; } for (int i = 2; i <= n; i += 2) { cout << i << " "; } cout << endl; } return 0; }