Educational Codeforces Round 158 (Rated for Div. 2)C. Add, Divide and Floor(思维/数学)
C. Add, Divide and Floor
这里我们选择固定最小数不变,然后每次让其他数向最小数靠近,模拟一下可以发现,只要最大值变为和最小值一样,其他都会和最小值一样。
#include <bits/stdc++.h>
#define rep(i,a,b) for(register int i = (a); i <= (b); ++i)
#define fep(i,a,b) for(register int i = (a); i >= (b); --i)
#define ls p<<1
#define rs p<<1|1
#define PII pair<int, int>
#define ll long long
#define ull unsigned long long
#define db double
#define endl '\n'
#define debug(a) cout<<#a<<"="<<a<<endl;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define INF 0x3f3f3f3f
using namespace std;
const int N = 2e5+10;
int t;
int p[40];
void solve()
{
int n, maxx=-INF, minn=INF; cin >> n;
rep(i,1,n)
{
int x; cin >> x;
maxx=max(x, maxx);
minn=min(x, minn);
}
vector<int>a;
while(maxx != minn)
{
maxx = (maxx+minn)/2;
a.push_back(minn);
}
if(a.size() <= n)
{
cout << a.size() << endl;
for(auto x : a) cout << x << ' ';
cout << endl;
}
else cout << a.size() << endl;
}
int main()
{
IOS
// freopen("1.in", "r", stdin);
cin >> t;
while(t --)
solve();
return 0;
}
Educational Codeforces Round 158 (Rated for Div. 2)C. Add, Divide and Floor(思维/数学)的更多相关文章
- Educational Codeforces Round 37 (Rated for Div. 2)C. Swap Adjacent Elements (思维,前缀和)
Educational Codeforces Round 37 (Rated for Div. 2)C. Swap Adjacent Elements time limit per test 1 se ...
- Educational Codeforces Round 89 (Rated for Div. 2) A. Shovels and Swords(贪心/数学)
题目链接:https://codeforces.com/contest/1366/problem/A 题意 有两个数 $a$ 和 $b$,每次可以选择从一个数中取 $2$,另一个数中取 $1$,问最多 ...
- Educational Codeforces Round 61 (Rated for Div. 2)F(区间DP,思维,枚举)
#include<bits/stdc++.h>typedef long long ll;const int inf=0x3f3f3f3f;using namespace std;char ...
- Educational Codeforces Round 78 (Rated for Div. 2) B - A and B(思维)
- Educational Codeforces Round 72 (Rated for Div. 2)E(线段树,思维)
#define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;#define BUF_SIZE 100000 ...
- Educational Codeforces Round 96 (Rated for Div. 2) E. String Reversal 题解(思维+逆序对)
题目链接 题目大意 给你一个长度为n的字符串,可以交换相邻两个元素,使得这个字符串翻转,求最少多少种次数改变 题目思路 如果要求数组排序所需要的冒泡次数,那其实就是逆序对 这个也差不多,但是如果是相同 ...
- Educational Codeforces Round 88 (Rated for Div. 2) E、Modular Stability 逆元+思维
题目链接:E.Modular Stability 题意: 给你一个n数,一个k,在1,2,3...n里挑选k个数,使得对于任意非负整数x,对于这k个数的任何排列顺序,然后用x对这个排列一次取模,如果最 ...
- Educational Codeforces Round 69 (Rated for Div. 2) D. Yet Another Subarray Problem 【数学+分块】
一.题目 D. Yet Another Subarray Problem 二.分析 公式的推导时参考的洛谷聚聚们的推导 重点是公式的推导,推导出公式后,分块是很容易想的.但是很容易写炸. 1 有些地方 ...
- Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship
Problem Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...
- Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)
Problem Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...
随机推荐
- 初试高云FPGA
前言 之前一直眼馋Sipeed的Tang系列,正好遇到有工程需要高速控制并行总线,就买了NANO 9K和Primer 20K试试水 买回来先拆的贵的20k,结果发现Sipeed设计师有奇怪的脑回路: ...
- Linux 应用Kickstart部署系统
Kickstart 是一种无人值守系统安装方式,其工作原理是预先把原本需要运维人员手工填写的参数保存成文件,当安装过程中需要填写参数时则自动匹配Kickstart生成的文件,所以只要文件内包含了安装过 ...
- 【STL源码剖析】list::sort真的好用吗?Centos7-Linux环境g++Release下vector数组排序和list排序效率测试【超详细的注释和解释】
说在前面的话 在使用C++的标准模板库的一些容器时,我们难免会遇到给序列排序的问题. 在学习list的时候,我们可能会了解到,algorithm::sort其实不是万能的. 当我们要给list排序的时 ...
- Leetcode刷题第五天-二分法-回溯
215:第k个最大元素 链接:215. 数组中的第K个最大元素 - 力扣(LeetCode) em~~怎么说呢,快速选择,随机定一个目标值,开始找,左边比目标小,右边比目标大,左右同时不满足时,交换左 ...
- php批量更新多条数据
/** * @param $table 表名 * @param array $multipleData 拼接的批量更新的数组格式: * $students = [['id' => 1, 'cit ...
- Delphi-判断一个对象是否释放,改造官方的Assigned
直接上例子了,基础知识自己去了解,首先定义一个类: TPerson = class public name: string; age: Integer; constructor Create(name ...
- JDK + Tomcat 安装 + 制作自定义镜像【第 2.1 篇 Tomcat 日志满问题】
更好的方法,跨平台(不依赖平台,比如阿里云的后台)的方法是:spring boot 定时任务,直接在程序里写定时清除日志的任务:以后再说: ============================== ...
- SQLWorkbench使用自定义JDBC驱动连接数据库
一.Windows上使用SQLWorkbench 1. 添加CloudDB的驱动,点击"Manage Driver". Name : Fandatsys-CDB sample U ...
- UUID算法:独一无二的标识符解决方案
引言 在分布式系统和大数据环境下,唯一标识符的生成和管理是一项关键任务.UUID(Universally Unique Identifier)算法应运而生,成为了解决重复数据和标识符冲突的有效工具.本 ...
- JS Leetcode 74. 搜索二维矩阵题解分析,二分法与坐标轴法
壹 ❀ 引 本题来自Leetcode74. 搜索二维矩阵,虽然难度是中等,但如果站在做出来的角度,你会发现其实并不难,题目描述如下: 编写一个高效的算法来判断 m x n 矩阵中,是否存在一个目标值. ...