Array Product

http://codeforces.com/problemset/problem/1042/C

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.

Examples

Input
  1. 5
    5 -2 0 1 -3
Output
  1. 2 3
    1 1 2
    1 2 4
    1 4 5
Input
  1. 5
    5 2 0 4 0
Output
  1. 1 3 5
    2 5
    1 1 2
    1 2 4
Input
  1. 2
    2 -1
Output
  1. 2 2
Input
  1. 4
    0 -10 0 0
Output
  1. 1 1 2
    1 2 3
    1 3 4
Input
  1. 4
    0 0 0 0
Output
  1. 1 1 2
    1 2 3
    1 3 4

Note

Let X be the removed number in the array. Let's take a look at all the examples:

The first example has, for example, the following sequence of transformations of the array: [5,−2,0,1,−3]→[5,−2,X,1,−3]→[X,−10,X,1,−3]→[5,−2,0,1,−3]→[5,−2,X,1,−3]→[X,−10,X,1,−3]→ [X,X,X,−10,−3]→[X,X,X,X,30][X,X,X,−10,−3]→[X,X,X,X,30]. Thus, the maximum answer is 3030. Note, that other sequences that lead to the answer 3030 are also correct.

The second example has, for example, the following sequence of transformations of the array: [5,2,0,4,0]→[5,2,X,4,0]→[5,2,X,4,X]→[X,10,X,4,X]→[5,2,0,4,0]→[5,2,X,4,0]→[5,2,X,4,X]→[X,10,X,4,X]→ [X,X,X,40,X][X,X,X,40,X]. The following answer is also allowed:

  1. 1 5 3
    1 4 2
    1 2 1
    2 3

Then the sequence of transformations of the array will look like this: [5,2,0,4,0]→[5,2,0,4,X]→[5,8,0,X,X]→[40,X,0,X,X]→[5,2,0,4,0]→[5,2,0,4,X]→[5,8,0,X,X]→[40,X,0,X,X]→ [40,X,X,X,X][40,X,X,X,X].

The third example can have the following sequence of transformations of the array: [2,−1]→[2,X][2,−1]→[2,X].

The fourth example can have the following sequence of transformations of the array: [0,−10,0,0]→[X,0,0,0]→[X,X,0,0]→[X,X,X,0][0,−10,0,0]→[X,0,0,0]→[X,X,0,0]→[X,X,X,0].

The fifth example can have the following sequence of transformations of the array: [0,0,0,0]→[X,0,0,0]→[X,X,0,0]→[X,X,X,0][0,0,0,0]→[X,0,0,0]→[X,X,0,0]→[X,X,X,0].

简单的模板,要注意的就是只能删除一次

杂乱无章的代码。。。

  1. #include <iostream>
  2. #include<vector>
  3. #include<cstring>
  4. #include<algorithm>
  5. #include<set>
  6. using namespace std;
  7.  
  8. int a[];
  9. vector<pair<int,int> >zheng,fu,ling;
  10.  
  11. int main(){
  12. std::ios::sync_with_stdio(false);
  13. int n;
  14. cin>>n;
  15. set<int>s;
  16. for(int i=;i<=n;i++){
  17. cin>>a[i];
  18. if(a[i]==){
  19. ling.push_back(make_pair(a[i],i));
  20. }
  21. else if(a[i]>){
  22. zheng.push_back(make_pair(a[i],i));
  23. }
  24. else{
  25. fu.push_back(make_pair(a[i],i));
  26. }
  27.  
  28. }
  29. if((zheng.size()==)&&(ling.size()>=)&&(fu.size()==)){
  30. for(int i=;i<=n;i++){
  31. cout<<<<" "<<i-<<" "<<i<<endl;
  32. }
  33. return ;
  34. }
  35. if((zheng.size()==)&&(fu.size()==)){
  36. for(int i=;i<ling.size();i++){
  37. cout<<<<" "<<ling[i-].second<<" "<<ling[i].second<<endl;
  38. }
  39. return ;
  40. }
  41. if(fu.size()>){
  42. sort(fu.begin(),fu.end());
  43. }
  44. int tmp1=-,tmp2=-,tmp3=-,tmp4=-;
  45. int fulen;
  46. if(fu.size()>){
  47. fulen=fu.size();
  48. if(fu.size()%){
  49. fulen--;
  50. tmp4=fu[fulen].second;
  51. }
  52. for(int i=;i<fulen;i++){
  53. cout<<<<" "<<fu[i-].second<<" "<<fu[i].second<<endl;
  54. }
  55. if(fu.size()==fulen)
  56. tmp1=fu[fulen-].second;
  57. else if(fulen)
  58. tmp1=fu[fulen-].second;
  59. }
  60. if(ling.size()>){
  61. for(int i=;i<ling.size();i++){
  62. cout<<<<" "<<ling[i-].second<<" "<<ling[i].second<<endl;
  63. }
  64. tmp2=ling[ling.size()-].second;
  65. }
  66. if(zheng.size()>){
  67. for(int i=;i<zheng.size();i++){
  68. cout<<<<" "<<zheng[i-].second<<" "<<zheng[i].second<<endl;
  69. }
  70. tmp3=zheng[zheng.size()-].second;
  71. }
  72. if(tmp2!=-&&tmp4!=-){
  73. cout<<<<" "<<tmp2<<" "<<tmp4<<endl;
  74. cout<<<<" "<<tmp4<<endl;
  75. }
  76. else if(tmp2==-&&tmp4!=-){
  77. cout<<<<" "<<tmp4<<endl;
  78. }
  79. else if(tmp2!=-&&tmp4==-){
  80. cout<<<<" "<<tmp2<<endl;
  81. }
  82. if(tmp1!=-&&tmp3!=-){
  83. cout<<<<" "<<tmp1<<" "<<tmp3<<endl;
  84. }
  85. }

