Codeforces gym 100685 E. Epic Fail of a Genie 贪心

时间:2021-11-19 06:42:53

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");
}