题目:
B. Shashlik Cooking
time limit per test

1 second

memory limit per test

512 megabytes

input

standard input

output

standard output

Long story short, shashlik is Miroslav's favorite food. Shashlik is prepared on several skewers simultaneously. There are two states for each skewer: initial and turned over.

This time Miroslav laid out nn skewers parallel to each other, and enumerated them with consecutive integers from 11 to nn in order from left to right. For better cooking, he puts them quite close to each other, so when he turns skewer number ii, it leads to turning kk closest skewers from each side of the skewer ii, that is, skewers number i−ki−k, i−k+1i−k+1, ..., i−1i−1, i+1i+1, ..., i+k−1i+k−1, i+ki+k (if they exist).

For example, let n=6n=6 and k=1k=1. When Miroslav turns skewer number 33, then skewers with numbers 22, 33, and 44 will come up turned over. If after that he turns skewer number 11, then skewers number 11, 33, and 44 will be turned over, while skewer number 22 will be in the initial position (because it is turned again).

As we said before, the art of cooking requires perfect timing, so Miroslav wants to turn over all nn skewers with the minimal possible number of actions. For example, for the above example n=6n=6 and k=1k=1, two turnings are sufficient: he can turn over skewers number 22 and 55.

Help Miroslav turn over all nn skewers.

Input

The first line contains two integers nn and kk (1≤n≤10001≤n≤1000, 0≤k≤10000≤k≤1000) — the number of skewers and the number of skewers from each side that are turned in one step.

Output

The first line should contain integer ll — the minimum number of actions needed by Miroslav to turn over all nn skewers. After than print llintegers from 11 to nn denoting the number of the skewer that is to be turned over at the corresponding step.

Examples
input

Copy
7 2
output

Copy
2
1 6
input

Copy
5 1
output

Copy
2
1 4
Note

In the first example the first operation turns over skewers 11, 22 and 33, the second operation turns over skewers 44, 55, 66 and 77.

In the second example it is also correct to turn over skewers 22 and 55, but turning skewers 22 and 44, or 11 and 55 are incorrect solutions because the skewer 33 is in the initial state after these operations.

题目大意:

翻烤串问题,有N个烤串需要被翻面,每次翻第i个烤串可以使得第i-k到第i+k个烤串也同时翻转,问需要至少多少次的翻转使得翻转烤串的数量最大,输出次数和每次翻转烤串的位置。

思路:

首先,每一次翻转烤串的最大影响个数为2*k+1(本身和左右都影响到的烤串)。那么我们可以先将(2*k+1)的倍数烤串翻转,余数进行判断。

如果余数大于k,那么翻转次数加一;如果余数为零,那么翻转次数就为n/(2*k+1);如果余数小于k,那么翻转次数加一,并使第一个翻转烤串的位置从余数开始,保证答案正确。

AC代码如下:

#include<stdio.h>

int main()
{
int n,k;
scanf("%d%d",&n,&k);
int mi=n%(*k+);
if(mi>k) mi=k+,printf("%d\n",n/(*k+)+);
else if(mi==) mi=k+,printf("%d\n",n/(*k+));
else {
printf("%d\n",n/(*k+)+);
}
for(;mi<=n;mi+=*k+) printf("%d ",mi);
return ;
}

CodeForces - 1040B Shashlik Cooking(水题)的更多相关文章

  1. CodeForces - 1040B Shashlik Cooking

    Long story short, shashlik is Miroslav's favorite food. Shashlik is prepared on several skewers simu ...

  2. Codeforces Gym 100531G Grave 水题

    Problem G. Grave 题目连接: http://codeforces.com/gym/100531/attachments Description Gerard develops a Ha ...

  3. codeforces 706A A. Beru-taxi(水题)

    题目链接: A. Beru-taxi 题意: 问那个taxi到他的时间最短,水题; AC代码: #include <iostream> #include <cstdio> #i ...

  4. codeforces 569B B. Inventory(水题)

    题目链接: B. Inventory time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  5. Codeforces 489A SwapSort (水题)

    A. SwapSort time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...

  6. codeforces 688A A. Opponents(水题)

    题目链接: A. Opponents time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  7. CodeForces 534B Covered Path (水题)

    题意:给定两个速度,一个一初速度,一个末速度,然后给定 t 秒时间,还每秒速度最多变化多少,让你求最长距离. 析:其实这个题很水的,看一遍就知道怎么做了,很明显就是先从末速度开始算起,然后倒着推. 代 ...

  8. Codeforces Gym 100286I iSharp 水题

    Problem I. iSharpTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/ ...

  9. CodeForces 705A(训练水题)

    题目链接:http://codeforces.com/problemset/problem/705/A 从第三个输出中可看出规律, I hate that I love that I hate it ...

随机推荐

  1. memcached、cookie、session

    Memcached(一个高性能的分布式的内存对象缓存系统) 可用来分担数据库的压力.通过在内存里维护一个统一的巨大的hash表,memcached能存储各种各样的数据,包括图像.视频.文件.以及数据库 ...

  2. scipy 短时傅里叶变化

    原文链接   https://www.cnblogs.com/hoojjack/p/9967298.html 计算短时傅里叶变换(STFT) scipy.signal.stft(x,fs = 1.0, ...

  3. mysql基础篇(上篇)

    一.数据库 1.数据库介绍 2.RDBMS专业术语 3.MySQL数据库 4.常用数据库命令 1.数据库介绍 :什么是数据库 数据库就是按照数据结构来组织.存储和管理数据的仓库. 我们常常讲的数据库往 ...

  4. java的hello world

    public class HelloWorld { public static void main(String []args) { System.out.println("Hello Wo ...

  5. 解决IE11安装时需要“获取更新”(IE11离线安装)

    方法一:说明:目前是针对Windows7 64位操作系统安装! 1. 在C盘下新建文件夹,取名为“IE11”. 2. 将官网下载的IE11离线包放到此文件夹中. 3. win + r 打开运行窗口,输 ...

  6. [原]osg模型动画|骨骼动画

    参考源码:osg的官方例子:osganimationviewer 首先制作一个带骨骼动画的模型  demo.FBX 这里面我们做了两个骨骼动画:1.open   2.close 下面开始在osg中使用 ...

  7. MySQL 列出存储过程

    MySQL  列出存储过程 接下来介绍如何列出MySQL数据库中的所有存储过程,并显示存储过程源代码的一些非常有用的语句. MySQL为提供了一些有用的语句,可以更有效地管理存储过程.这些语句包括列出 ...

  8. 3 - Two Pointers Algorithm

    5. Kth Largest Element (quick sort的变种) https://www.lintcode.com/problem/kth-largest-element/descript ...

  9. springboot缓存注解——@Cacheable和@CacheConfig

    @Caching :制定多个缓存规则 @Cacheable 和 @CachePut 同时标注时 ,@CachePut导致还是会走方法跟数据库交互 //根据lastName查,并将结果缓存,并且可以用于 ...

  10. IP通信实验感想

    经过几周的学习之后,我终于开始了IP通信的实验课. 我们利用H3C进行对ip地址进行设置,在对不同交换机下的pc进行连接测试 首先,我们对交换机和pc机器进行配置设置,ip地址分配分别从192.168 ...