zoukankan      html  css  js  c++  java
  • CodeForces

    There are nn houses in a row. They are numbered from 11 to nn in order from left to right. Initially you are in the house 11.

    You have to perform kk moves to other house. In one move you go from your current house to some other house. You can't stay where you are (i.e., in each move the new house differs from the current house). If you go from the house xx to the house yy, the total distance you walked increases by |xy||x−y| units of distance, where |a||a| is the absolute value of aa. It is possible to visit the same house multiple times (but you can't visit the same house in sequence).

    Your goal is to walk exactly ss units of distance in total.

    If it is impossible, print "NO". Otherwise print "YES" and any of the ways to do that. Remember that you should do exactly kk moves.

    Input

    The first line of the input contains three integers nn, kk, ss (2n1092≤n≤109, 1k21051≤k≤2⋅105, 1s10181≤s≤1018) — the number of houses, the number of moves and the total distance you want to walk.

    Output

    If you cannot perform kk moves with total walking distance equal to ss, print "NO".

    Otherwise print "YES" on the first line and then print exactly kk integers hihi (1hin1≤hi≤n) on the second line, where hihi is the house you visit on the ii-th move.

    For each jj from 11 to k1k−1 the following condition should be satisfied: hjhj+1hj≠hj+1. Also h11h1≠1 should be satisfied.

    Examples

    Input
    10 2 15
    Output
    YES
    10 4
    Input
    10 9 45
    Output
    YES
    10 1 10 1 2 1 2 1 6
    Input
    10 9 81
    Output
    YES
    10 1 10 1 10 1 10 1 10
    Input
    10 9 82
    Output
    NO


    刚一碰到题,头有点大,感觉有很多需要判断的条件,但是仔细缕一缕发现,其实需要判的条件并不多。

     1 #include<cstdio>
     2 #include<cstdlib>
     3 #include<cstring>
     4 #include<cmath>
     5 #include<algorithm>
     6 #include<queue>
     7 #include<stack>
     8 #include<deque>
     9 #include<map>
    10 #include<iostream>
    11 using namespace std;
    12 typedef long long  LL;
    13 const double pi=acos(-1.0);
    14 const double e=exp(1);
    15 const int N = 100010;
    16 
    17 #define lson i << 1,l,m
    18 #define rson i << 1 | 1,m + 1,r
    19 
    20 int main()
    21 {
    22     LL n,k,s;
    23     LL i,j,x,y,p;
    24     scanf("%lld%lld%lld",&n,&k,&s);
    25     p=1;
    26     if(k>s||(n-1)*k<s)
    27         printf("NO
    ");
    28     else
    29     {
    30         printf("YES
    ");
    31         x=s/k;
    32         y=s%k;
    33         for(i=1; i<=k; i++)
    34         {
    35             LL mid=x;
    36             if(y>0)
    37             {
    38                 mid+=1;
    39                 y--;
    40             }
    41             if(p+mid>n)
    42                 p=p-mid;
    43             else
    44                 p=p+mid;
    45             printf("%lld ",p);
    46         }
    47     }
    48     return 0;
    49 }
    View Code
  • 相关阅读:
    连接ACCESS数据库[原创]
    破解金山词霸2007
    上班族饮食十大“夺命”恶习
    C#3.0 新特性速览(1) (2)
    抽象工厂模式(AbstractFactory)创建型模式
    委托创建小记
    八个笑话,八个人生哲理
    自定义对话框[原创]
    一个数字键盘的自定义控件[原创]
    男人绝对需要红颜知己
  • 原文地址:https://www.cnblogs.com/daybreaking/p/9417814.html
Copyright © 2011-2022 走看看