Walking Between Houses

There are 1.

You have to perform a. 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 s 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 k moves.

Input

The first line of the input contains three integers 1≤s≤1018) — the number of houses, the number of moves and the total distance you want to walk.

Output

If you cannot perform 

Otherwise print "YES" on the first line and then print exactly i-th move.

For each h1≠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


题目意思:
现在有n个房子排成一列,编号为1~n,起初你在第1个房子里,现在你要进行k次移动,每次移动一都可以从一个房子i移动到另外一个其他的房子j
里(i != j),移动的距离为|j - i|。问你进过k次移动后,移动的总和可以刚好是s吗?若可以则输出YES并依次输出每次到达的房子的编号,
否则输出NO。

解题思路:
每次至少移动一个单位的距离,至多移动n-1个单位的距离,所以要想完成上述要求每次决策前后一定要满足条件: 
k <= s && k*(n-1) >= s

   假设当前决策为移动x单位的距离,所以要满足下述条件: 
 ( k-1 <= s-x) && (x <= n-1)

   得:max(x) = min( (s - k + 1) , (n-1) ) 
   因此我们的决策为:每次移动的大小为 s与k的差值 和 n-1 中的较小值,使得s和k尽快的相等。

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<cstring>
 4 #define ll long long int
 5 #include<algorithm>
 6 using namespace std;
 7 ll n,s,k;
 8 int main()
 9 {
10     ll sum,i,pos,len;
11     scanf("%lld%lld%lld",&n,&k,&s);
12     if(k>s||k*(n-1)<s)
13     {
14         printf("NO\n");
15     }
16     else
17     {
18         printf("YES\n");
19         pos=1;///记录位置
20         while(k--)
21         {
22           len=min(s-k,n-1);
23           s=s-len;
24           if(pos+len<=n)///向前移还是向后移的判断
25           {
26               pos=pos+len;
27           }
28           else
29           {
30               pos=pos-len;
31           }
32           printf("%d ",pos);
33         }
34     }
35     return 0;
36 }

 



相关文章:

  • 2022-03-07
  • 2022-12-23
  • 2022-12-23
  • 2021-06-20
  • 2021-10-01
  • 2021-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-11-12
  • 2021-10-12
  • 2022-12-23
  • 2021-05-24
  • 2021-06-04
  • 2021-08-04
  • 2022-12-23
相关资源
相似解决方案