Array Product(模拟)的更多相关文章

  1. CF1042C Array Product(贪心,模拟)

    题目描述 You are given an array aa consisting of nn integers. You can perform the following operations w ...

  2. CodeForces ---596B--Wilbur and Array(贪心模拟)

    Wilbur and Array Time Limit: 2000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Su ...

  3. hdu 5532 Almost Sorted Array(模拟)

    Problem Description We are all familiar with sorting algorithms: quick sort, merge sort, heap sort, ...

  4. CodeForce 439C Devu and Partitioning of the Array(模拟)

     Devu and Partitioning of the Array time limit per test 1 second memory limit per test 256 megabytes ...

  5. Educational Codeforces Round 52D(ARRAY,模拟最短路)

    #include<bits/stdc++.h>using namespace std;int n,x;int chess[17*17];//记录棋盘上的numberarray<int ...

  6. Codeforces 950D A Leapfrog in the Array ( 思维 && 模拟 )

    题意 : 给出 N 表示有标号 1~N 的 N 个数,然后从下标 1 开始将这 N 个数每隔一位放置一个,直到 N 个数被安排完,现在有一个操作就是每次将数列中最右边的数向离其左边最近的空缺处填上,一 ...

  7. Beauty of Array(模拟)

    M - M Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status P ...

  8. codeforces 1042c// Array Product// Codeforces Round #510(Div. 2)

    题意:给出一个数组,2种操作:.1:x*y然后x消失,2:除掉x(2操作最多只能进行一次).问最大的结果的一种操作方式.逻辑题,看能不能想全面. 1先数好0,正,负的数量,zero,pos,neg.如 ...

  9. CF1042C Array Product 分类讨论+贪心

    考虑有无负数(负数的个数为奇视作“有”,否则为“无”)和有无零 无负数无零,全部合并即可 无负数有零,那么把零合并起来,删掉零 有负数无零,把最大的负数找出来,删掉,合并剩余的数 有负数有零,把零和最 ...

随机推荐

  1. [转]C# 使用代理访问网络

    本文部分内容来自:https://zhidao.baidu.com/question/563196409.html 也可以参考:http://www.cnblogs.com/stuart/p/5442 ...

  2. Valgrind memcheck 8种错误实例

    调不尽的内存泄漏,用不完的Valgrind Valgrind 安装 1. 到www.valgrind.org下载最新版valgrind-3.2.3.tar.bz2 2. 解压安装包:tar –jxvf ...

  3. [UE4]事件代理,无输出参数,蓝图中不需要绑定

    .h UFUNCTION(BlueprintImplementableEvent, meta=(DisplayName = "LoginSuccess")) void LoginS ...

  4. Process Pool实现Python的并行执行

    参考:Python3.6.2文档 Source code: Lib/concurrent/futures/thread.py and Lib/concurrent/futures/process.py ...

  5. sqoop操作之ETL小案例

    Extraction-Transformation-Loading的缩写,中文名称为数据提取.转换和加载.将数据从ORACLE中抽取数据,经过hive进行分析转换,最后存放到ORACLE中去. 本案例 ...

  6. Python while 循环使用实例

    while循环是在Python中的循环结构之一. while循环继续,直到表达式变为假.表达的是一个逻辑表达式,必须返回一个true或false值,本文章向码农介绍Python while 循环使用方 ...

  7. 分割List为指定size

    背景 老项目,用的原生的JDBC,获取连接,预编译...然后业务需要要更新很多条数据,我就写了条件为 ——IN()... 根据传入的 list 的 size 循环的给sql语句拼接上“ ? ”为了之后 ...

  8. 如何决定Web应用的线程池大小

    线程池(Thread Pool)在Web应用中线程池的大小决定了在任何一个时间点应用可以处理请求的并发数.如果一个系统收到的请求数超过了线程池的大小,那么超出的请求要么进入等待队列要么被拒绝.请注意, ...

  9. 模板方法模式( TemplateMethod)

    定义一个操作中的算法的骨架,而将一些步骤延迟到子类中,模板方法使得子类可以不改变一个算法的结构即可重新定义该算法的某些特定步骤. AbstractClass 是抽象类,其实也是一个抽象模板,定义并实现 ...

  10. JavaScript中的数组和字符串

    知识内容: 1.JavaScript中的数组 2.JavaScript中的字符串 一.JavaScript中的数组 1.JavaScript中的数组是什么 数组指的是数据的有序列表,每种语言基本上都有 ...