【日常训练赛】C - Prove Him Wrong

题目链接

Problem - 1651B - Codeforces

题意

对数有这样一个操作,选择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;
} 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值