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 22will 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 ll integers from 11 to nndenoting the number of the skewer that is to be turned over at the corresponding step.

Examples

Input
  1. 7 2
Output
  1. 2
    1 6
Input
  1. 5 1
Output
  1. 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.

若翻动其中的一个烤串,也会影响到两侧的烤串,问怎样才能翻动最少的次数,使得全部的烤串都由初始的正面变成反面。

一刻开始思考的是,两侧的烤串是否要翻动,直接考虑了边界,然后想用边界去就决定主体,但是这个切入点是错的。

正确的切入点是:因为每串烤串影响的范围是一定的,那么就有了个周期循环的过程,且每个烤串被翻过一次,也就是说不需要一个数被除两次,因此将问题缩小为有几个串是多余的。再分类讨论:

设余数为p,将所有多余的串放到开头。这些烤串肯定是只翻动一次,问题是翻哪一串。

又,不管翻哪一串最小的影响都是k+1,所以若p>(K+1)好说,若p<(k+1)&&p!=0 , 则必须翻第一串且因为它造成了过多的影响,所以之后每一个翻动的位置都要向后错。

  1. #include<cstdio>
  2. #include<cstdlib>
  3. #include<cstring>
  4. #include<string>
  5. #include<cmath>
  6. #include<algorithm>
  7. #include<queue>
  8. #include<stack>
  9. #include<deque>
  10. #include<map>
  11. #include<iostream>
  12. using namespace std;
  13. typedef long long LL;
  14. const double pi=acos(-1.0);
  15. const double e=exp();
  16. const int N = ;
  17.  
  18. int ans[];
  19. int main()
  20. {
  21. int i,p,j,n,k;
  22. int cnt=;
  23. scanf("%d%d",&n,&k);
  24. p=n%(*k+);
  25. if(p==)
  26. {
  27. for(i=k+;i<=n;i+=(*k+))
  28. ans[cnt++]=i;
  29. }
  30. else if(p<=(k+)&&p!=)
  31. {
  32. ans[cnt++]=;
  33. for(i=k+;i<=n;i+=(*k+))
  34. {
  35. if(i+k<=n)
  36. ans[cnt++]=i+k;
  37. else
  38. ans[cnt++]=n;
  39. }
  40.  
  41. }
  42. else
  43. {
  44. ans[cnt++]=p-(k+)+;
  45. for(i=p+;i<=n;i+=(*k+))
  46. {
  47. if(i+k<n)
  48. ans[cnt++]=i+k;
  49. }
  50. }
  51. printf("%d\n",cnt);
  52. for(i=;i<cnt;i++)
  53. printf("%d ",ans[i]);
  54. return ;
  55. }

CodeForces - 1040B Shashlik Cooking的更多相关文章

  1. CodeForces - 1040B Shashlik Cooking(水题)

    题目: B. Shashlik Cooking time limit per test 1 second memory limit per test 512 megabytes input stand ...

  2. A - Shashlik Cooking CodeForces - 1040B

    http://codeforces.com/problemset/problem/1040/B Long story short, shashlik is Miroslav's favorite fo ...

  3. 【Codeforces Round #507 (Div. 2, based on Olympiad of Metropolises) B】Shashlik Cooking

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 翻转一次最多影响2k+1个地方. 如果n<=k+1 那么放在1的位置就ok.因为能覆盖1..k+1 如果n<=2k+1 ...

  4. Shashlik Cooking

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

  5. 2018SDIBT_国庆个人第二场

    A.codeforces1038A You are given a string ss of length nn, which consists only of the first kk letter ...

  6. Codeforces Round #326 (Div. 2) A. Duff and Meat 水题

    A. Duff and Meat Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/588/probl ...

  7. Codeforces Gym 100342D Problem D. Dinner Problem Dp+高精度

    Problem D. Dinner ProblemTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/1003 ...

  8. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  9. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

随机推荐

  1. 关于vue项目管理项目的架构管理平台

    关于vue项目管理项目的架构管理平台 https://panjiachen.github.io/vue-element-admin-site/#/zh-cn/faq 31.4k 次浏览 完整项目地址: ...

  2. Ubuntu 14.04(64bit)使用mentohust连接校园网

    ubuntu14.04系统安装成功之后,需要连接上网络才可以对更新系统以及安装一些必须包.而在学校中,经常遇到的情况需要通过锐捷客户端来连接校园网. 更新: 在Ubuntu14.04下面不用装ment ...

  3. IE实现userData 永久存储

      注意:只支持IE5,及其以上的浏览器 //需要使用 if 条件注释 <!DOCTYPE html> <html> <head> <meta charset ...

  4. double 和 im2double 的区别

    double 就是简单地把一个变量类型转换成double型,数值大小不变. 函数im2double将输入换成double类型.如果输入是unit8,unit16或者是二值的logical类型,则函数i ...

  5. 【Java并发编程】之十一:线程间通信中notify通知的遗漏

    notify通知的遗漏很容易理解,即threadA还没开始wait的时候,threadB已经notify了,这样,threadB通知是没有任何响应的,当threadB退出synchronized代码块 ...

  6. Linux_MySql_yum_安装

    1.卸载原始mysql-lib sudo rpm -e --nodeps mysql-libs-xx 2.yum安装mysql-server sudo yum -y install mysql -se ...

  7. Powerful array CodeForces - 86D(莫队)

    给你n个数,m次询问,Ks为区间内s的数目,求区间[L,R]之间所有Ks*Ks*s的和.1<=n,m<=200000.1<=s<=10^6 #include <iostr ...

  8. C/C++缓冲区刷新问题

    参考链接 参考链接2 Buffers are normally maintained by the operating system, which determines the optimal tim ...

  9. Java List /ArrayList 三种遍历方法

    java list三种遍历方法性能比较http://www.cnblogs.com/riskyer/p/3320357.html JAVA LIST 遍历http://blog.csdn.net/lo ...

  10. 【loj2586】【APIO2018】选圆圈

    题目 有 \(n\) 个圆$c_1,c_2, \cdots , c_n $,执行如下的操作: 找到剩下的半径最大的圆删除并删除所有和它有交的其他并没有被删除的圆: 求每个圆是被那个圆删除的: $1 \ ...