Codeforces 877(442 Div.2) C. Slava and tanks(思维)

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.

Examples

Input

2

Output

3
2 1 2 

Input

3

Output

4
2 1 3 2 

 

 

题意:在一维数轴上有一个长为n的阵地,在阵地上有一些坦克(不知道数量和位置),你是一名飞行员,你的任务是炸毁这些坦克,坦克防御力很强,第一枚导弹只会炸伤坦克,第二枚导弹才能炸毁,当坦克受到攻击时,坦克就会向左或者右移动一个(不知道具体向左还是右)。你飞得太高了,所以你看不到地面的情况。问在这种情况下,如何轰炸才能在保证在炸毁所有的坦克的前提下,花费导弹最少。

 

思路:先炸偶数区间,所有坦克移动到奇数区间,然后再炸奇数区间,将所有被炸伤的坦克炸毁,并且所有原来在奇数区间的坦克移动到偶数区间,然后在炸偶数区间即可。(刚开始理解错题意了,以为题中求最少导弹数就是就 最小可能导弹数,最小可能导弹数是n+1枚,大家有空可以推一下,挺有意思的)

 

#include "iostream"
#include "map"
#include "algorithm"
using  namespace std;
map<int,int> mp;
const int Max=1e5+10;
int a[Max];
int main()
{
    ios::sync_with_stdio(false);
    int n,k,m,x,flag=0;
    mp.clear();
    cin>>n>>k>>m;
    for(int i=0;i<n;i++){
        cin>>a[i];
        mp[a[i]%m]++;
    }
    for(int i=0;i<m;i++)
        if(mp[i]>=k&&!flag){
            flag=1;
            cout<<"Yes"<<endl;
            for(int j=0;j<n;j++)
                if(a[j]%m==i&&k) {cout<<a[j]<<" ";k--;}
        }
    if(!flag) cout<<"No";
    cout<<endl;
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值