0
点赞
收藏
分享

微信扫一扫

C. Multiples of Length(思维问题) Codeforces Round #666 (Div. 2)

原题链接: ​​https://codeforces.com/contest/1397/problem/C​​

C. Multiples of Length(思维问题)  Codeforces Round #666 (Div. 2)_#define
测试样例:

input
4
1 3 2 4
output
1 1
-1
3 4
4 2
2 4
-3 -6 -6

题意: 给你一个整数序列,你需要找出三步操作使得整数序列的所有元素都变为0。

解题思路: 对于长度为1的整数序列,我们自然可以知道怎么处理。那么大于1的整数序列呢?我们想想,我们是可以给区间C. Multiples of Length(思维问题)  Codeforces Round #666 (Div. 2)_#define_02中的每个元素都加上C. Multiples of Length(思维问题)  Codeforces Round #666 (Div. 2)_ios_03的倍数的值。那么,如果我是加上每个元素对应的相反数的倍数,那么每个元素都会变成什么?没错它们的值都变为C. Multiples of Length(思维问题)  Codeforces Round #666 (Div. 2)_#define_04,那么如果我再对C. Multiples of Length(思维问题)  Codeforces Round #666 (Div. 2)_#define_05中的加上C. Multiples of Length(思维问题)  Codeforces Round #666 (Div. 2)_#define_06的倍数的值。那么这个区间中的数是不是都变为了0,这里我们用去了两个操作,还剩下一个操作我们自然是用来将第区间右端点C. Multiples of Length(思维问题)  Codeforces Round #666 (Div. 2)_i++_07的值变为0,这我们好办。OK,那么此问题自然已解决,对于区间C. Multiples of Length(思维问题)  Codeforces Round #666 (Div. 2)_思维_08我们这样处理自然可以三步使得整数序列元素都变为0。具体看代码。

AC代码:

/*

*注:文章若有任何问题请私信我或评论区留言,谢谢支持。
*
*/
#include<bits/stdc++.h> //POJ不支持

#define rep(i,a,n) for (int i=a;i<=n;i++)//i为循环变量,a为初始值,n为界限值,递增
#define per(i,a,n) for (int i=a;i>=n;i--)//i为循环变量, a为初始值,n为界限值,递减。
#define pb push_back
#define IOS ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define fi first
#define se second
#define mp make_pair

using namespace std;

const int inf = 0x3f3f3f3f;//无穷大
const int maxn = 1e5+3;//最大值。
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
//*******************************分割线,以上为自定义代码模板***************************************//

ll n,a[maxn];
int main(){
//freopen("in.txt", "r", stdin);//提交的时候要注释掉
IOS;
while(cin>>n){
rep(i,1,n)
cin>>a[i];
if(n==1){
rep(i,0,1){
cout<<"1 1"<<endl;
cout<<0<<endl;
}
cout<<"1 1"<<endl;
cout<<(-1)*a[1]<<endl;
}
else{
//让前n-1个数都变成它们的(n-1)*(-1)倍。
//再让前n-1个数变成0.
//最后对第n个数进行处理。
cout<<"1 "<<n<<endl;
rep(i,1,n){
cout<<(-1)*a[i]*n<<" ";
}
cout<<endl;
cout<<"1 "<<n-1<<endl;
rep(i,1,n-1){
cout<<a[i]*(n-1)<<" ";
}
cout<<endl;
cout<<n<<" "<<n<<endl;
cout<<a[n]*(n-1)<<endl;
}
}
return 0;
}


举报

相关推荐

0 条评论