日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

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

發(fā)布時(shí)間:2023/12/10 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【CodeForces - 1042C】Array Product(思维,有坑细节) 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

題干:

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

  • 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;
  • 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個(gè)數(shù),兩種操作,第一種是a[i]*a[j],刪掉a[i],第二種是直接刪除a[i](其中第二種操作只能用一次)剩下的數(shù)序列號(hào)不變。操作n-1次,使最后剩下的那個(gè)數(shù)最大化。

    讓你輸出這n-1次操作(數(shù)字位置的序號(hào)輸出原序列的)。

    解題報(bào)告:

    分情況,如果全是正數(shù)或者有偶數(shù)個(gè)負(fù)數(shù),那就全乘起來,然后0單獨(dú)處理。

    如果有奇數(shù)個(gè)負(fù)數(shù),那就貪心將絕對(duì)值最小的那個(gè)負(fù)數(shù)看成0一類的,然后化為第一種情況,一樣處理。

    樣例給的很到位啊,,,不然就忘了判斷那個(gè)操作次數(shù)是否是n-1次了,因?yàn)橹挥?操作不到n-1次時(shí),才用2操作。

    再就是x剛開始給了-1e9,,,竟然WA了,,不過想想也是啊,,這個(gè)值還是太大了,,賦初值-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 ; }

    ?

    總結(jié)

    以上是生活随笔為你收集整理的【CodeForces - 1042C】Array Product(思维,有坑细节)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。