A. Specific Tastes of Andre(构造)Codeforces Round #682 (Div. 2)

原题链接; http://codeforces.com/contest/1438/problem/A

在这里插入图片描述
测试样例

input
3
1
2
4
output
24
19 33
7 37 79 49

Note

Array [19,33] is perfect as all 3 its subarrays: [19], [33], [19,33], have sums divisible by their lengths, and therefore are good.

题意: 定义一个好数组如下:

如果一个数组的和能整除这个数组的长度,那么这个数组就是好数组。

现在你需要构建长度为 n n n的这个的一个数组 a a a,它的子序列都满足好子数组的条件。

解题思路: 一道构造问题,看起来比较难,但我们想想是放在div2中的A题,便可以想到应该是有特殊的构造方法。我们来想一想,如果一个数组中的所有元素都是相同的,那么这个数组是不是必是好数组,假设数组元素为 a a a,那么对于长度为 n n n的数组其和必为 n ∗ a n*a na,必能整除。 所以我们只要构建一个长度为 n n n的所有元素都相同的 a a a数组即可。

AC代码

/*
*邮箱:unique_powerhouse@qq.com
*blog:https://me.csdn.net/hzf0701
*注:文章若有任何问题请私信我或评论区留言,谢谢支持。
*
*/
#include<bits/stdc++.h>//POJ不支持

#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,a,n) for(int i=a;i>=n;i--)

using namespace std;

const int inf=0x3f3f3f3f;//无穷大。
const int maxn=1e5;//限定值。
typedef long long ll;

int t,n;
int main(){
	while(cin>>t){
		while(t--){
			cin>>n;
			rep(i,0,n-1){
				cout<<"1 ";
			}
			cout<<endl;
		}
	}
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

HeZephyr

你的鼓励是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值