Codeforces Round #510 (Div. 2) C. Array Product

0 篇文章 0 订阅

不会用set所以就用队列来模拟,大体思想是(没有)反正数据弱就每次取2个放回一个这样循环跑

#include <iostream>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <vector>
#include <map>
#include <cstring>
#include <set>
using namespace std;
typedef long long LL;
const int MOD=1e9+7;
LL Pow(LL a,LL b);
const int MAXN=1e6+7;
const int MAX=0x3f3f3f3f;
queue<int>a,b,c,d;
int main()
{
    ios::sync_with_stdio(false);
    int n;
    LL a1=0,b1=-MOD;
    scanf("")
    LL number;
    int k0=0,k1=0,k2=0;
    int pos=0;
    for(int i=1;i<=n;i++)
    {
        cin>>number;
        if(number==0)
            a.push(i);
        else if(number<0)
        {

           c.push(i);
           if(b1<number)
           {
               b1=number;
               pos=i;
           }
            //a1++;
           // num1[k1++]=i;
        }
        else
        {
            b.push(i);
          //  num[k2++]=i;
        }
    }
    int now,l,r;
    while(a.size()>1)//a=0
    {
        l=a.front();
        a.pop();
        r=a.front();
        a.pop();
        cout<<"1"<<" "<<l<<" "<<r<<endl;
        a.push(r);
    }
   while(b.size()>1)//b>0
    {
        l=b.front();
        b.pop();
        r=b.front();
        b.pop();
        cout<<"1"<<" "<<l<<" "<<r<<endl;
        b.push(r);
    }

    if(c.size()%2==1)
    {
        if(c.size()==1)
        {
            l=c.front();
            c.pop();
           if(a.size()==0)
                cout<<"2"<<" "<<l<<endl;
           else
           {
               r=a.front();
               a.pop();
                cout<<"1"<<" "<<l<<" "<<r<<endl;
                a.push(r);
           }

        }
        else
        {
        while(c.size()>1)
        {
        l=c.front();
        c.pop();
        r=c.front();
        c.pop();


        if(l==pos&&a.size()!=0)
        {
            c.push(r);
            r=a.front();
            a.pop();
            cout<<"1"<<" "<<l<<" "<<r<<endl;
            a.push(r);
        }
        else if(l==pos&&a.size()==0)
        {
            c.push(r);
            cout<<"2"<<" "<<l<<endl;
        }
        else if(a.size()!=0&&r==pos)
        {
           c.push(l);
           l=a.front();
           a.pop();
           cout<<"1"<<" "<<l<<" "<<r<<endl;
           a.push(l);
        }
        else if(r==pos&&a.size()==0)
        {
             c.push(l);
             cout<<"2"<<" "<<r<<endl;
        }
        else
        {
            cout<<"1"<<" "<<l<<" "<<r<<endl;
            c.push(r);
        }
        }
        }
    }
    else
    {
        if(c.size()!=0)
        {
            while(c.size()>1)
            {
            l=c.front();
            c.pop();
            r=c.front();
            c.pop();
            cout<<"1"<<" "<<l<<" "<<r<<endl;
            c.push(r);
            }
        }
    }



    if(a.size()!=0&&(b.size()!=0||c.size()!=0))///a为0 b为正数 c负数
    {
        cout<<"2"<<" "<<a.front()<<endl;
    }
    if(b.size()!=0&&c.size()!=0)
    {
        cout<<"1"<<" "<<b.front()<<" "<<c.front()<<endl;
    }

    return 0;
}


LL Pow(LL a,LL b)
{
    LL ans=1;
    while(b!=0)
    {
        if(b&1!=0)
        {
            ans=ans*a;
        }
        a*=a;
        b>>=1;
    }
    return ans;
}

。。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值