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 != ...
随机推荐
- 小试---EF5.0入门实例1
现在做个小练习吧~~~ 第一步:首先新建一个数据库名字为Test;数据库里面只有一个表UserTable 脚本为: USE [master] GO /****** 对象: Database [Test ...
- ACM竞赛之输入输出(以C与C++为例)
本文转自互联网,内容.排版有修正. 欢迎和大家交流技术相关问题: 邮箱: jiangxinnju@163.com 博客园地址: http://www.cnblogs.com/jiangxinnju G ...
- 虚拟机中安装mac系统
虚拟机安装就很简单了,傻瓜式安装,一直点击下一步就行,这里就不多说了. 所需要的配置: 虚拟机下载地址:链接:http://pan.baidu.com/s/1i45wXRf 密码:7c4x mac补丁 ...
- PHP发送HTTP请求的6种方法
方法1: 用 file_get_contents 以get方式获取内容: <?php$url = 'https://wenda.shukaiming.com/';echo file_get_co ...
- Python Web学习笔记之socket套接字
套接字是为特定网络协议(例如TCP/IP,ICMP/IP,UDP/IP等)套件对上的网络应用程序提供者提供当前可移植标准的对象.它们允许程序接受并进行连接,如发送和接受数据.为了建立通信通道,网络通信 ...
- 20162311 解读同伴的收获&解决同伴的问题(11月29日,周三)
20162311 解读同伴的收获&解决同伴的问题(11月29日,周三) 解读同伴的收获 我的同组同学是20162325学号金立清同学 同组同学的收获是:递归算法的非递归实现.分治法.动态规划法 ...
- cygwin下使用apt-cyg安装新软件
1.获取 (记得先安装好git) git clone https://github.com/transcode-open/apt-cyg.git 2.安装apt-cyg cd apt-cyg chm ...
- react 为元素添加自定义事件监听器
https://zhenyong.github.io/react/tips/dom-event-listeners.html class MovieItem extends React.Compone ...
- Java LinkedList源码剖析
LinkedList 本文github地址 总体介绍 LinkedList同时实现了List接口和Deque接口,也就是说它既可以看作一个顺序容器,又可以看作一个队列(Queue),同时又可以看作一个 ...
- UVa 10163 仓库守卫
https://vjudge.net/problem/UVA-10163 题意: 有n个仓库,m个管理员,每个管理员有一个能力值P(接下来的一行有m个数,表示每个管理员的能力值) 每个仓库只能由一个管 ...