题意:给出一个数组,2种操作:。1:x*y然后x消失,2:除掉x(2操作最多只能进行一次)。问最大的结果的一种操作方式。
逻辑题,看能不能想全面。

1先数好0,正,负的数量,zero,pos,neg。如果0数量不为0,在所有0的内部用操作1减少到只剩1个0,zero置1;(删去0不影响结果,如果结果是0,那么剩1个0也能做到,如果结果不是0,那么删0是必须的)

2负数有奇数个时(这种情况下一定有非负解)(1)如果zero=0,用操作2删掉最大的负数(不删结果负,删了必为正)(2)zero=1,用0和最大的负数乘。如果pos!=0或者neg!=1,再用操作2删去0;

3负数有0个时:如果有正数且zero=1,用操作2删去0;没正数结果只能为0(即给的数列全是0)

4负数

//#pragma comment(linker,"/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include <stack>
#include <list>
using namespace std;
const int SZ=,INF=0x7FFFFFFF;
typedef long long lon;
const double EPS=1e-;
bool isneg(int x)
{
return x<;
} bool ispos(int x)
{
return x>;
} int main()
{
std::ios::sync_with_stdio();
//freopen("d:\\1.txt","r",stdin);
int n;
cin>>n;
vector<int> vct(n);
for(int i=;i<n;++i)
{
cin>>vct[i];
}
int negnum=count_if(vct.begin(),vct.end(),isneg);
int zeronum=count(vct.begin(),vct.end(),);
int posnum=n-negnum-zeronum;
//if(vct[0]==582204189 )cout<<negnum<<" "<<zeronum<<" "<<posnum<<endl;
if(zeronum>)
{
int last=-;
for(int i=;i<n;++i)
{
if(vct[i]==)
{
if(last!=-)
{
cout<<<<" "<<last+<<" "<<i+<<endl;
vct[last]=-INF;
}
last=i; }
}
}
if(negnum&)
{
if(zeronum==)
{
int maxv=-INF,maxid=;
for(int i=;i<n;++i)
{
if(vct[i]<&&vct[i]>maxv)
{
maxv=vct[i];
maxid=i;
}
}
cout<<<<" "<<maxid+<<endl;
vct[maxid]=-INF;
}
else
{
int maxv=-INF,maxid=;
for(int i=;i<n;++i)
{
if(vct[i]<&&vct[i]>maxv)
{
maxv=vct[i];
maxid=i;
}
}
int pos=find(vct.begin(),vct.end(),)-vct.begin();
cout<<<<" "<<maxid+<<" "<<pos+<<endl;
if(posnum||negnum!=)cout<<<<" "<<pos+<<endl;
vct[maxid]=-INF;
vct[pos]=-INF;
}
}
else if(negnum==)
{
if(posnum&&zeronum)
{
int pos=find(vct.begin(),vct.end(),)-vct.begin();
cout<<<<" "<<pos+<<endl;
vct[pos]=-INF;
} }
else if(zeronum)
{
int pos=find(vct.begin(),vct.end(),)-vct.begin();
cout<<<<" "<<pos+<<endl;
vct[pos]=-INF;
} int last=-;
for(int i=;i<n;++i)
{
if(vct[i]!=-INF)
{
if(last==-)last=i;
else
{
cout<<<<" "<<last+<<" "<<i+<<endl;
last=i;
}
}
}
return ;
}

为其它偶数时(至少为2,一定有正数解),如果zero=1删去1

上面删的数用数组记录,最后没删的数用操作1乘起来。

