CodeForces - 1040B (思维题)

代码极其简短

#include<iostream>
#include <stdio.h>
using namespace std;
const int MAX = 1005;
int a[MAX];
int main()
{
    int n, k;
    scanf("%d%d", &n, &k);
    int cnt  = n / (2 * k + 1);
    int x = n % (2 * k + 1);
    printf("x = %d\n", x);
    if(x != 0){
        cnt++;
    } else{
        x = 2 * k;
    }
    printf("%d\n", cnt);
    for(int i = 1 + x / 2; i <= n; i += 2 * k + 1){ //若x != 0,则将一份完全的分成最左边何最右边两份,每份离左端(或右端的距离为x / 2)
        printf("%d ", i);
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_43737952/article/details/89265649
今日推荐