CodeForces 877C Slava and tanks

本文介绍了一种在特定地图上使用最少炸弹摧毁所有坦克的策略。通过将地图划分为奇数区和偶数区,文章详细阐述了如何利用坦克移动规律来制定轰炸计划,以达到最小化轰炸次数的目标。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Slava plays his favorite game "Peace Lightning". Now he is flying a bomber on a very specific map.

Formally, map is a checkered field of size 1 × n, the cells of which are numbered from 1 to n, in each cell there can be one or several tanks. Slava doesn't know the number of tanks and their positions, because he flies very high, but he can drop a bomb in any cell. All tanks in this cell will be damaged.

If a tank takes damage for the first time, it instantly moves to one of the neighboring cells (a tank in the cell n can only move to the cell n - 1, a tank in the cell 1 can only move to the cell 2). If a tank takes damage for the second time, it's counted as destroyed and never moves again. The tanks move only when they are damaged for the first time, they do not move by themselves.

Help Slava to destroy all tanks using as few bombs as possible.

Input

The first line contains a single integer n (2 ≤ n ≤ 100 000) — the size of the map.

Output

In the first line print m — the minimum number of bombs Slava needs to destroy all tanks.

In the second line print m integers k1, k2, ..., km. The number ki means that the i-th bomb should be dropped at the cell ki.

If there are multiple answers, you can print any of them.

Sample Input

Input

2

Output

3
2 1 2 

Input

3

Output

4
2 1 3 2 

 

题意:在n个区域内有许多坦克,每个坦克有两个血条,你可向任意一个区域投放炸弹,该区域的坦克被炸时会损失一个血条,此时只有一个血条的坦克就会被摧毁,有两个血条的坦克会损失一个血条并逃到邻近的区域,区域1的坦克只能逃到区域2,区域n的坦克只能逃到区域n-1,问你最少要投放多少颗炸弹才能将所有坦克摧毁,并输出投放炸弹的位置

 

观察发现(看题解):
奇数区域的坦克被轰炸后会逃到偶数区;

偶数区域的坦克被轰炸后会逃到奇数区;

看似无规律的移动 实则有规律可寻,

将区域划分为偶数区和奇数区,这样处理问题来非常简单,不用去仔细去分析每个坦克的移动。

所以有:

先轰炸一遍偶数区(为什么不是奇数区?使轰炸次数最少),再轰炸一遍奇数区,再轰炸一遍偶数区

 

 

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <stack>
#include <queue>
#include <deque>
#include <cstdio>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define eps 1e-8
#define PI acos(-1)
#define INF 0x3f3f3f3f
using namespace std;
const int N=1e6;
typedef long long int LL;
const int dir[4][2]= { {1,0},{0,1},{-1,0},{0,-1} };


int ans[N];
int GCD(int a,int b)
{
    return b ? GCD(b,a%b) : a;
}


int main()
{
    int i,g=0,n;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
        if(i%2==0)
            ans[g++]=i;

    for(i=1;i<=n;i++)
        if(i%2!=0)
            ans[g++]=i;

    for(i=1;i<=n;i++)
        if(i%2==0)
            ans[g++]=i;
    printf("%d\n",g);
    for(i=0;i<g;i++)
        printf("%d%c",ans[i],i==g-1?'\n':' ');
    return 0;
}

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值