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 != ...
随机推荐
- MyEclipse 相关设置
1. MyElipse复制项目后,修改项目的发布名称的方式.右击你的项目,选择 properties -- > MyElipse -- > web,然后修改名称即可. 2. IDE查看源代 ...
- Linux服务器配置---ftp限制ip
ftp限制IP 1.通过vsftpd的配置文件以及“hosts.deny”和“hosts.allow”文件设置允许某个ip地址访问 1)修改配置文件“/etc/vsftpd/vsftpd.conf”中 ...
- fastDFS errcode:9 path:Bad file descriptor errcode:22 path:Invalid argument
fastDFS errcode:9 path:Bad file descriptor errcode:22 path:Invalid argument <error>status:4 er ...
- oracle中如何判断blob类型字段是否为空
eg.假如有表T_GA_GRJBXX ,字段zp是blob类型 查询blob非空的记录 SELECT * FROM u_rs_sjgx.T_GA_GRJBXX TB WHERE TB.zp IS n ...
- Core Java 2
p267~p270: 1.一个方法不仅需要告诉编译器将要返回什么值, 还要告诉编译器有可能发生什么错误(以便在错误发生时用妥善的方式处理错误). 2.方法应该在首部声明所有可能抛出的异常. 3.方法抛 ...
- 20145105 《Java程序设计》第7周学习总结
20145105 <Java程序设计>第7周学习总结 教材学习内容总结 第十三章 时间与日期 一.认识时间与日期 (一)时间的度量 格林威治标准时间 世界时 国际原子时 世界协调时 Uni ...
- tslib移植笔记(1)【转】
本文转载自:https://blog.csdn.net/zijie_xiao/article/details/50740950 tslib移植笔记(1)2016-04-25 tslib背景[摘自百度] ...
- Linux系统编程--文件描述符的复制dup()和dup2()【转】
本文转载自:http://blog.csdn.net/tennysonsky/article/details/45870459 dup() 和 dup2() 是两个非常有用的系统调用,都是用来复制一个 ...
- Wireshark分析RabbitMQ
消费者Code: using System; using System.Collections.Generic; using System.Linq; using System.Text; using ...
- JSON类库Jackson与JSON-lib性能对比[转]
Jackson:http://jackson.codehaus.org/ JSON-lib:http://json-lib.sourceforge.net/ Gson:http://code.goog ...