B. Shashlik Cooking:题目
思路,如果所有烤肉都可以一次就行,如果不行就去前面调整一下
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<ll> a((int)6e5);
vector<ll> b((int)6e5);
int main()
{
int n,k;
cin>>n>>k;
if (!k)
{
cout<<n<<endl;
for (int i=1;i<=n;i++) cout<<i<<" ";
return 0;
}
int res = 0;
int p = n/(k*2+1);
int v = n%(k*2+1);
if (p==0)
{
cout<<1<<endl<<(n+1)/2;
}
else
{
if (v==0)
{
cout<<p<<endl;
for (int i=k+1;i<=n;i+=2*k+1) cout<<i<<" ";
}
else if (v<=k+1)
{
p--;
int cou = v+2*k+1;
int cou1 = cou/2;
int cou2 = cou-cou1;
cout<<p+2<<endl;
cout<<cou1-k<<" ";
int pp = p;
int i = cou1+k+1;
while (pp)
{
cout<<i<<" ";
pp--;
i+=2*k+1;
}
cout<<n-(cou2-k)+1;
}
else
{
cout<<p+1<<endl;
for (int i=k+1;i<=n;i+=2*k+1) cout<<i<<" ";
}
}
}