【CodeForces - 1042C】Array Product(思维,有坑细节)

题干:

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

5
5 -2 0 1 -3

Output

2 3
1 1 2
1 2 4
1 4 5

Input

5
5 2 0 4 0

Output

1 3 5
2 5
1 1 2
1 2 4

Input

2
2 -1

Output

2 2

Input

4
0 -10 0 0

Output

1 1 2
1 2 3
1 3 4

Input

4
0 0 0 0

Output

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 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].

题目大意:

n个数,两种操作,第一种是a[i]*a[j],删掉a[i],第二种是直接删除a[i](其中第二种操作只能用一次)剩下的数序列号不变。操作n-1次,使最后剩下的那个数最大化。

让你输出这n-1次操作(数字位置的序号输出原序列的)。

解题报告:

分情况,如果全是正数或者有偶数个负数,那就全乘起来,然后0单独处理。

如果有奇数个负数,那就贪心将绝对值最小的那个负数看成0一类的,然后化为第一种情况,一样处理。

样例给的很到位啊,,,不然就忘了判断那个操作次数是否是n-1次了,因为只有1操作不到n-1次时,才用2操作。

再就是x刚开始给了-1e9,,,竟然WA了,,不过想想也是啊,,这个值还是太大了,,赋初值-1e9-1也行、、

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define F first
#define S second
#define ll long long
#define pb push_back
#define pm make_pair
using namespace std;
typedef pair<int,int> PII;
const int MAX = 2e5 + 5;
int pos[MAX],a[MAX];
int tot,cnt;
int main()
{int n,cur=0;cin>>n;for(int i = 1; i<=n; i++) {scanf("%d",a+i);if(a[i] == 0) pos[++tot] = i;if(a[i] <  0) cnt++;}if(cnt%2==0) {int last = -1;for(int i = 1; i<=n; i++) {if(a[i] == 0) continue;else {if(last == -1) last = i;else printf("1 %d %d\n",last,i),last=i,cur++;}}for(int i = 2; i<=tot; i++) printf("1 %d %d\n",pos[i-1],pos[i]),cur++;if(cur!=n-1) printf("2 %d\n",pos[tot]);}else {int x=-1e9-12,tar;for(int i = 1; i<=n; i++) {if(a[i] >= 0) continue;if(a[i] > x) tar=i,x=a[i];}tot=0;for(int i = 1; i<=n; i++) {if(i==tar||a[i]==0) pos[++tot]=i;}int last = -1;for(int i = 1; i<=n; i++) {if(a[i] == 0 || i == tar) continue;else {if(last == -1) last = i;else printf("1 %d %d\n",last,i),last=i,cur++;}}for(int i = 2; i<=tot; i++) printf("1 %d %d\n",pos[i-1],pos[i]),cur++;if(cur!=n-1) printf("2 %d\n",pos[tot]);		}return 0 ;
}

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/440392.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

红米pro android o刷机,红米Pro如何刷机?你可以通过这两种方法获取root权限!

小米官网最近发布了关于红米pro的消息&#xff0c;相信很多米粉们已经上手了&#xff0c;那么新到手的机子怎么刷机呢&#xff1f;下面小编为大家带来一个完整的红米Pro官方卡刷机教程&#xff0c;希望可以帮助到大家。红米Pro卡刷升级教程&#xff1a;准备工作1.进入红米Pro刷…

【2019浙江省赛 - K 】Strings in the Pocket(马拉车,思维)

题干&#xff1a; BaoBao has just found two strings and in his left pocket, where indicates the -th character in string , and indicates the -th character in string . As BaoBao is bored, he decides to select a substring of and reverse it. Formally spe…

android+微信一键关注,一键关注微信公众平台JS代码有哪些?

一键关注微信公众平台JS代码有哪些&#xff1f;在网页设置一个按钮或者链接可以让用户一键关注微信公众平台&#xff0c;那么这种一键关注微信公众平台的功能如何实现呢&#xff1f;下面小编分享给大家一键关注微信公众平台的JS代码。在微信上&#xff0c;通过微信公众平台推送…

【2019浙江省赛 - A】Vertices in the Pocket(权值线段树下二分,图,思维)

题干&#xff1a; DreamGrid has just found an undirected simple graph with vertices and no edges (thats to say, its a graph with isolated vertices) in his right pocket, where the vertices are numbered from 1 to . Now he would like to perform operations …

html写原生曲线图,HTML5 平滑的正弦波曲线图

JavaScript语言&#xff1a;JaveScriptBabelCoffeeScript确定var waves new SineWaves({el: document.getElementById(waves),speed: 4,width: function() {return $(window).width();},height: function() {return $(window).height();},ease: SineInOut,wavesWidth: 80%,wav…

【CodeForces - 1150C】Prefix Sum Primes(思维)

题干&#xff1a; Were giving away nice huge bags containing number tiles! A bag we want to present to you contains nn tiles. Each of them has a single number written on it — either 11or 22. However, there is one condition you must fulfill in order to re…

asp.net 写入html代码,asp.net读取模版并写入文本文件

本文要介绍的是ASP.NET怎样读写文本文件&#xff0c;但更重要的是实现的过程。使用的工具是Visual Studio 2015 &#xff0c;.NET版本是4.6.1 。一共建立的2个项目&#xff0c;HoverTreePanel和HoverTreeWeb&#xff0c;都是ASP.NET项目。文章末尾附源码下载。项目结果如下图&a…

