B. Lord of the Values- Deltix Round, Spring 2021 (open for everyone, rated, Div. 1 + Div. 2)

题目链接Problem - B - Codeforces

B. Lord of the Values

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

While trading on his favorite exchange trader William realized that he found a vulnerability. Using this vulnerability he could change the values of certain internal variables to his advantage. To play around he decided to change the values of all internal variables from a1,a2,…,ana1,a2,…,an to −a1,−a2,…,−an−a1,−a2,…,−an. For some unknown reason, the number of service variables is always an even number.

William understands that with his every action he attracts more and more attention from the exchange's security team, so the number of his actions must not exceed 50005000 and after every operation no variable can have an absolute value greater than 10181018. William can perform actions of two types for two chosen variables with indices ii and jj, where i<ji<j:

  1. Perform assignment ai=ai+ajai=ai+aj
  2. Perform assignment aj=aj−aiaj=aj−ai

William wants you to develop a strategy that will get all the internal variables to the desired values.

Input

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤201≤t≤20). Description of the test cases follows.

The first line of each test case contains a single even integer nn (2≤n≤1032≤n≤103), which is the number of internal variables.

The second line of each test case contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤109)(1≤ai≤109), which are initial values of internal variables.

Output

For each test case print the answer in the following format:

The first line of output must contain the total number of actions kk, which the strategy will perform. Note that you do not have to minimize kk. The inequality k≤5000k≤5000 must be satisfied.

Each of the next kk lines must contain actions formatted as "type i j", where "type" is equal to "1" if the strategy needs to perform an assignment of the first type and "2" if the strategy needs to perform an assignment of the second type. Note that i<ji<j should hold.

We can show that an answer always exists.

Example

input

Copy

2
4
1 1 1 1
4
4 3 1 2

output

Copy

8
2 1 2
2 1 2
2 1 3
2 1 3
2 1 4
2 1 4
1 1 2
1 1 2
8
2 1 4
1 2 4
1 2 4
1 2 4
1 3 4
1 1 2
1 1 2
1 1 4

Note

For the first sample test case one possible sequence of operations is as follows:

  1. "2 1 2". Values of variables after performing the operation: [1, 0, 1, 1]
  2. "2 1 2". Values of variables after performing the operation: [1, -1, 1, 1]
  3. "2 1 3". Values of variables after performing the operation: [1, -1, 0, 1]
  4. "2 1 3". Values of variables after performing the operation: [1, -1, -1, 1]
  5. "2 1 4". Values of variables after performing the operation: [1, -1, -1, 0]
  6. "2 1 4". Values of variables after performing the operation: [1, -1, -1, -1]
  7. "1 1 2". Values of variables after performing the operation: [0, -1, -1, -1]
  8. "1 1 2". Values of variables after performing the operation: [-1, -1, -1, -1]

For the second sample test case one possible sequence of operations is as follows:

  1. "2 1 4". Values of variables after performing the operation: [4, 3, 1, -2]
  2. "1 2 4". Values of variables after performing the operation: [4, 1, 1, -2]
  3. "1 2 4". Values of variables after performing the operation: [4, -1, 1, -2]
  4. "1 2 4". Values of variables after performing the operation: [4, -3, 1, -2]
  5. "1 3 4". Values of variables after performing the operation: [4, -3, -1, -2]
  6. "1 1 2". Values of variables after performing the operation: [1, -3, -1, -2]
  7. "1 1 2". Values of variables after performing the operation: [-2, -3, -1, -2]
  8. "1 1 4". Values of variables after performing the operation: [-4, -3, -1, -2]
  9. ----------------------------------------------------------------------------------------------------------------

本题察点其实是dfs和一些思维,当然不是说本题要用dfs,我们只是借助dfs找寻规律;题目给

出的条件就很有暗示性,说是偶数个元素,其实元素本身随机,如果真要随机找元素结合那么这个题也别做了,根本做不出来。这就暗示我们两两结合一定能产生结果。我们随机测了大量数据,发现dfs打出来的结果有八种,为了不越界,我们选取了 1 2 1 1 2 1这种

# include<iostream>
using namespace std;
typedef  long long int ll;
ll ans[1000];
int cnt=6;
 ll a,b;
void dfs(ll nowa,ll nowb,int nowcnt,int step)
{
    if(nowcnt>cnt)
        return  ;
    if(nowa==-a&&nowb==-b)
    {
        for(int i=0;i<step;i++)
        {
            cout<<ans[i]<<" ";
        }

        cout<<endl;
    }



         ans[step]=1;
        dfs(nowa+nowb,nowb,nowcnt+1,step+1);




         ans[step]=2;
        dfs(nowa,nowb-nowa,nowcnt+1,step+1);


}
int main ()
{

    cin>>a>>b;


    dfs(a,b,0,0);
    return 0;
}
#include<iostream>
#include<stack>
#include<string>
using namespace std;



int main ()
{



   int t;
   cin>>t;
   
   while(t--)
   {
       int n;
       cin>>n;
       int x;
       for(int i=1;i<=n;i++)
        cin>>x;
       
       cout<<3*n<<'\n';
       for(int i=1;i<=n;i+=2)
       {
           cout<<1<<" "<<i<<" "<<i+1<<'\n';
             cout<<2<<" "<<i<<" "<<i+1<<'\n';
               cout<<1<<" "<<i<<" "<<i+1<<'\n';
                 cout<<1<<" "<<i<<" "<<i+1<<'\n';
                   cout<<2<<" "<<i<<" "<<i+1<<'\n';
                     cout<<1<<" "<<i<<" "<<i+1<<'\n';
                     
       }
   }




    return 0;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

秦三码

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

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

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

打赏作者

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

抵扣说明:

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

余额充值