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 ...
随机推荐
- CreateProcess函数源码分析
CreateProcess函数源码分析 源码版本:Windows 2003 源码 源码阅读工具:Source Insight 函数功能分析 函数原型 BOOL CreateProcessA( ...
- parser.add_argument()用法——命令行选项、参数和子命令解析器
argparse是一个Python模块:命令行选项.参数和子命令解析器.通过使用这种方法,可以在使用 1.argparse简介: argparse 模块是 Python 内置的一个用于命令项选项与参数 ...
- Typora Mac中文破解版获取
作为程序员,markdown是非常好用的文本编辑语言,而Typora是非常好用的一款markdown编辑工具.Typora提供读者和作家的无缝体验.它删除了预览窗口,模式切换器,降低源代码的语法符号以 ...
- 9.文件和异常--《Python编程:从入门到实践》
9.1 从文件中读取数据 要使用文本文件中的信息,首先需要将信息读取到内存中.为此,你可以一次性读取文件的全部内容,也可以以每次一行的方式逐步读取. 9.1.1 读取整个文件 with open( ...
- Hive中insert into 和 insert overwrite的区别
相同点 insert into 和 insert overwrite 都是往表中插入数据的. 不同点 区别1: insert into :其实是将数据追加到表的末尾,注意:不是覆盖,是追加. inse ...
- JS leetcode 至少是其他数字的两倍的最大数 解答思路分析
壹 ❀ 引 刷leetcode的第二天,那么今天做的也是一道难度为简单的题目至少是其他数字的两倍的最大数,老规矩,先说说我的实现思路后,再来分析优质答案,原题如下: 在一个给定的数组nums中,总是存 ...
- NC24953 [USACO 2008 Jan G]Cell Phone Network
题目链接 题目 题目描述 Farmer John has decided to give each of his cows a cell phone in hopes to encourage the ...
- 轻松玩转makefile|基础知识
1.什么是Makefile 在嵌入式软件开发领域,使用 make 工具构建开发环境是非常常见的.而要使用 make 工具,就需要编写 Makefile 文件来定义一系列规则,指定需要先编译.后编译 ...
- python绘图总结
1 二维图像 1.1 二维曲线 plot(x, y, ls="-", lw=1.5, label=None) x, y:横坐标和纵坐标 ls:颜色.点标记.线型列表,如 ls='r ...
- Oracle 分析函数详解(Analytic Functions)--示例部分
Analytic functions are commonly used in data warehousing environments. In the list of analytic funct ...