D. Walking Between Houses
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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 |x−y||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 (2≤n≤1092≤n≤109 , 1≤k≤2⋅1051≤k≤2⋅105 , 1≤s≤10181≤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 (1≤hi≤n1≤hi≤n ) on the second line, where hihi is the house you visit on the ii -th move.

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

Examples
Input

Copy
10 2 15
Output

Copy
YES
10 4
Input

Copy
10 9 45
Output

Copy
YES
10 1 10 1 2 1 2 1 6
Input

Copy
10 9 81
Output

Copy
YES
10 1 10 1 10 1 10 1 10
Input

Copy
10 9 82
Output

Copy
NO

题目大意:1~n个房子,起点为1,然后规定刚好k步,走完s的距离,(从x到y,距离为|x-y|).

思路:以为是个深搜。但是感觉写不了。。。看了官方题解。(蠢了)。左右走无法判断。

官方给了 cur + x cur - x 来左右走。怎么保证刚好k步s距离呢。 s-(k-1)

如果s-(k-1) > (n-1)  走最大的距离,然后k -= 1,  s -= l;  (l为他俩的最小值)

当k等于1,剩最后s',就保证刚好走完s。k != 1, 总还会剩一点。比较巧妙

不能刚好k步走完s,当且仅当 k > s or  k*(n-1) < s

能继续走,当且仅当 k-1 <=  s-x      x <= n-1 也就是min(n-1, s-(k-1));

 #include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f; ll step(ll cur, ll x) {
if(cur - x > )//能左走就先左走
return cur - x;
else//不行就右走
return cur + x;
} int main() {
//freopen("in.txt", "r", stdin);
ll n, k, s, cur = ;
scanf("%lld%lld%lld", &n, &k, &s);
if(k > s || k*(n-) < s) {//只有这两种情况NO
printf("NO\n");
return ;
}
printf("YES\n");
while(k > ) {//先走最大的,直到最后不足最大的,然后一点点走。
ll l = n- < s-(k-) ? n- : s-(k-);// s-(k-1)能保证k步刚好s距离
cur = step(cur, l);//左走还是右走
printf("%lld ", cur);
s -= l;
k -= ;
}
}

Codeforces Round #501 (Div. 3) 1015D Walking Between Houses的更多相关文章

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

    题目链接 题意:给你三个数n,k,sn,k,sn,k,s,让你构造一个长度为k的数列,使得相邻两项差值的绝对值之和为sss, ∑i=1n∣a[i]−a[i−1]∣,a[0]=1\sum_{i=1}^n ...

  2. Codeforces Round #501 (Div. 3) D. Walking Between Houses (思维,构造)

    题意:一共有\(n\)个房子,你需要访问\(k\)次,每次访问的距离是\(|x-y|\),每次都不能停留,问是否能使访问的总距离为\(s\),若能,输出\(YES\)和每次访问的房屋,反正输出\(NO ...

  3. Codeforces Round #501 (Div. 3) F. Bracket Substring

    题目链接 Codeforces Round #501 (Div. 3) F. Bracket Substring 题解 官方题解 http://codeforces.com/blog/entry/60 ...

  4. Codeforces Round #501 (Div. 3)

    A - Points in Segments 题意:implement #include<bits/stdc++.h> using namespace std; typedef long ...

  5. Codeforces Round #501 (Div. 3) 1015A Points in Segments (前缀和)

    A. Points in Segments time limit per test 1 second memory limit per test 256 megabytes input standar ...

  6. 【Codeforces Round #501 (Div. 3)】

    A:https://www.cnblogs.com/myx12345/p/9842904.html B:https://www.cnblogs.com/myx12345/p/9842964.html ...

  7. Codeforces Round #501 (Div. 3) B. Obtaining the String (思维,字符串)

    题意:有两个字符串\(S\)和\(T\),判断\(T\)是否能由\(S\)通过交换某位置的相邻字符得到,如果满足,输出交换次数及每次交换的位置,否则输出\(-1\). 题解:首先判断不满足的情况,只有 ...

  8. Codeforces Round #552 (Div. 3) 题解

    Codeforces Round #552 (Div. 3) 题目链接 A. Restoring Three Numbers 给出 \(a+b\),\(b+c\),\(a+c\) 以及 \(a+b+c ...

  9. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

随机推荐

  1. python模块inspect.py

    inspect模块用来检查对象的类型(函数,属性,类,抽象基类,方法,模块等等) 是一个封装好的非常有用的模块. ]) ]: cls = :]: content = ] = lines[].lstri ...

  2. BZOJ4676 Xor-Mul棋盘

    传送门 题目大意懒得写了,题目说的挺明白的了 题解 主要的难点在于异或意义下的最大值和很玄学,但不难发现这道题中让你定义的$D_{i,j}$只参与异或运算,所以我们可以逐位进行讨论.所以我们每一位就只 ...

  3. hdu 3998 Sequence

    There is a sequence X (i.e. x[1], x[2], ..., x[n]). We define increasing subsequence of X as x[i1], ...

  4. VBA记录当前系统时间并精确到毫秒

    想做个功能,点一次按钮,就在A1记录一次当前系统时间,要精确到毫秒的.再点一次按钮就在A2显示,以此类推! 例如:这个功能可以用来做歌词记时间! Sub ttt() ActiveCell.Select ...

  5. 洛谷【P1908】逆序对

    题目传送门:https://www.luogu.org/problemnew/show/P1908 所谓逆序对,就是序列中\(a[i]>a[j]\)且\(i<j\)的有序对. 所以我们在归 ...

  6. 孤独地、凄惨地AK

    一个\(OIer\)要写多少\(for\) 才能被称为一个\(OIer\) 一位巨佬要爆过多少次零 才能在省选逆袭 手指要多少次掠过键盘 才能安心地休息 \(OI\)啊 我的朋友 在风中\(AK\) ...

  7. 问题15:如何判断字符串a是否以字符串b开头或结尾

    方法一:使用正则表达式的^和$实现 '^000':表示,只匹配字符串的开头,若开头是 '000' ,则返回 ['000'] : '000$':表示,只匹配字符串的结尾,若结尾是 '000' ,则返回 ...

  8. 【转】 Pro Android学习笔记(五七):Preferences(1):ListPreference

    目录(?)[-] 例子1ListPreference小例子 定义一个preferences XML文件 继承PreferenceActivity 用户定制偏好的读取 第一次运行时设置缺省值 设置Cat ...

  9. Hdu 4762 网络赛 高精度大数模板+概率

    注意题目中的这句话he put the strawberries on the cake randomly one by one,第一次选择草莓其实有N个可能,以某一个草莓为开头,然后顺序的随机摆放, ...

  10. 杂项:art-template-loader

    ylbtech-杂项:art-template-loader 1.返回顶部   2.返回顶部   3.返回顶部   4.返回顶部   5.返回顶部 1. https://www.npmjs.com/p ...