当前位置: 首页 > 工具软件 > shashlik > 使用案例 >

1040B. Shashlik Cooking

杜砚
2023-12-01

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<<" ";
        }
    }
}
 类似资料:

相关阅读

相关文章

相关问答