E. Epic Fail of a Genie
Time Limit:20 Sec
Memory limit:256 MB
Topic Connection
Http://codeforces.com/gym/100685/problem/E
Description
Aladdin had found a new shiny lamp and have started polishing it with his hands. Suddenly a mysterious genie appeared from within and offered Aladdin to fulfill all of his three wishes. Genie had a very subtle humor that made Aladdin very sceptical about him. Aladdin didn ' t believe that Genie is so powerful that could does 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 G Iven set of numbers. Genie was shocked. Math is his Achilles ' heel, however he is able to the contact anyone on Earth to help him. You is a secret weapon of the genie -help him solve the test and avoid this epic fail. The last chance for the Genie:he ' ll was forever jailed in the lamp if he 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 NU Mbers.
The second line of input contains N floating-point numbers with absolute value isn't more than 6. The fractional part of each number does not contain more than the digits.
Output
The first line of the output should contain a single integer M -the Total number of numbers that Genie SH Ould choose from the set.
The second line of output should contain 1-based indexes of these numbers. Indexes must is sorted in ascending order. If multiple solutions exist please output the one with the minimal subset cardinality. If there is 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
Test instructions
Give you a set that lets you choose a non-empty set that makes the product maximum
The following:
1. A positive number greater than 1 must be selected
2. Multiply a negative number greater than 1 to choose
If not all
So choose two large negative numbers, or a larger positive number.
Although the feeling will card EPS ...
But not?
Code
#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>typedefLong Longll;using namespacestd;//freopen ("d.in", "R", stdin);//freopen ("D.out", "w", stdout);#defineSspeed ios_base::sync_with_stdio (0); Cin.tie (0)#defineTest Freopen ("Test.txt", "R", stdin)#defineMAXN 20001#defineMoD 1000000007#defineEPS 1e-9Const intinf=0x3f3f3f3f;Constll infll =0x3f3f3f3f3f3f3f3fll;inline ll Read () {ll x=0, f=1;CharCh=GetChar (); while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} returnx*F;}//**************************************************************************************Vector<int>Q;structnode{intx, y;};structpoint{Doublex; inty;};BOOLCMP (point A,point b) {returna.x<b.x;}DoubleA[maxn];vector<point>T;intMain () {node tmp; Tmp.x=0, tmp.y=0; intn=read (); for(intI=1; i<=n;i++) scanf ("%LF",&A[i]); intflag=1; for(intI=1; i<=n;i++) { if(Fabs (A[i]) >1&&a[i]>0) {q.push_back (i); Flag=0; } } for(intI=1; i<=n;i++) { if(a[i]<0) {point kiss; Kiss.x=A[i]; Kiss.y=i; T.push_back (Kiss); } } if(T.size ()! =0) {sort (T.begin (), T.end (), CMP); for(intI=0; I<t.size ()-1; i++) { if(t[i].x*t[i+1].x>1) {q.push_back (T[I].Y); Q.push_back (T[i+1].y); I++; Flag=0; } }} a[0]=0; if(flag) {intmax1=0, max2=0; intmax3=0; for(inti=n;i>=1; i--) { if(a[i]<0) { 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==0) { if(max2==0) Q.push_back (MAX1); ElseQ.push_back (MAX1), Q.push_back (MAX2); } Else { if(max2==0) Q.push_back (MAX3); Else { Doubletmp1=a[max3],tmp2=a[max1]*A[MAX2]; if(tmp1-tmp2>-EPS) Q.push_back (MAX3); ElseQ.push_back (MAX1), Q.push_back (MAX2); }}} sort (Q.begin (), Q.end ()); printf ("%d\n", Q.size ()); for(intI=0; I<q.size (); i++) printf ("%d", Q[i]); printf ("\ n");}
Codeforces Gym 100685 E. Epic Fail of a Genie greedy