codeforces 1042c// Array Product// Codeforces Round #510(Div. 2)的更多相关文章

  1. codeforces 1042C Array Product【构造】

    题目:戳这里 题意:n个数,两种操作,第一种是a[i]*a[j],删掉a[i],第一种是直接删除a[i](只能用一次)剩下的数序列号不变.操作n-1次,使最后剩下的那个数最大化. 解题思路: 正数之间 ...

  2. Codeforces Round #510 (Div. 2)

    Codeforces Round #510 (Div. 2) https://codeforces.com/contest/1042 A 二分 #include<iostream> usi ...

  3. CF Round #510 (Div. 2)

    前言:没想到那么快就打了第二场,题目难度比CF Round #509 (Div. 2)这场要难些,不过我依旧菜,这场更是被\(D\)题卡了,最后\(C\)题都来不及敲了..最后才\(A\)了\(3\) ...

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

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

  5. Codeforces Round #510 (Div. 2) D. Petya and Array(树状数组)

    D. Petya and Array 题目链接:https://codeforces.com/contest/1042/problem/D 题意: 给出n个数,问一共有多少个区间,满足区间和小于t. ...

  6. Codeforces Round #510 (Div. 2) D. Petya and Array(离散化+反向树状数组)

    http://codeforces.com/contest/1042/problem/D 题意 给一个数组n个元素,求有多少个连续的子序列的和<t (1<=n<=200000,abs ...

  7. codeforces 1042d//Petya and Array// Codeforces Round #510 (Div. 2)

    题意:给出一个数组,求其中和小于t的区间数. 先计算前缀和数组sum[i].对当前的sum[i],查询树状数组中有几个比(sum[i]-t)大的数,那么用sum[i]减它就是一个合法区间.再将当前的s ...

  8. Codeforces Round #510 (Div. 2) B. Vitamins

    B. Vitamins 题目链接:https://codeforces.com/contest/1042/problem/B 题意: 给出几种药,没种可能包含一种或多种(最多三种)维生素,现在问要吃到 ...

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

    传送门:Problem C https://www.cnblogs.com/violet-acmer/p/9682082.html 题意: 给你n个数,定义有两种操作 ① 1 i j : (i != ...

随机推荐

  1. Python2 简明教程

    Python 由 Guido Van Rossum 在90年代初创建. 它现在是最流行的语言之一 我喜爱python是因为它有极为清晰的语法,甚至可以说,它就是可以执行的伪代码. 注意: 这篇文章针对 ...

  2. SpringBoot之统一异常处理

    异常,不仅仅是程序运行状态的描述,还可以使得代码编写更加的规范   1.自定义异常:FieldValueInvalidException package com.geniuses.sewage_zer ...

  3. Quartz框架调用——运行报错:ThreadPool class not specified

    Quartz框架调用——运行报错:ThreadPool class not specified 问题是在于Quartz框架在加载的时候找不到quartz.properties配置文件: 解决方案一: ...

  4. 第一个c++泛型函数(即模板)

    先定义如下: ns.h template <typename T> // 这个关键字typename, 明显多此一举 inline void PRINT_ELEMENTS(const T& ...

  5. 04: Mysql性能优化

    MySQL其他篇 目录: 参考网站 1.1 Mysql数据库的优化技术 1.2 数据库表设计 1.3 SQL优化 1.为查询缓存优化你的查询 2.EXPLAIN 你的 SELECT 查询 3. 当只要 ...

  6. redis.windows.conf 参数说明

    1. Redis默认不是以守护进程的方式运行,可以通过该配置项修改,使用yes启用守护进程 daemonize no 2. 当Redis以守护进程方式运行时,Redis默认会把pid写入/var/ru ...

  7. AD快捷键

    * 在PCB电气层之间切换.在布线的过程中,按此键则换层并自动添加过孔并换层. Q 在公制和英制之间切换 J+C 定位到指定的元件处.在弹出的对话框内输入该元件的编号. G+G 设定栅格吸附尺寸. T ...

  8. git commit如何修改默认编辑器为vim

    答:修改~/.gitconfig(修改这个文件将全局有效)或项目目录中的.git/config(修改此文件只是使当前项目默认使用vim)中增加以下内容: [core] editor=vim

  9. Pairs Forming LCM (LCM+ 唯一分解定理)题解

    Pairs Forming LCM Find the result of the following code: ; i <= n; i++ )        for( int j = i; j ...

  10. Java Collections Framework概览

    本文github地址 概览 容器,就是可以容纳其他Java对象的对象.Java Collections Framework(JCF)为Java开发者提供了通用的容器,其始于JDK 1.2,优点是: 降 ...