• 题意:一共有\(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. Jenkins+windows+.netcore+git+iis自动化部署入门

    什么是自动化部署,就不介绍了,喜欢直接进入主题. 一. 所需环境: 1.系统为windows10 . 2.asp.net core3.1 runtime必须安装,因为我的代码是asp.net core ...

  2. ctfhub技能树—sql注入—时间盲注

    打开靶机 查看页面信息 测试时间盲注 可以看到在执行命令后会有一定时间的等待,确定为时间盲注 直接上脚本 1 #! /usr/bin/env python 2 # _*_ coding:utf-8 _ ...

  3. 二进制部署kubernetes

    Kubernetes二进制安装 环境准备: 主机环境:做好主机名hosts文件映射 硬件2cpu  2G内存 192.168.30.21 k8s-master 192.168.30.22 k8s-no ...

  4. 面试时通过volatile关键字,全面展示线程内存模型的能力

    面试时,面试官经常会通过volatile关键字来考核候选人在多线程方面的能力,一旦被问题此类问题,大家可以通过如下的步骤全面这方面的能力.     1 首先通过内存模型说明volatile关键字的作用 ...

  5. React 入门-redux 和 react-redux

    React 将页面元素拆分成组件,通过组装展示数据.组件又有无状态和有状态之分,所谓状态,可以简单的认为是组件要展示的数据.React 有个特性或者说是限制单向数据流,组件的状态数据只能在组件内部修改 ...

  6. Java中的Date类型无法赋值给数据库的datetime类型

    因为Java中new Date()的结果是"Thu Aug 27 19:03:54 CST 2020",而mysql中的datetime不接受这样的日期格式,插入数据会报错. 解决 ...

  7. js12种应该注意的地方

    1. == Javascript有两组相等运算符,一组是==和!=,另一组是===和!==.前者只比较值的相等,后者除了值以外,还比较类型是否相同. 请尽量不要使用前一组,永远只使用===和!==.因 ...

  8. SMTP 协议发送邮件的整体过程

    使用 SMTP 发送邮件_使用 SMTP 发送邮件_发送邮件_用户指南_邮件推送-阿里云 https://help.aliyun.com/knowledge_detail/51622.html 通过 ...

  9. 为什么要内存对齐?Go 语言有时也需要考虑对齐的问题

    https://mp.weixin.qq.com/s/NE6Y2TVxrl-cpY-36puQcQ

  10. IdentityServer4之Implicit和纯前端好像很配哦

    前言 上一篇Resource Owner Password Credentials模式虽然有用户参与,但对于非信任的第三方的来说,使用这种模式是有风险的,所以相对用的不多:这里接着说说implicit ...