Codeforces Round #501 (Div. 3) D. Walking Between Houses (思维,构造)
题意:一共有\(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 (思维,构造)的更多相关文章
- 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 ...
- 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 ...
- Codeforces Round #501 (Div. 3) B. Obtaining the String (思维,字符串)
题意:有两个字符串\(S\)和\(T\),判断\(T\)是否能由\(S\)通过交换某位置的相邻字符得到,如果满足,输出交换次数及每次交换的位置,否则输出\(-1\). 题解:首先判断不满足的情况,只有 ...
- Codeforces Round #643 (Div. 2) D. Game With Array (思维,构造)
题意:给你两个正整数\(N\)和\(S\),构造一个长度为\(N\)并且所有元素和为\(S\)的正整数数组,问是否能找到一个\(K (0\le K \le S)\)使得这个数组的任意_子数组_的和都不 ...
- Codeforces Round #501 (Div. 3) F. Bracket Substring
题目链接 Codeforces Round #501 (Div. 3) F. Bracket Substring 题解 官方题解 http://codeforces.com/blog/entry/60 ...
- Codeforces Round #521 (Div. 3) E. Thematic Contests(思维)
Codeforces Round #521 (Div. 3) E. Thematic Contests 题目传送门 题意: 现在有n个题目,每种题目有自己的类型要举办一次考试,考试的原则是每天只有一 ...
- Codeforces Round #501 (Div. 3)
A - Points in Segments 题意:implement #include<bits/stdc++.h> using namespace std; typedef long ...
- 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 ...
- 【Codeforces Round #501 (Div. 3)】
A:https://www.cnblogs.com/myx12345/p/9842904.html B:https://www.cnblogs.com/myx12345/p/9842964.html ...
随机推荐
- idea中文注释出现乱码,我靠自己解决了
如果你像我一样️,查遍google百度,半天下来还是找不到解决方案,说不定这篇博客能帮助你顺利解决呢 好了,那么开始说说我是怎么解决麻烦的. 首先,我想打开一份java文稿.光预览,它是没有任何问题的 ...
- Docker构建Python Web环境
出于寻找Docker对Python相关项目部署的学习,找到腾讯课堂NEXT公开课中[Docker构建Python Web环境]的课程,本文对其进行内容梳理及知识点汇总. 该课程总计6小时左右,是个适合 ...
- 【Oracle】DRM官方介绍
DRM 简介 By: Allen Gao 首先,我们对和DRM 相关的一些概念进行介绍. Buffer: 对于RAC 数据库,当一个数据块被读入到buffer cache后,我们就称其为buffer ...
- ctfshow—web—web3
打开靶机 提示是文件包含漏洞 测试成功 https://d7c9f3d7-64d2-4110-a14b-74c61f65893c.chall.ctf.show/?url=../../../../../ ...
- os.system('cmd')在linux和windows系统下返回值的差异
今天,用os.system('cmd')分别在windows和linux平台上执行同一ping命令,命令执行失败时返回码不同,windows为1,而linux下返回为256,如下: linux下: & ...
- Pandas的数据分组-aggregate聚合
在对数据进行分组之后,可以对分组后的数据进行聚合处理统计. agg函数,agg的形参是一个函数会对分组后每列都应用这个函数. import pandas as pd import numpy as n ...
- python中hmac模块的使用
hmac(hex-based message authentication code)算法在计算哈希的过程中混入了key(实际上就是加盐),和hashlib模块中的普通加密算法相比,它能够防止密码被撞 ...
- ECC 6 debuging中create points
2013-12-07 今天无意中,发现,在ECC6中debug的时候,创建动态断点,对于command中的delete from语句居然无效,唉 虽然设置了DELETE 和DELETE FROM两个动 ...
- idea 启动热部署Devtolls
1.在子工程pom.xml中添加devtools jar包到需要启动的项目中 1 <dependency> 2 <groupId>org.springframework.boo ...
- Centos 安装postgreSQL9.4.3
rpm -ivh http://download.postgresql.org/pub/repos/yum/9.4/redhat/rhel-7.2-x86_64/pgdg-centos94-9.4-3 ...