Codeforces Round #667 (Div. 3) C. Yet Another Array Restoration (数学)

题意:给你两个数字\(x\)和\(y\),让你构造一个长度为\(n\)的序列,要求包含\(x\)和\(y\),并且排序后相邻两项的差值相等.
题解:有排序后相邻两项的差值相等可知,构造的序列排序后一定是一个等差数列,而题目给的\(x\)和\(y\)的范围很小,所以我们可以从\([1,50]\)来枚举公差\(d\),这个\(d\)必须要能整除\(x\)和\(y\)的差值,并且\([x,y]\)的所有数的个数整除\(d\)上取整后不大于\(n\),这样找到的第一个\(d\),一定是最优解,直接构造输出即可.
代码:
int t;
int n,x,y; int main() {
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
t=read();
while(t--){
n=read();
x=read();
y=read();
int d;
for(int i=1;i<=50;++i){
if((y-x)%i==0 && (y-x+1-1)/i+1<=n){
d=i;
break;
}
}
for(int i=x;i<=y;i+=d){
if(n>0){
n--;
printf("%d ",i);
}
}
for(int i=x-d;i>=1;i-=d){
if(n>0){
n--;
printf("%d ",i);
}
}
for(int i=1;i<=n;++i){
printf("%d ",y+i*d);
}
puts("");
} return 0;
}
Codeforces Round #667 (Div. 3) C. Yet Another Array Restoration (数学)的更多相关文章
- Codeforces Round #667 (Div. 3)
比赛链接:https://codeforces.com/contest/1409 A. Yet Another Two Integers Problem 题意 给出两个数 $a$ 和 $b$,有以下两 ...
- Codeforces Round #667 (Div. 3) B、C、D、E 题解
抱歉B.C题咕了这么久 B. Minimum Product #枚举 #贪心 题目链接 题意 给定四个整数\(a, b, x, y\),其中\(a\geq x, b\geq y\),你可以执行不超过\ ...
- Codeforces Round #667 (Div. 3) E. Two Platforms (双指针)
题意:有\(n\)个点往下落,你可以在最下面放两个长度为\(k\)的板子,问做多能接到多少个点. 题解:这题给纵坐标\(y\)完全没有用,我们先对横坐标\(x\)排序,然后从左边开始枚举,用\(l[i ...
- Codeforces Round #667 (Div. 3) D. Decrease the Sum of Digits (贪心)
题意:给你一个正整数\(n\),每次可以对\(n\)加一,问最少操作多少次是的\(n\)的所有位数之和不大于\(s\). 题解:\(n\)的某个位置上的数进位,意味这后面的位置都可以被更新为\(0\) ...
- Codeforces Round #667 (Div. 3) B. Minimum Product (贪心,数学)
题意:给你\(a\)和\(b\)两个数,每次操作可以是任意一个数\(-1\),最多操作\(n\),并且\(a\ge x\),\(b\ge y\),求操作后\(a*b\)的最小值. 题解:观察样例并且在 ...
- Codeforces Round #404 (Div. 2) D. Anton and School - 2 数学
D. Anton and School - 2 题目连接: http://codeforces.com/contest/785/problem/D Description As you probabl ...
- Codeforces Round #304 (Div. 2) D. Soldier and Number Game 数学 质因数个数
D. Soldier and Number Game Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/conte ...
- Codeforces Round #384 (Div. 2)B. Chloe and the sequence 数学
B. Chloe and the sequence 题目链接 http://codeforces.com/contest/743/problem/B 题面 Chloe, the same as Vla ...
- Codeforces Round #342 (Div. 2) A - Guest From the Past 数学
A. Guest From the Past 题目连接: http://www.codeforces.com/contest/625/problem/A Description Kolya Geras ...
随机推荐
- zabbix 4.X 版本 web字体显示方块
先看看问题长啥样...... Zabbix 字体乱码(显示呈现方块) 第一种解决方法: # 1) 进入代码存放目录的字体目录: cd /data/www/zabbix/assets/fonts # 2 ...
- Celery--短信与邮件
1 Celery 实现短信--邮件 1.1 容联云-短信 from ronglian_sms_sdk import SmsSDK accountSid = '8a216da8757784cd01759 ...
- 技术实践丨React Native 项目 Web 端同构
摘要:尽管 React Native 已经进入开源的第 6 个年头,距离发布 1.0 版本依旧是遥遥无期."Learn once, write anywhere",完全不影响 Re ...
- 【Linux】ssh设置了密钥,但ssh登陆的时候还需要输入密码
------------------------------------------------------------------------------------------------- | ...
- kubernets之机理概览
一 了解kubernets的运行机理 1.1 了解架构 众所周知,kubernets的组成由2个部分组成 kubernets 平面 node节点 (工作节点) 控制平面的组成 etcd 分布 ...
- linux DRM GPU scheduler 笔记
内核文档: Overview The GPU scheduler provides entities which allow userspace to push jobs into softw ...
- 鸿蒙的fetch请求加载聚合数据的前期准备工作-手动配置网络权限
目录: 1.双击打开"config.json"文件 2.找到配置网络访问权限位置1 3.配置内容1 4.默认访问内容是空的 5.添加配置内容2 6.复制需要配置的网络二级URL 7 ...
- 论super().__init__()的用法
当我们调用 super() 的时候,实际上是实例化了一个 super 类. super 是个类,既不是关键字也不是函数等其他数据结构,该对象就是专门用来访问父类中的属性的(严格按照继承的关系). -- ...
- codeup 1934 查找元素
题目描述: 输入一个数n,然后输入n个数值各不相同,再输入一个值x,输出这个值在这个数组中的下标(从0开始,若不在数组中则输出-1. 输入: 测试数据有多组,输入n(1<=n<=200), ...
- Crunch
Crunch 目录 1. 简介 2. 命令格式 3. options可选参数 3.1 -b number[type] 3.2 -c number 3.3 -d numbersymbol 3.4 -e ...