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. JavaWeb日常笔记

    1.   XML文档的作用和解析 1. XML的基本概述: XML的主要是用来存储一对多的数据,另外还可以用来当做配置文件存储数据.XML的表头如下: <?xml version='1.0' e ...

  2. 非空校验在oracle和mysql中的用法

    oracle判断是否为null nvl(参数1,参数2) :如果参数1为null则返回参数2,否则返回参数1 mysql判断是否为null ifnull(参数1,参数2) :如果参数1为null则返回 ...

  3. ElasticSearch优化系列四:ES的heap是如何被瓜分掉的

    以下分别解读几个我知道的内存消耗大户: Segment Memory Segment不是file吗?segment memory又是什么?前面提到过,一个segment是一个完备的lucene倒排索引 ...

  4. Python学习 :异常处理

    异常处理 什么是异常处理 - python解释器检测到错误,触发异常(也允许程序员自己触发了异常) - 程序员编写特定的代码,专门用来捕捉这个异常(这段代码与程序逻辑无关,只与异常处理有关) - 如果 ...

  5. java->php之在线子域名查询-接口光速版

    因为不懂java,所以 用php重写了大佬的 在线子域名查询-接口光速版 http://sbd.ximcx.cn/  这是大佬的 然后 改一下 ,用php 其实就是改了几行代码而已,jquery和aj ...

  6. 用html页面模板使用django完成个人博客

    1.进入虚拟环境: workon 虚拟环境名 2.找到我们的项目管理文件夹django,进入创建项目django-admin startproject blog 3.进入到我们的项目文件夹当中,创建我 ...

  7. 用GO写一个后台权限管理系统

    最近用GO写了一个后台权限管理系统,在WIN10和ubuntu下部署,在win系统下编译ububtu的部署文件要先做如下配置 set GOARCH=amd64 set GOOS=linux go bu ...

  8. 20155207王雪纯 《Java程序设计》实验一报告

    20155207王雪纯 <Java程序设计>实验一报告 课程:Java程序设计 班级:1552 指导教师:娄嘉鹏 实验日期:2017.04.07 实验名称:Java开发环境的熟悉(Linu ...

  9. 20155217 2016-2017-2 《Java程序设计》第6周学习总结

    20155217 2016-2017-2 <Java程序设计>第6周学习总结 教材学习内容总结 第十章 InputStream与OutputStream 10.1.1串流设计的概念 Jav ...

  10. 学号20155311 2016-2017-2 《Java程序设计》第4周学习总结

    教材学习内容总结 6.1 何谓继承 何谓继承 面向对象中,子类继承父类,避免重复的行为定义,不过并非为了避免重复定义行为就使用继承,滥用继承而导致程序维护上的问题时有所闻.如何正确判断使用继承的时机, ...