CodeForces - 1042C (emmmmmm水题)

You are given an array aa consisting of nn integers. You can perform the following operations with it:

  1. Choose some positions ii and jj (1≤i,j≤n,i≠j1≤i,j≤n,i≠j), write the value of ai⋅ajai⋅aj into the jj-th cell and remove the number from the ii-th cell;
  2. Choose some position ii and remove the number from the ii-th cell (this operation can be performed no more than once and at any point of time, not necessarily in the beginning).

The number of elements decreases by one after each operation. However, the indexing of positions stays the same. Deleted numbers can't be used in the later operations.

Your task is to perform exactly n−1n−1 operations with the array in such a way that the only number that remains in the array is maximum possible. This number can be rather large, so instead of printing it you need to print any sequence of operations which leads to this maximum number. Read the output format to understand what exactly you need to print.

Input

The first line contains a single integer nn (2≤n≤2⋅1052≤n≤2⋅105) — the number of elements in the array.

The second line contains nn integers a1,a2,…,ana1,a2,…,an (−109≤ai≤109−109≤ai≤109) — the elements of the array.

Output

Print n−1n−1 lines. The kk-th line should contain one of the two possible operations.

The operation of the first type should look like this: 1 ik jk1 ik jk, where 11 is the type of operation, ikik and jkjk are the positions of the chosen elements.

The operation of the second type should look like this: 2 ik2 ik, where 22 is the type of operation, ikik is the position of the chosen element. Note that there should be no more than one such operation.

If there are multiple possible sequences of operations leading to the maximum number — print any of them.

 

      有一tuo数量为n的数列,你有两种操作,一种是删掉某个位置的值,一个是吧i位置的数乘到j位置上,再把i位置上的数删除,求怎么样操作能使最后留下的数最大~~。对了。。删除操作只能用一次;

      通过贪心可得出,这个删除操作一定是用在删除0以及(奇数上那个的负数)而造成的影响上,所以把所有的0以及最大的负数(负数数量为奇数时)乘起来再删掉就行了。其他的按步骤操作即可。

#include<bits/stdc++.h>
using namespace std;
const int inf =0x3f3f3f3f;
int n,m[200005];
int main(){
    scanf("%d",&n);
    int fsum=0;int minn=-0x3f3f3f3f;
    int zero=0;
    for(int i=1;i<=n;i++){
        scanf("%d",&m[i]);
        if(m[i]==0){
            zero++;
        }
        if(m[i]<0){
            minn=max(minn,m[i]);
            fsum++;
        }
    }
    if(fsum%2){
        int za=inf;int a=inf;
        int spot=1,res=0;
        for(int i=1;i<=n;i++){
            if(m[i]==0||(m[i]==minn&&spot==1)){
                if(m[i]==minn){
                    spot=0;
                }
                if(za==inf){
                    za=i;
                }
                else{
                    res++;
                    printf("1 %d %d\n",za,i);
                    za=i;
                }
            }
            else{
                if(a==inf){
                    a=i;
                }
                else{
                    res++;
                    printf("1 %d %d\n",a,i);
                    a=i;
                }
            }
        }
        if(res!=n-1){
            printf("2 %d\n",za);
        }
    }
    else{
        int za=inf;int a=inf;
        int res=0;
        for(int i=1;i<=n;i++){
            if(m[i]==0){
                if(za==inf){
                    za=i;
                }
                else{
                    res++;
                    printf("1 %d %d\n",za,i);
                    za=i;
                }
            }
            else{
                if(a==inf){
                    a=i;
                }
                else{
                    res++;
                    printf("1 %d %d\n",a,i);
                    a=i;
                }
            }
        }
        if(res!=n-1){
            printf("2 %d\n",za);
        }
    }
    return 0;
}

      

 

全部评论

相关推荐

11-15 18:39
已编辑
西安交通大学 Java
全村最靓的仔仔:卧槽,佬啥bg呢,本也是西交么
点赞 评论 收藏
分享
贺兰星辰:不要漏个人信息,除了简历模板不太好以外你这个个人简介是不是太夸大了...
点赞 评论 收藏
分享
11-24 00:11
已编辑
广东工业大学 算法工程师
避雷深圳&nbsp;&nbsp;yidao,试用期&nbsp;6&nbsp;个月。好嘛,试用期还没结束,就直接告诉你尽快找下一家吧,我谢谢您嘞
牛客75408465号:笑死,直属领导和 hr 口径都没统一,各自说了一些离谱的被裁理由,你们能不能认真一点呀,哈哈哈哈哈😅😅😅
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务