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|a[i]-a[i-1]|,a[0]=1∑i=1n∣a[i]−a[i−1]∣,a[0]=1。
思路:遍历每一步,找到当前能走的步数的最大可能,然后走就好了。
写这个博客是因为看cf的时候,有个远古题没补。。好像是去年暑假的题了。。今天翻出来补了一下,发现现在的思路明显比当时清晰,好像真的进步了一点点,雾,要加油!!
#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mp make_pair
#define pb push_back
using namespace std;
LL gcd(LL a,LL b){return b?gcd(b,a%b):a;}
LL lcm(LL a,LL b){return a/gcd(a,b)*b;}
LL powmod(LL a,LL b,LL MOD){LL ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
LL n,k,s;
int main(){
ios::sync_with_stdio(false);
cin>>n>>k>>s;
LL sum=0,pre=1;
if((k*(n-1))<s||k>s)return cout<<"NO\n",0;
cout<<"YES\n";
for(int i=1;i<=k;i++){
LL need=s-sum-(k-i);
need=min(need,n);
need=min(need,max(pre-1,n-pre));
if(need+pre<=n)pre+=need,cout<<pre<<' ';
else pre-=need,cout<<pre<<' ';
sum+=need;
}
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\)次,每次访问的距离是\(|x-y|\),每次都不能停留,问是否能使访问的总距离为\(s\),若能,输出\(YES\)和每次访问的房屋,反正输出\(NO ...
- Codeforces Round #501 (Div. 3) F. Bracket Substring
题目链接 Codeforces Round #501 (Div. 3) F. Bracket Substring 题解 官方题解 http://codeforces.com/blog/entry/60 ...
- 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 ...
- Codeforces Round #501 (Div. 3) B. Obtaining the String (思维,字符串)
题意:有两个字符串\(S\)和\(T\),判断\(T\)是否能由\(S\)通过交换某位置的相邻字符得到,如果满足,输出交换次数及每次交换的位置,否则输出\(-1\). 题解:首先判断不满足的情况,只有 ...
- Codeforces Round #552 (Div. 3) 题解
Codeforces Round #552 (Div. 3) 题目链接 A. Restoring Three Numbers 给出 \(a+b\),\(b+c\),\(a+c\) 以及 \(a+b+c ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
随机推荐
- 10分钟,AppCan帮你搞定跨平台开发APP问题!
跨平台开发APP时,开发者总会遇到一些问题,如打包失败等等,尤其对于iOS来说,由于它的限制性会导致一些状况发生(如证书上传问题等),小编总结了几个AppCan在线IOS打包失败常见的情况及排查技巧, ...
- 011_如何decode url及图片转为base64文本编码总结
一.咱们经常会遇到浏览器给encode后的url,如何转换成咱们都能识别的url呢?很简单,talk is easy,Please show me your code,如下所示: (1)英文decod ...
- STM32F40G-EVAL_UC/OS III
micrum官网下载uc/os程序包: 包含文件cotex_M4.h:
- Linux笔记-nohup和&
nohup:忽略SIGHUP信号,当关闭shell之后,程序仍然执行,但是如果在shell中 ctrl+c,会结束程序 &:忽略SIGINT信号,程序后台执行,在shell中 ctrl+c,程 ...
- vs2017创建.net core 应用程序,发布到Linux
1.打开vs2017,创建.net core 应用程序 压缩上传到linux
- H5 百度一下,你就知道
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- auth mysql
DROP TABLE IF EXISTS tky_auth_role;CREATE TABLE tky_auth_role ( roleid MEDIUMINT (8) UNSIGNED NOT NU ...
- 时间插件--daterangepicker使用和配置详解
1.序言: daterangepicker是Bootstrap的一个时间组件,使用很方便 用于选择日期范围的JavaScript组件. 设计用于Bootstrap CSS框架. 它最初是为了改善报表而 ...
- 转 spring注解式参数校验
转自: https://blog.csdn.net/jinzhencs/article/details/51682830 转自: https://blog.csdn.net/zalan01408980 ...
- Docker 容器日志格式化
Docker容器的日志文件每一行都是一个json对象,其包含log.stream.time三个属性,下面的HTML从textarea中读取输入的日志信息,格式化为表格显示. <!DOCTYPE ...