题目链接
题意
对数有这样一个操作,选择a[i]与a[j] 使 a[i]=a[j]=| a[i]-a[j] |
要求判断的数,给出数组的长度,要求判判断能否证明进行操作之后,数组的和不会减小
思路
在我看来是很直观的一道题目,求解不等式 a[i]+a[j]>=|a[i]+a[j]| 算出来的是三倍的关系,我们只需要保证,后者是前者的三倍即可满足,因为数据限制在1e9之内,3^18<1e9<3^19,也就是说n<=18的都可以满足条件,并且主要满足三倍的关系即可。
代码
#include<map>
#include<cmath>
#include<stack>
#include<queue>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#define Endl "\n"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 1e5+5;
const int INF = 0x3f3f3f;
const int mod = 1e9 + 7;
const double pi = acos(-1);
inline ll read(){
ll x = 0, f = 1; char ch; ch = getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
ll n;
void solve() {
n=read();
if(n>19) cout<<"NO"<<Endl;
else
{
cout<<"YES"<<Endl;
int ans=1;
for(int i=1;i<=n;i++)
{
cout<<ans<<" ";
ans*=3;
}
cout<<Endl;
}
return ;
}
int main() {
for(int T = read(); T; T--)
solve();
return 0;
}