zoukankan      html  css  js  c++  java
  • 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 |xy||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 (2n1092≤n≤109, 1k21051≤k≤2⋅105, 1s10181≤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 (1hin1≤hi≤n) on the second line, where hihi is the house you visit on the ii-th move.

    For each jj from 11 to k1k−1 the following condition should be satisfied: hjhj+1hj≠hj+1. Also h11h1≠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

    代码:

    #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
    ");
            return 0;
        }
    
        printf("YES
    ");
        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("
    ");
        return 0;
    }
    

      

  • 相关阅读:
    Windows 7 x64 (英文操作系统)安装SQLServer 2005版本相关解决方法
    vs2008打开vs2010所做的项目的方法
    sqlserver2008 创建自动备份任务(图文教程)
    js返回上一页,自动刷新自身、父页面语句的实现
    有效的更改IE、Firefox、Chrome浏览器缓存位置的方法
    oo第二次总结
    OO第一次博客总结
    Ansible常用命令整理
    APM全链路监控日志收集篇
    TCP 和 UDP 的区别还有一个UTP一
  • 原文地址:https://www.cnblogs.com/zlrrrr/p/9858444.html
Copyright © 2011-2022 走看看