E. Epic Fail of a Genie
Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/gym/100685/problem/E

Description

Aladdin had found a new shiny lamp and has started polishing it with his hands. Suddenly a mysterious genie appeared from within and offered Aladdin to fulfill any of his three wishes. Genie had a very subtle humor that made Aladdin very sceptical about him. Aladdin didn't believe that genie was so powerful that could do anything he had wished and asked him to become a mouse. The genie did that without hesitation. Then Aladdin asked genie to become a mouse pad. Genie didn't like this kind of wish but had to submit. Finally Aladdin tested genie's abilities in math: he had to choose a nonempty subset giving the maximum product from the given set of numbers. Genie was shocked. Math was his Achilles' heel, however he was able to contact anyone on earth to help him. You are a secret weapon of the genie — help him solve the test and avoid this epic fail. This is the last chance for the genie: he'll be forever jailed in the lamp if his new master doesn't trust him.

Input

The first line of input contains an integer N (2 ≤ N ≤ 104) — the cardinality of a set of numbers.

The second line of input contains N floating-point numbers with absolute value not more than 106. The fractional part of each number does not contain more than two digits.

Output

The first line of the output should contain a single integer M — the total number of numbers that genie should choose from the set.

The second line of output should contain 1-based indexes of these numbers. Indexes must be sorted in ascending order. If multiple solutions exist please output the one with the minimal subset cardinality. If there are still several suitable solutions output any of them.

Sample Input

7
1 3 0 -1 -2 0.5 3

Sample Output

4
2 4 5 7

HINT

题意

给你一个集合,让你选择出一个非空子集,使得乘积最大

题解

1.大于1的正数必选

2.乘起来大于1的负数对也要选择

如果都没有

那么选择俩乘起来大的负数,或者一个较大的正数

虽然感觉会卡eps……

但是并没有?

代码

#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define test freopen("test.txt","r",stdin)
#define maxn 20001
#define mod 1000000007
#define eps 1e-9
const int inf=0x3f3f3f3f;
const ll infll = 0x3f3f3f3f3f3f3f3fLL;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
//************************************************************************************** vector<int> Q;
struct node
{
int x,y;
};
struct point
{
double x;
int y;
};
bool cmp(point a,point b)
{
return a.x<b.x;
}
double a[maxn];
vector<point> T;
int main()
{
node tmp;
tmp.x=,tmp.y=;
int n=read();
for(int i=;i<=n;i++)
scanf("%lf",&a[i]);
int flag=; for(int i=;i<=n;i++)
{
if(fabs(a[i])>&&a[i]>)
{
Q.push_back(i);
flag=;
}
} for(int i=;i<=n;i++)
{
if(a[i]<)
{
point kiss;
kiss.x=a[i];
kiss.y=i;
T.push_back(kiss);
}
}
if(T.size()!=)
{ sort(T.begin(),T.end(),cmp);
for(int i=;i<T.size()-;i++)
{
if(T[i].x*T[i+].x>)
{
Q.push_back(T[i].y);
Q.push_back(T[i+].y);
i++;
flag = ;
}
}
}
a[]=;
if(flag)
{
int max1=,max2=;
int max3=;
for(int i=n;i>=;i--)
{
if(a[i]<)
{
if(fabs(a[i])>=fabs(a[max1]))
{
max2=max1;
max1=i;
}
else if(fabs(a[i])>=fabs(a[max2]))
{
max2=i;
}
}
else
{
if(fabs(a[i])>=fabs(a[max3]))
{
max3=i;
}
}
} if(max3==)
{
if(max2==)
Q.push_back(max1);
else
Q.push_back(max1),Q.push_back(max2);
}
else
{
if(max2==)
Q.push_back(max3);
else
{
double tmp1=a[max3],tmp2=a[max1]*a[max2];
if(tmp1-tmp2>-eps)
Q.push_back(max3);
else
Q.push_back(max1),Q.push_back(max2);
}
} }
sort(Q.begin(),Q.end());
printf("%d\n",Q.size());
for(int i=;i<Q.size();i++)
printf("%d ",Q[i]);
printf("\n");
}

