codeforces 1042c// Array Product// Codeforces Round #510(Div. 2)
题意:给出一个数组,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)的更多相关文章
- codeforces 1042C Array Product【构造】
题目:戳这里 题意:n个数,两种操作,第一种是a[i]*a[j],删掉a[i],第一种是直接删除a[i](只能用一次)剩下的数序列号不变.操作n-1次,使最后剩下的那个数最大化. 解题思路: 正数之间 ...
- Codeforces Round #510 (Div. 2)
Codeforces Round #510 (Div. 2) https://codeforces.com/contest/1042 A 二分 #include<iostream> usi ...
- CF Round #510 (Div. 2)
前言:没想到那么快就打了第二场,题目难度比CF Round #509 (Div. 2)这场要难些,不过我依旧菜,这场更是被\(D\)题卡了,最后\(C\)题都来不及敲了..最后才\(A\)了\(3\) ...
- Codeforces Round #510 (Div. 2) C. Array Product
题目 题意: 给你n个数,有两种操作,操作1是把第i个位置的数删去, 操作2 是把 a[ j ]= a[ i ]* a[ j ],把a[ i ]删去 .n-1个操作以后,只剩1个数,要使这个数最大 . ...
- Codeforces Round #510 (Div. 2) D. Petya and Array(树状数组)
D. Petya and Array 题目链接:https://codeforces.com/contest/1042/problem/D 题意: 给出n个数,问一共有多少个区间,满足区间和小于t. ...
- Codeforces Round #510 (Div. 2) D. Petya and Array(离散化+反向树状数组)
http://codeforces.com/contest/1042/problem/D 题意 给一个数组n个元素,求有多少个连续的子序列的和<t (1<=n<=200000,abs ...
- codeforces 1042d//Petya and Array// Codeforces Round #510 (Div. 2)
题意:给出一个数组,求其中和小于t的区间数. 先计算前缀和数组sum[i].对当前的sum[i],查询树状数组中有几个比(sum[i]-t)大的数,那么用sum[i]减它就是一个合法区间.再将当前的s ...
- Codeforces Round #510 (Div. 2) B. Vitamins
B. Vitamins 题目链接:https://codeforces.com/contest/1042/problem/B 题意: 给出几种药,没种可能包含一种或多种(最多三种)维生素,现在问要吃到 ...
- Codeforces Round #510 (Div. 2)(C)
传送门:Problem C https://www.cnblogs.com/violet-acmer/p/9682082.html 题意: 给你n个数,定义有两种操作 ① 1 i j : (i != ...
随机推荐
- 常用linux命令:locate 命令
locate 让使用者可以很快速的搜寻档案系统内是否有指定的档案.其方法是先建立一个包括系统内所有档案名称及路径的数据库,之后当寻找时就只需查询这个数据库,而不必实际深入档案系统之中了.在一般的 di ...
- ORA-00980: 同义词转换不再有效
客户账号TB在操作软件时,报错:“[Microsoft][ODBC driver for Oracle][Oracle]ORA-00980: 同义词转换不再有效”. 使用拥有dba权限的账号sys的登 ...
- java多线程----线程池源码分析
http://www.cnblogs.com/skywang12345/p/3509954.html 线程池示例 在分析线程池之前,先看一个简单的线程池示例. 1 import java.util.c ...
- TED #08# Learn to read Chinese ... with ease!
ShaoLan: Learn to read Chinese ... with ease! Pre-requisites calligraphermy most treasured memoriesw ...
- Fine报表权限流程分析记录
Fine报表权限流程分析记录 URL访问三种类型的报表:第一个:BI报表 例如: http://192.25.103.250:37799/WebReport/ReportServer?op=fr_bi ...
- Hive-复制表
非分区表复制 复制一张非分区表,使用CREATE TABLE IF NOT EXISTS AS SELECT * FROM tb_name;只复制表结构,CREATE TABLE IF NOT EXI ...
- 03: Memcached
目录: 1.1 Memcached简介与安装 1.2 python-memcached模块天生支持集群 1.3 Memcached基本操作 1.1 Memcached简介与安装返回顶部 1.Memca ...
- 常用模块之 shutil,json,pickle,shelve,xml,configparser
shutil 高级的文件.文件夹.压缩包 处理模块 shutil.copyfileobj(fsrc, fdst[, length]) 将文件内容拷贝到另一个文件中 import shutil shut ...
- 精巧好用的DelayQueue 转
我们谈一下实际的场景吧.我们在开发中,有如下场景 a) 关闭空闲连接.服务器中,有很多客户端的连接,空闲一段时间之后需要关闭之.b) 缓存.缓存中的对象,超过了空闲时间,需要从缓存中移出.c) 任务超 ...
- python urljoin问题
如何去除url拼接的时候存在的遗留的'../'问题,可以参考如下的强制去除方法: def fix_URL(urlstring): parts = list(urlparse.urlparse(urls ...