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

  • 题解:最优解一定是让每次访问的距离为\(s/k\),然后将余数\(s\ mod\ k\)平均分配到前s%k的房屋中,之后每次访问\(s/k\)即可,也就是构造一个类似于\(x\ 1\ x\ 1\ x\ 1\)这样的一个序列,但因为有余数,所以要修改.

  • 代码:

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    #include <stack>
    #include <queue>
    #include <vector>
    #include <map>
    #include <set>
    #include <unordered_set>
    #include <unordered_map>
    #define ll long long
    #define fi first
    #define se second
    #define pb push_back
    #define me memset
    const int N = 1e6 + 10;
    const int mod = 1e9 + 7;
    const int INF = 0x3f3f3f3f;
    using namespace std;
    typedef pair<int,int> PII;
    typedef pair<ll,ll> PLL; ll n,k,s; int main() {
    ios::sync_with_stdio(false);cin.tie(0);
    cin>>n>>k>>s;
    if(k*(n-1)<s || k>s) puts("NO");
    else{
    puts("YES");
    ll num=s/k;
    ll rest=s%k;
    ll tmp=1;
    for(ll i=1;i<=rest;++i){
    if(tmp==1){
    tmp=num+2;
    printf("%lld ",tmp);
    }
    else{
    tmp=1;
    printf("1 ");
    }
    }
    for(ll i=rest+1;i<=k;++i){
    if(tmp<=num) tmp+=num;
    else tmp-=num;
    printf("%lld ",tmp);
    } } return 0;
    }

Codeforces Round #501 (Div. 3) D. Walking Between Houses (思维,构造)的更多相关文章

  1. 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 ...

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

    题目链接 题意:给你三个数n,k,sn,k,sn,k,s,让你构造一个长度为k的数列,使得相邻两项差值的绝对值之和为sss, ∑i=1n∣a[i]−a[i−1]∣,a[0]=1\sum_{i=1}^n ...

  3. Codeforces Round #501 (Div. 3) B. Obtaining the String (思维,字符串)

    题意:有两个字符串\(S\)和\(T\),判断\(T\)是否能由\(S\)通过交换某位置的相邻字符得到,如果满足,输出交换次数及每次交换的位置,否则输出\(-1\). 题解:首先判断不满足的情况,只有 ...

  4. Codeforces Round #643 (Div. 2) D. Game With Array (思维,构造)

    题意:给你两个正整数\(N\)和\(S\),构造一个长度为\(N\)并且所有元素和为\(S\)的正整数数组,问是否能找到一个\(K (0\le K \le S)\)使得这个数组的任意_子数组_的和都不 ...

  5. Codeforces Round #501 (Div. 3) F. Bracket Substring

    题目链接 Codeforces Round #501 (Div. 3) F. Bracket Substring 题解 官方题解 http://codeforces.com/blog/entry/60 ...

  6. Codeforces Round #521 (Div. 3) E. Thematic Contests(思维)

    Codeforces Round #521 (Div. 3)  E. Thematic Contests 题目传送门 题意: 现在有n个题目,每种题目有自己的类型要举办一次考试,考试的原则是每天只有一 ...

  7. Codeforces Round #501 (Div. 3)

    A - Points in Segments 题意:implement #include<bits/stdc++.h> using namespace std; typedef long ...

  8. Codeforces Round #501 (Div. 3) 1015A Points in Segments (前缀和)

    A. Points in Segments time limit per test 1 second memory limit per test 256 megabytes input standar ...

  9. 【Codeforces Round #501 (Div. 3)】

    A:https://www.cnblogs.com/myx12345/p/9842904.html B:https://www.cnblogs.com/myx12345/p/9842964.html ...

随机推荐

  1. mybatis入门教程之搭建一个简单的mybatis项目并启动它

    一.准备条件: 1.依赖jar包:mybatis核心包(必须).lombok插件包(非必须)以及MySQL数据库连接驱动包(必须) <dependency> <groupId> ...

  2. Subline Text 3 安装

    Subline Text 3 下载 下载链接 http://www.sublimetext.com/3 ,下载Subline Text3的安装包,这里以 64位的windows10为例,如果是其他操作 ...

  3. 怎么判断innodb 日志缓冲区该设置为多大呢

    怎么判断innodb 日志缓冲区该设置为多大呢

  4. 远程部署项目,修改catalina.bat文件 完美解决在代理服务器上HttpURLConnection 调接口超时的问题

    远程给客户部署项目,运行时程序调外部接口时总是出不去,经过不懈努力,后来发现客户那边的网络走的是代理,于是在代码中加下面代码: //设置代理 System.setProperty("http ...

  5. 同一份数据,Redis为什么要存两次

    前言 在 Redis 中,有一种数据类型,当在存储的时候会同时采用两种数据结构来进行分别存储,那么 Redis 为什么要这么做呢?这么做会造成同一份数据占用两倍空间吗? 五种基本类型之集合对象 Red ...

  6. Ubuntu对接GlusterFS

    存储节点部署示例环境,仅供参考 主机名 IP 系统 gfs01 10.10.10.13 Ubuntu 16.04.3 LTS gfs02 10.10.10.14 Ubuntu 16.04.3 LTS ...

  7. day132:2RenMJ:MJ需求文档&MJ游戏流程&Egret白鹭引擎安装&TypeScript简要介绍

    目录 1.麻将产品需求文档 2.麻将游戏流程 3.Egret白鹭引擎 4.TypeScript简要了解 5.TypeScript快速入门 1.麻将产品需求文档 1.麻将术语 1.名词术语 牌⼦: 序数 ...

  8. MySQL调优之查询优化

    一.查询慢的原因 1.网络 (1)网络丢包,重传 这个比较容易理解.当SQL 从客户端发送到数据库,执行完毕,数据库将结果返回给客户端,这个将数据返回给客户端的过程本质是网络包传输.因为链路的不稳定性 ...

  9. 前置时间(Lead Time),也称前置期、备货周期

    https://wiki.mbalib.com/wiki/前导时间 什么是前导时间 所谓的前导时间(leading time),就是产品从设计,到生产.物流.销售的过程. BELLWETHER:&qu ...

  10. Linux进程内存用量分析之堆内存篇

    https://mp.weixin.qq.com/s/a6mLMDinYQGUSaOsGYCEaA 独家|Linux进程内存用量分析之堆内存篇 姬晨烜 58技术 2019-12-06 导语 本文将介绍 ...