Walking Between Houses

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
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尽快的相等。

 #include<cstdio>
#include<cstring>
#include<cstring>
#define ll long long int
#include<algorithm>
using namespace std;
ll n,s,k;
int main()
{
ll sum,i,pos,len;
scanf("%lld%lld%lld",&n,&k,&s);
if(k>s||k*(n-)<s)
{
printf("NO\n");
}
else
{
printf("YES\n");
pos=;///记录位置
while(k--)
{
len=min(s-k,n-);
s=s-len;
if(pos+len<=n)///向前移还是向后移的判断
{
pos=pos+len;
}
else
{
pos=pos-len;
}
printf("%d ",pos);
}
}
return ;
}

Walking Between Houses(贪心+思维)的更多相关文章

  1. CF D. Walking Between Houses (贪心)

    题意: 现在有n个房子排成一列,编号为1~n,起初你在第1个房子里,现在你要进行k次移动,每次移动一都可以从一个房子i移动到另外一个其他的房子j里(i != j),移动的距离为|j - i|.问你进过 ...

  2. Mike and distribution CodeForces - 798D (贪心+思维)

    题目链接 TAG: 这是我近期做过最棒的一道贪心思维题,不容易想到,想到就出乎意料. 题意:给定两个含有N个正整数的数组a和b,让你输出一个数字k ,要求k不大于n/2+1,并且输出k个整数,范围为1 ...

  3. Codeforces Round #546 (Div. 2) D 贪心 + 思维

    https://codeforces.com/contest/1136/problem/D 贪心 + 思维 题意 你面前有一个队列,加上你有n个人(n<=3e5),有m(m<=个交换法则, ...

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

    D. Walking Between Houses time limit per test 2 seconds memory limit per test 256 megabytes input st ...

  5. 贪心/思维题 Codeforces Round #310 (Div. 2) C. Case of Matryoshkas

    题目传送门 /* 题意:套娃娃,可以套一个单独的娃娃,或者把最后面的娃娃取出,最后使得0-1-2-...-(n-1),问最少要几步 贪心/思维题:娃娃的状态:取出+套上(2),套上(1), 已套上(0 ...

  6. 贪心/思维题 UVA 11292 The Dragon of Loowater

    题目传送门 /* 题意:n个头,m个士兵,问能否砍掉n个头 贪心/思维题:两个数组升序排序,用最弱的士兵砍掉当前的头 */ #include <cstdio> #include <c ...

  7. T - Posterized(贪心思维)

    Description Professor Ibrahim has prepared the final homework for his algorithm’s class. He asked hi ...

  8. 【CF1015D】Walking Between Houses(构造,贪心)

    题意:从1开始走,最多走到n,走k步,总长度为n,不能停留在原地,不能走出1-n,问是否有一组方案,若有则输出 n<=1e9,k<=2e5,s<=1e18 思路:无解的情况分为两种: ...

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

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

随机推荐

  1. 给Extjs的window弹窗的关闭事件添加验证

    问题:我想在window点击右上角叉关闭时添加一些验证,来确定是否关闭? 实现: 首先想到的是拦截window的关闭事件,在它关闭前添加验证,但是有一个问题是,如何阻止它的关闭和组织关闭后,如何让它再 ...

  2. 底层文件I/O操作中read()函数的缓存问题

    最近在学习Linux过程中看到文件I/O操作这里时,文件I/O操作的系统调用涉及的5个函数:open(),read(),write(),lseek(),close().在一开始就阐明这些函数的特点是不 ...

  3. Bulk Rename Utility 3.0 + x64 中文汉化版

    Bulk Rename Utility 3.0 + x64 中文汉化版由大眼仔旭(www.dayanzai.me)汉化发布.当发现做一件事情,原本用工具或软件进行批量处理也能达到相同效果,可却花了数倍 ...

  4. IIS配置导入导出

    使用管理员身份运行cmd 应用程序池: # 导出所有应用程序池 %windir%\system32\inetsrv\appcmd list apppool /config /xml > c:\a ...

  5. underscore.js常用方法整理(慢慢完善)

    整理自Underscore.js (1.8.3) 中文文档,http://www.css88.com/doc/underscore/ 1. extend _.extend() 复制对象中的所有属性到目 ...

  6. HTML标签速记整理W3C

    标题 <h1>段落<p>链接< href="">图像<img src="">自关闭元素,不需要结束标记换行标志& ...

  7. PHP常用函数归类【持续整理】

    学习了这么久PHP,基础知识总感觉不牢靠,尤其是数组,字符串函数的应用,全部手敲过次手,做出总结都是基础,在回顾一下吧. 一.PHP基础语法 变量,常量     严格区分大小写,但内置结构或关键字无所 ...

  8. 使用jenkins中遇到的问题汇总/持续更新

    jenkins产生大量日志文件 question: [DNSQuestion@1446063419 type: TYPE_IGNORE index 0, class: CLASS_UNKNOWN in ...

  9. Linux了解一下

    VMware与CentOS系统安装 1, 下载CentOS系统ISO镜像: 国内镜像源 https://opsx.alibaba.com/mirror#阿里云官方镜像站 iso下载地址(此DVD映像包 ...

  10. vs2013发布网站合并程序是出错(ILmerge.merge:error)

    Vs2013发布网站时,生成错误提示: 合并程序集时出错: ILMerge.Merge: ERROR!!: Duplicate type 'manage_ForcePasswrod' found in ...