Codeforces gym 100685 E. Epic Fail of a Genie 贪心的更多相关文章

  1. CodeForces Gym 100685E Epic Fail of a Genie (贪心,控制精度)

    题意:给定 n 个数,然后让从中选取一些数使得它们的总乘积最大.如果有多个,要求这些数尽量少,如果还有多个,随便输出一组即可. 析:一个贪心题,根据乘法的性质,很容易知道,如果一个数大于1,那么肯定要 ...

  2. CF Gym 100685E Epic Fail of a Genie

    传送门 E. Epic Fail of a Genie time limit per test 0.5 seconds memory limit per test 64 megabytes input ...

  3. Codeforces gym 100685 A. Ariel 暴力

    A. ArielTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100685/problem/A Desc ...

  4. Codeforces gym 100685 F. Flood bfs

    F. FloodTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100685/problem/F Desc ...

  5. Codeforces gym 100685 C. Cinderella 水题

    C. CinderellaTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100685/problem/C ...

  6. codeforce Gym 100685E Epic Fail of a Genie(MaximumProduction 贪心)

    题意:给出一堆元素,求一个子集,使子集的乘积最大,如有多个,应该使子集元素个数尽量小. 题解:贪心,如果有大于1的正数,那么是一定要选的,注意负数也可能凑出大于1的正数,那么将绝对值大于1的负数两两配 ...

  7. 程序员的Epic Fail [0]

    作为程序员,我们经常会被客户问的一个问题一定是不是说很容易么,为什么花了这么长时间.不得不说,程序员可能是最糟糕的计划者,按时按点按计划完成的软件项目永远是下一个项目.一个项目的延期,有很多这样那样的 ...

  8. Codeforces Gym 101252D&&floyd判圈算法学习笔记

    一句话题意:x0=1,xi+1=(Axi+xi%B)%C,如果x序列中存在最早的两个相同的元素,输出第二次出现的位置,若在2e7内无解则输出-1. 题解:都不到100天就AFO了才来学这floyd判圈 ...

  9. Codeforces Gym 101190M Mole Tunnels - 费用流

    题目传送门 传送门 题目大意 $m$只鼹鼠有$n$个巢穴,$n - 1$条长度为$1$的通道将它们连通且第$i(i > 1)$个巢穴与第$\left\lfloor \frac{i}{2}\rig ...

随机推荐

  1. 转《深入理解Java虚拟机》学习笔记之最后总结

    编译器 Java是编译型语言,按照编译的时期不同,编译器可分为: 前端编译器:其实叫编译器的前端更合适些,它把*.java文件转变成*.class文件,如Sun的Javac.Eclipse JDT中的 ...

  2. Java中的DeskTop类使用介绍

    在Jdk1.6以后新增加了一个类--DeskTop,在JDK中它的解释是这样的: The Desktop class allows a Java application to launch assoc ...

  3. binlog/relay_log的清理

    http://www.yuminstall.com/how-to-remove-mysql-relay-log.html CHANGE MASTER TO changes the parameters ...

  4. 高性能Server---Reactor模型-----Socket

    高性能Server---Reactor模型   原文地址:http://www.ivaneye.com/2016/07/23/iomodel.html 无处不在的C/S架构 在这个充斥着云的时代,我们 ...

  5. POJ 2253 Difference of Clustering

    题意:给出一堆点,求从起点到终点的所有通路中相邻点的距离的最大值的最小值.(意思就是自己百度吧……) 解法:用相邻点的最大值作为权值代替路径的距离跑最短路或者最小生成树.然后我写了一个我以为是优化过的 ...

  6. hdu 1506(dp求最大子矩阵)

    题意:容易理解... 分析:对于每个单位矩阵,我们先求出连续比它高的最左边的下标假设为l,然后求出比它高的最右边的下标假设为r,然后矩阵的面积就是(r-l+1)*1:我们从左到 右扫一遍,求出每个点的 ...

  7. [原创]个人工具 - YE快速复制助手(YeFastcopyHelper)

    版本:v1.3.216 更新时间:2014/02/16 * 代码完善 + 右键关于显示当前版本号,点击并链接到软件帮助页 Technorati 标签: NET,.NET 3.5,asion C#,Ch ...

  8. 初识HTML 5:关于它的三个三

    来源:http://www.ido321.com/949.html 一.HTML 5受欢迎的三个理由 1.IE.Google.Firefox.Safari.Opera等主流浏览器的支持 1.1  微软 ...

  9. Unbutu网卡驱动安装(Intel内置网卡8086:15b8)

    工作中需要在新的实验平台上安装unbuntu14.04操作系统,系统安装好之后发现无法连接网络,分析后是由于缺少网卡驱动的原因. 下面把分析问题的过程及安装网卡驱动步骤介绍如下: 查看PCI信息 su ...

  10. .net中的"异步"-手把手带你体验

    周二刚过,离5.1小长假还有那么一阵,北京的天气已经开始热起来了.洗完澡,突然想起博客园一位大哥暂称呼元哥吧,当时我写了一篇windows服务的安装教程(http://www.cnblogs.com/ ...