题目:戳这里

题意: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. Databricks 第8篇:把Azure Data Lake Storage Gen2 (ADLS Gen 2)挂载到DBFS

    DBFS使用dbutils实现存储服务的装载(mount.挂载),用户可以把Azure Data Lake Storage Gen2和Azure Blob Storage 账户装载到DBFS中.mou ...

  2. wmic process进程管理

    process    进程管理工具 示例:1.列举当前的进程.进程路径.命令行.进程ID.父进程ID.线程数,内存使用::wmic process get name,executablepath,co ...

  3. odoo之技巧合集一

    罗列一些odoo开发中的简单但有效的方法: 1.重写odoo登录代码 参考链接:odoo10-重写登录方法 from odoo import models, fields, api, SUPERUSE ...

  4. Mybatis【15】-- Mybatis一对一多表关联查询

    注:代码已托管在GitHub上,地址是:https://github.com/Damaer/Mybatis-Learning ,项目是mybatis-11-one2one,需要自取,需要配置maven ...

  5. 简单的DbContext工厂类(EFCore)

    前言 根据appsettings.json的中配置的数据库类型,使用工厂模式创建DbContext 代码实现 appsettings.json中的配置项 //使用的数据库类型 "Server ...

  6. cisco思科交换机终端远程ssh另一端报错:% ssh connections not permitted from this terminal

    故障现象: XSJ-GH10-C3750->ssh 58.64.xx.xx% ssh connections not permitted from this terminal 解决办法: 原因: ...

  7. Spring Security OAuth2.0认证授权六:前后端分离下的登录授权

    历史文章 Spring Security OAuth2.0认证授权一:框架搭建和认证测试 Spring Security OAuth2.0认证授权二:搭建资源服务 Spring Security OA ...

  8. UT /SIT/ UAT

    UT /SIT/ UAT - 云+社区 - 腾讯云 https://cloud.tencent.com/developer/article/1541268 我们公司只有测试环境--准生产环境--生产环 ...

  9. 序列化 serialize

    Serializable 序列化  The byte stream created is platform independent. So, the object serialized on one ...

  10. P1837 单人纸牌

    写在前面 感谢巨佬 yu__xuan 的帮助! 原本题解区的大佬们大都写的九层循环,其实此题如果写成状压,可以将这九层循环写成一层,非但简洁.代码可读性强,常数也比直接九维 dp 小. 算法思路 由于 ...