CodeForces - 1015D
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
10 2 15
YES
10 4
10 9 45
YES
10 1 10 1 2 1 2 1 6
10 9 81
YES
10 1 10 1 10 1 10 1 10
10 9 82
NO 刚一碰到题,头有点大,感觉有很多需要判断的条件,但是仔细缕一缕发现,其实需要判的条件并不多。
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<deque>
#include<map>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0);
const double e=exp();
const int N = ; #define lson i << 1,l,m
#define rson i << 1 | 1,m + 1,r int main()
{
LL n,k,s;
LL i,j,x,y,p;
scanf("%lld%lld%lld",&n,&k,&s);
p=;
if(k>s||(n-)*k<s)
printf("NO\n");
else
{
printf("YES\n");
x=s/k;
y=s%k;
for(i=; i<=k; i++)
{
LL mid=x;
if(y>)
{
mid+=;
y--;
}
if(p+mid>n)
p=p-mid;
else
p=p+mid;
printf("%lld ",p);
}
}
return ;
}
CodeForces - 1015D的更多相关文章
- 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 ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
- CodeForces - 261B Maxim and Restaurant
http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...
- CodeForces - 696B Puzzles
http://codeforces.com/problemset/problem/696/B 题目大意: 这是一颗有n个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...
随机推荐
- 开发环境解决 kafka Failed to send messages after 3 tries
新建了一个kafka集群,在window下写了一个简单的producer做测试,结果遇到了消息发送失败的问题,代码如下: Properties props = new Properties(); pr ...
- openssl 基本加密
openssl命令行工具详解(openssl的命令众多,请酌情处理与记忆) 在命令行输入:openssl asdf,可以显示openssl的命令说明 1:Standard commands(标准命 ...
- 操作系统作业一——仿CMD
实验一.CMD实验 2014商软2 卓宇靖 4238 一. 实验目的 (1)掌握命令解释程序的原理: (2)掌握简单的DOS调用方法: (3)掌握C语言编程初步. 二. ...
- laya3d 文件格式
先认识下laya3d的一些文件 导出文件说明: ls --- 场景文件: Json文件,包含场景中所有节点的数据信息,包含光照贴图信息 ...
- oracle锁与死锁概念,阻塞产生的原因以及解决方案
锁是一种机制,一直存在:死锁是一种错误,尽量避免. 首先,要理解锁和死锁的概念: 1.锁: 定义:简单的说,锁是数据库为了保证数据的一致性而存在的一种机制,其他数据库一样有,只不过实现机制上可能大 ...
- 「美团 CodeM 资格赛」跳格子
题目描述 nnn 个格子排成一列,一开始,你在第一个格子,目标为跳到第 n 个格子.在每个格子 i 里面你可以做出两个选择: 选择「a」:向前跳 ai 步. 选择「b」:向前跳 bi 步. 把每步 ...
- Jsp遍历后台传过来的List
1:使用jstl标签 (可以和自定义标签配合使用) 首先引用jstl标签 <%@ taglib uri="http://java.sun.com/jsp/jstl/core" ...
- 【BZOJ2109/2535】【NOI2010】航空管制(贪心)
[BZOJ2109/2535][NOI2010]航空管制(贪心) 题面 BZOJ2109 BZOJ2535 题解 很好玩的一道题目 先看第一问,显然是要找一个合法的拓扑排序的序列. 直接拓扑排序,把队 ...
- 【HDU4336】Card Collector (动态规划,数学期望)
[HDU4336]Card Collector (动态规划,数学期望) 题面 Vjudge 题解 设\(f[i]\)表示状态\(i\)到达目标状态的期望 \(f[i]=(\sum f[j]*p[j]+ ...
- Unity3D手游开发日记(3) - 场景加载进度条的完美方案
我以为做个进度条很简单,分分钟解决,结果折腾了一天才搞定,Unity有很多坑,要做完美需要逐一解决. 问题1:最简单的方法不能实现100%的进度 用最简单的方法来实现,不能实现100%的进度,原因是U ...