C. Slava and tanks【思维构造】

C. Slava and tanks

题意:有长为n的方格,每个方格里有若干辆坦克,当一个区域里的坦克被炸了,它有一次逃命(朝左或者朝右,在不越界的情况下)的机会。若第二次被炸中,则坦克毁灭。问至少需要多少次,才可让坦克全部毁灭

思路:模拟样例找策略没找出来。 题解是这样讲的,先炸偶数的位置,再炸奇数的位置,再炸偶数的位置。至于证明,没想好

#include<bits/stdc++.h>
#define PI acos(-1.0)
#define pb push_back
#define F first
#define S second
#define debug puts
#define setp cout << fixed << setprecision(3)
#define FAST_IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
const int N=1e5+5;
const int MOD=1e9+7;
const ll INF=1e18+8;

int main(void){
    FAST_IO;
    int n;
    cin >>n;
    int c1=n/2;///even
    int c2=n-c1;///odd
    cout << c1+c1+c2<<"\n";
    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<<" ";

    return 0;
}

猜你喜欢

转载自blog.csdn.net/haipai1998/article/details/80686935