CodeForces D. Walking Between Houses

http://codeforces.com/contest/1015/problem/D

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

YES10 4 

input

Copy

10 9 45

output

Copy

YES10 1 10 1 2 1 2 1 6 

input

Copy

10 9 81

output

Copy

YES10 1 10 1 10 1 10 1 10 

input

Copy

10 9 82

output

Copy

NO

代码:

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
ll N, K, S;

int main() {
    cin >>N >> K >> S;
    if((N - 1) * K < S || S < K) {
        printf("NO\n");
        return 0;
    }

    printf("YES\n");
    int st = 1;
    while(K --) {
        int dis = min(S - K, N - 1);
        S -= dis;
        if(st + dis <= N) st += dis;
        else st -= dis;
        printf("%d ", st);
    }
    printf("\n");
    return 0;
}

  

原文地址:https://www.cnblogs.com/zlrrrr/p/9858444.html

时间: 2024-10-17 06:59:29

CodeForces D. Walking Between Houses的相关文章

CodeForces - 1015 D.Walking Between Houses

Description Natasha is planning an expedition to Mars for nn people. One of the important tasks is to provide food for each participant. The warehouse has mm daily food packages. Each package has some food type ai. Each participant must eat exactly o

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

翻译 给你一条数轴(出题人很喜欢数轴啊),上面有排列着\(n\)个点,编号为\(1\)到\(n\)(你开始在\(1\)).每次你要从一个点移动到另一个点(可以重复).移动距离为两点坐标之差的绝对值,问你是否能否在\(k\)次机会内里一共移动\(s\)距离,并输出方案. 思路 第四题还是比较难的,赛后想了几分钟时才有头绪. 毫无疑问还是贪心(出题人很喜欢贪心啊)!那么我们分类讨论,先看不合法的情况 无论如何走你也走不到那个距离 无论如何走你也会走超那个距离 看来只要能走到那个距离除外都是不合法的,

Codeforces 1154D - Walking Robot - [贪心]

题目链接:https://codeforces.com/contest/1154/problem/D 题解: 贪心思路,没有太阳的时候,优先用可充电电池走,万不得已才用普通电池走.有太阳的时候,如果可充电电池能够充一格电,就用普通电池跑(让可充电池充电),否则就用可充电电池走. AC代码: #include<bits/stdc++.h> using namespace std; const int maxn=2e5+10; int n,a,b; bool s[maxn]; int main()

CF D. Walking Between Houses (贪心)

题意: 现在有n个房子排成一列,编号为1~n,起初你在第1个房子里,现在你要进行k次移动,每次移动一都可以从一个房子i移动到另外一个其他的房子j里(i != j),移动的距离为|j - i|.问你进过k次移动后,移动的总和可以刚好是s吗?若可以则输出YES并依次输出每次到达的房子的编号,否则输出NO. 分析:首先观察下NO的情况,如果s<k 也就是说总步数都比不是次数的话,那肯定是NO拉,或者s>k*(n-1) 无论如何走都到吧了总步数,那也是NO; 什么时候是YES呢?我们可以贪心下,尽可能

Codeforces 327E Axis Walking (状压dp lowbit优化)

E. Axis Walking time limit per test:3 seconds memory limit per test:512 megabytes Iahub wants to meet his girlfriend Iahubina. They both live in Ox axis (the horizontal axis). Iahub lives at point 0 and Iahubina at point d. Iahub has n positive integ

Codeforces Round #177 (Div. 2)---D. Polo the Penguin and Houses (组合数学+暴力)

Little penguin Polo loves his home village. The village has n houses, indexed by integers from 1 to n. Each house has a plaque containing an integer, the i-th house has a plaque containing integer pi (1?≤?pi?≤?n). Little penguin Polo loves walking ar

Diagonal Walking v.2 CodeForces - 1036B (思维,贪心)

Diagonal Walking v.2 CodeForces - 1036B Mikhail walks on a Cartesian plane. He starts at the point (0,0)(0,0), and in one move he can go to any of eight adjacent points. For example, if Mikhail is currently at the point (0,0)(0,0), he can go to any o

Codeforces 1036B Diagonal Walking v.2 【贪心】

题目传送门:https://codeforces.com/contest/1036/problem/B 被这道题坑了,说白了还是菜. 贪心策略是先斜对角从(0,0)走到(n,n),然后往右拐(分奇偶考虑)[若n>m,swap(n,m)] 理论上是画画图,知道切入点是奇偶性后,就能想清楚了 #include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<q

Codeforces Round #617 (Div. 3) C. Yet Another Walking Robot

http://codeforces.com/contest/1296/problem/C 题意:给一段字符串表示移动,然后求删除最短的一段,并且不影响结果 题解: 意思是:建立pair点和map,当遍历到第i个点有一个pair值,把这个加到map里面,如果向后接着遍历时出现与i点相同的pair值时,那么这一段表示可以删除的一段 #include <bits/stdc++.h> using namespace std; int main() { #ifdef _DEBUG freopen(&qu