codeforces Round #501 (Div. 3) D. Walking Between Houses

题目地址:http://codeforces.com/contest/1015/problem/D

理解很简单,主要有一段代码写起来没考虑好

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int inf = 0x3f3f3f3f;
const int N = 200005;
int main()
{
    LL n,k,s;
    while(~scanf("%lld %lld %lld",&n,&k,&s))
    {
        if((n - 1) * k * 1LL < s || k > s){
            printf("NO\n");
        }
        else{
            printf("YES\n");
            if(k == 1){
                printf("%d\n",1 + s);
            }
            else{
            //这里一直没想好怎么写,其实可以一个一个算,不用以下算出来,那个数要出现几次
                int x = 1,y = 1;
                while(s > 0)
                {
                //当走k步需要走出s距离,平均一次要走多少
                    int d = s / k;
                    if(s % k != 0){
                        d++;
                    }
                    x = x + d * y;
                    printf("%d ",x);
                    y *= -1;
                    s -= d;
                    k--;
                }
                printf("\n");
            }
        }
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_36386435/article/details/81365988