【CodeForces - 1150A】Stock Arbitraging (贪心,水题)

题干&#xff1a; Welcome to Codeforces Stock Exchange! Were pretty limited now as we currently allow trading on one stock, Codeforces Ltd. We hope youll still be able to make profit from the market! In the morning, there are nn opportunities to buy share…

html以图像中心定位,在HTML图像上水平和垂直居中文本(绝对定位)

Michael Roach0htmlcssflexbox鉴于以下设计元素,我试图在html中包含图像,以便可以使用css过渡(悬停效果)操纵不透明度.这里的主要缺点是我使用手动垂直居中(绝对/顶部:4​​0%),这在缩小浏览器时变得明显.在使用绝对定位时,是否可以使用flexbox或table进行垂直居中&#xff1f;…

*【CodeForces - 1150D】Three Religions(dp,预处理,思维)

题干&#xff1a; During the archaeological research in the Middle East you found the traces of three ancient religions: First religion, Second religion and Third religion. You compiled the information on the evolution of each of these beliefs, and you now…

基于android公交车线路查询论文文献,本科毕业论文---基于android的手机公交线路查询系统.doc...

毕 业 设 计( 论 文 )题目手机公交线路查询系统作者学院专业学号指导教师摘 要关键词&#xff1b;AbstractWith the level of people’s life improving,going out by bus become a necessary part of daily life.And the traffic line to destination should be known everyti…

【POJ - 3159】Candies (差分约束,卡SPFA)

题干&#xff1a; 在幼儿园的时候&#xff0c;Flymouse是班上的班长。有时班主任会给班上的孩子们带来一大袋糖果&#xff0c;让他们分发。所有的孩子都非常喜欢糖果&#xff0c;经常比较他们和别人买的糖果的数量。一个孩子A可以有这样的想法&#xff0c;尽管可能是另一个孩子…

计算机英语第六单元,计算机专业英语第六版第十单元课后汉译英,We do use other forms....这个do...

同样的 &#xff0c;多线程也存在许多缺点 &#xff0c;在考虑多线程时需要进行充分的考虑。多线程的主要缺点包括&#xff1a;Similarly, multi thread also has many shortcomings, in the consideration of the need for the full consideration of multiple threads. The m…

1.Hello,Python

本文为Kaggle Learn的Python课程的中文翻译&#xff0c;原文链接为&#xff1a;https://www.kaggle.com/colinmorris/hello-python 欢迎来到Kaggle Learn的Python课程。本课程将介绍在开始使用Python进行数据科学之前需要的基本Python技能。这些课程针对那些具有一些编程经验的…

【POJ - 1273】Drainage Ditches(网络流,最大流,模板)

题干&#xff1a; 现在有m个池塘(从1到m开始编号,1为源点,m为汇点),及n条水渠,给出这n条水渠所连接的点和所能流过的最大流量&#xff0c;求从源点到汇点能流过的最大流量。 Input 输入包括几种情况。 对于每种情况&#xff0c;第一行包含两个空格分隔的整数&#xff0c;N&a…

计算机网络阶段,计算机网络的发展大致可分为四个阶段,目前人类进入了()。 - 问答库...

问题&#xff1a;[单选] 计算机网络的发展大致可分为四个阶段&#xff0c;目前人类进入了()。A . 计算机网络阶段B . 信息高速公路阶段C . 计算机网络互联阶段D . 远程终端联机阶段教育心理学是研究教育情境中学生学习的基本心理规律的科学。王林平时成绩一般&#xff0c;但总想…

2.Functions and Getting Help

Functions and Getting Help 在本课中&#xff0c;我们将讨论函数&#xff1a;调用它们&#xff0c;定义它们&#xff0c;并使用Python的内置文档查找它们。 在某些语言中&#xff0c;定义函数必须要有特定的参数&#xff0c;每个参数都具有特定类型。 Python函数允许更灵活。…

华人科学家量子计算机,华人科学家在美国研发出性能强大的光子计算机,能够与中国的量子计算机一战高下!...

原标题&#xff1a;华人科学家在美国研发出性能强大的光子计算机&#xff0c;能够与中国的量子计算机一战高下&#xff01;在最近的《自然纳米技术》杂志上&#xff0c;一篇来自美国哥伦比亚大学的论文在业界掀起了轩然大波&#xff0c;一位名叫虞南方的物理学助理教授成功率领…

【BZOJ - 1001】狼抓兔子(无向图网络流,最小割,或平面图转对偶图求最短路SPFA)

题干&#xff1a; 现在小朋友们最喜欢的"喜羊羊与灰太狼",话说灰太狼抓羊不到&#xff0c;但抓兔子还是比较在行的&#xff0c; 而且现在的兔子还比较笨&#xff0c;它们只有两个窝&#xff0c;现在你做为狼王&#xff0c;面对下面这样一个网格的地形&#xff1a; …

3.Booleans and Conditionals

Booleans Python有bool类型数据&#xff0c;有两种取值&#xff1a;True 和 False. [1] x True print(x) print(type(x)) True <class bool> 我们通常从布尔运算符中获取布尔值&#xff0c;而不是直接在我们的代码中放入True或False。 这些是回答yes或no的运算符。…