题目:戳这里

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

解题思路:

正数之间全用操作1得到的结果最大。

负数的个数如果是偶数,全用操作1最后得到的也最大。如果是奇数,那最大的那个负数(贪心的思想)就要进行特殊操作,具体怎么操作要看后面有没有0,如果有0就用操作1去乘,没有就用操作2直接给这个数删了。

有0的话就把所有的0乘最后一个0,然后把最后一个0删了。

附ac代码:

 1 #include <bits/stdc++.h>
2 using namespace std;
3 typedef long long ll;
4 const int maxn = 5e5 + 10;
5 const int inf = 5e5 + 10;
6 struct nod
7 {
8 ll a;
9 int id;
10 }nu[maxn];
11 bool cmp(nod x, nod y)
12 {
13 return x.a < y.a;
14 }
15 int main() {
16 int n;
17 scanf("%d", &n);
18 for(int i = 1; i <= n; ++i)
19 {
20 scanf("%lld", &nu[i].a);
21 nu[i].id = i;
22 }
23 sort(nu + 1, nu + 1 + n, cmp);
24 int cntm = 0;
25 int lastz = 0;
26 int cntop = 0;
27 int firstp = 0;
28 int firstz = 0;
29
30 for(int i = 1; i <= n; ++i)
31 {
32 if(nu[i].a < 0) ++cntm;
33 if(nu[i].a == 0)
34 {
35 if(!firstz) firstz = i;
36 lastz = i;
37 }
38 if(nu[i].a > 0)
39 {
40 firstp = i;
41 break;
42 }
43 }
44 if(cntm & 1)
45 {
46 if(lastz) firstz = cntm;
47 else printf("2 %d\n", nu[cntm].id);
48 --cntm;
49 }
50 for(int i = 1; i < cntm; ++i)
51 {
52 printf("1 %d %d\n", nu[i].id, nu[cntm].id);
53 }
54 for(int i = firstz; i < lastz; ++i)
55 {
56 printf("1 %d %d\n", nu[i].id, nu[i + 1].id);
57 }
58 if(lastz && (cntm || firstp))//这里wa了好多发
59 {
60 printf("2 %d\n", nu[lastz].id);
61
62 }
63 if(firstp)
64 {
65 if(cntm)
66 {
67 printf("1 %d %d\n", nu[cntm].id, nu[n].id);
68 }
69 for(int i = firstp; i < n; ++i)
70 {
71 printf("1 %d %d\n", nu[i].id, nu[n].id);
72 }
73 }
74 return 0;
75 }

codeforces 1042C Array Product【构造】的更多相关文章

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

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

  2. Array Product(模拟)

    Array Product http://codeforces.com/problemset/problem/1042/C You are given an array aa consisting o ...

  3. Array Product CodeForces - 1042C (细节)

    #include <iostream> #include <sstream> #include <algorithm> #include <cstdio> ...

  4. Makes And The Product CodeForces - 817B (思维+构造)

    B. Makes And The Product time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  5. Codeforces F. Maxim and Array(构造贪心)

    题目描述: Maxim and Array time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  6. Codeforces Round #510 #C Array Product

    http://codeforces.com/contest/1042/problem/C 给你一个有n个元素序列,有两个操作:1,选取a[i]和a[j],删除a[i],将$a[i]*a[j]$赋值给a ...

  7. Codeforces Round #643 (Div. 2) D. Game With Array (思维,构造)

    题意:给你两个正整数\(N\)和\(S\),构造一个长度为\(N\)并且所有元素和为\(S\)的正整数数组,问是否能找到一个\(K (0\le K \le S)\)使得这个数组的任意_子数组_的和都不 ...

  8. Codeforces.487C.Prefix Product Sequence(构造)

    题目链接 \(Description\) 对于一个序列\(a_i\),定义其前缀积序列为\(a_1\ \mathbb{mod}\ n,\ (a_1a_2)\ \mathbb{mod}\ n,...,( ...

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

    题目 题意: 给你n个数,有两种操作,操作1是把第i个位置的数删去, 操作2 是把 a[ j ]= a[ i ]* a[ j ],把a[ i ]删去 .n-1个操作以后,只剩1个数,要使这个数最大 . ...

随机推荐

  1. [Usaco2008 Mar]River Crossing渡河问题

    题目描述 Farmer John以及他的N(1 <= N <= 2,500)头奶牛打算过一条河,但他们所有的渡河工具,仅仅是一个木筏. 由于奶牛不会划船,在整个渡河过程中,FJ必须始终在木 ...

  2. 【AtCoder Beginner Contest 181】A~F题解

    越学越菜系列 于2020.11.2,我绿了(错乱) A - Heavy Rotation 签到题,奇数Black,偶数White. code: #include<bits/stdc++.h> ...

  3. 03. struts2中Action配置的各项默认值

    Action中的各项默认值 Action各项配置 <action name="helloworld" class="com.liuyong666.action.He ...

  4. VMware中安装Ubuntu后,安装VMwareTools提示“Not enough free space to extract VMwareTools-10.3.10-13959562.tar.gz”的解决办法

    将加载后的Vmware Tools中的*.tar.gz文件复制到桌面后提取,否则会报错:

  5. 让绝对定位的div居中

    最近看到一个问题就是让绝对定位的div居中,在尝试了top:50%:left:50%:后发现,居中是有问题的并不是想象中的样子 需要再加两句margin-top:-盒子高度的一般px  margin- ...

  6. SpringBoot深入理解

    SpringBoot深入理解 项目打包SpringBoot启动过程 当使用打包时,会下载org-springframework-boot-loader的jar,并且不会放在lib存放的第三方jar包文 ...

  7. Redis击穿、穿透、雪崩产生原因以及解决思路

    击穿 大家都知道,计算机的瓶颈之一就是IO,为了解决内存与磁盘速度不匹配的问题,产生了缓存,将一些热点数据放在内存中,随用随取,降低连接到数据库的请求链接,避免数据库挂掉.需要注意的是,无论是击穿还是 ...

  8. tp6.0配置站点后无法访问

    1.安装composer中国镜像composer config -g repo.packagist composer https://packagist.phpcomposer.com2.执行comp ...

  9. Centos7 yum 安装 oracle-rdbms-server-11gR2-pre

    Oracleyum官方网站 http://yum.oracle.com/ 一.下载yum源 根据自己需求下载相应的yum源 http://yum.oracle.com/getting-started. ...

  10. Poem 01(转)

    Dear Sunshine The way you glow through my blinds in the morning. It makes me feel like you missed me ...