Educational Codeforces Round 158 (Rated for Div. 2)C. Add, Divide and Floor(思维/数学)

C. Add, Divide and Floor
这里我们选择固定最小数不变,然后每次让其他数向最小数靠近,模拟一下可以发现,只要最大值变为和最小值一样,其他都会和最小值一样。

#include  
#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;
}

你可能感兴趣的:(codeforces,c语言,算法,数据结构)