CodeForces - 1523B - Lord of the Values ( 思维 )

题目链接:点击进入
题目

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

题意

长度为 n 的数组,让你把数组里的元素都变成相反数( a [ i ] -> - a [ i ] )两种操作,每次选两个下标:
1、 a [ i ] = a [ i ] + a [ j ] ( i < j )
2、 a [ j ] = a [ j ] − a [ i ] ( i < j )
最多操作 5000 次

思路

题目说 n 一定是偶数,所以多半跟偶数有关系,如果单看两个元素,通过写写画画,对于 a1, a2 ,我们可以得到
2 1 2 : a1 、a2 - a1
1 1 2 : a2 、a2 - a1
1 1 2 : 2a2 - a1 、a2 - a1
2 1 2 : 2a2 - a1 、-a2
1 1 2 : a2 - a1 、-a2
1 1 2 : -a1 、-a2
两个数通过 6 次操作一定可以变为相反数,所以一共需要 n * 3 次

代码
// #pragma GCC optimize("Ofast","inline","-ffast-math")
// #pragma GCC target("avx,sse2,sse3,sse4,mmx")
//#pragma GCC optimize(3)//O3
//#pragma GCC optimize(2)//O2
//#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<map>
#include<set>
//#include<unordered_map>
#include<queue>
#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<bitset>
#include<fstream>
#define X first
#define Y second
#define best 131 
#define INF 0x3f3f3f3f3f3f3f3f
#define pii pair<int,int>
#define lowbit(x) x & -x
#define inf 0x3f3f3f3f
#define max(a,b) a>b?a:b
#define min(a,b) a<b?a:b
//#define int long long
//#define double long double
//#ifndef ONLINE_JUDGE  freopen("data.in.txt","r",stdin);
//freopen("data.out.txt","w",stdout); #endif //文件读取 
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double pai=acos(-1.0);
const int Mod=998244353;
const double eps=1e-9;
const int N=26;
const int mod=51123987;
const int maxn=1e6+10;

/*--------------------------------------------*/ 
inline int read()
{
    int data=0,w=1; char ch=0;
    while(ch!='-' && (ch<'0' || ch>'9')) ch=getchar();
    if(ch=='-') w=-1,ch=getchar();
    while(ch>='0' && ch<='9') data=data*10+ch-'0',ch=getchar();
    return data*w;
}
/*--------------------------------------------*/

int t,n,m,a[maxn];
string s;

int main()																						
{	
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	cin>>t;
	while(t--)
	{
		cin>>n;
		for(int i=1;i<=n;i++)
			cin>>a[i];
		cout<<n*3<<endl;
		for(int i=1;i<=n;i+=2)
		{
			cout<<2<<' '<<i<<' '<<i+1<<endl;
			cout<<1<<' '<<i<<' '<<i+1<<endl;
			cout<<1<<' '<<i<<' '<<i+1<<endl;
			cout<<2<<' '<<i<<' '<<i+1<<endl;
			cout<<1<<' '<<i<<' '<<i+1<<endl;
			cout<<1<<' '<<i<<' '<<i+1<<endl;
		}
	}
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值