Warm up 15 Epic Fail of a Genie
| Epic Fail of a Genie |
| Time Limit: 10000ms, Special Time Limit:25000ms, Memory Limit:65536KB |
| Total submit users: 44, Accepted users: 24 |
| Problem 12770 : Special judge |
| Problem 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 ≤ 10 ) — 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 |
| Problem Source |
| HNU Contest |
| Submit Discuss Judge Status Problems Ranklist |
1 #pragma comment(linker, "/STACK:1024000000,1024000000") 2 #include <map> 3 #include <queue> 4 #include <vector> 5 #include <string> 6 #include <cmath> 7 #include <cstdio> 8 #include <cstring> 9 #include <cstdlib> 10 #include <iostream> 11 #include <algorithm> 12 using namespace std; 13 #define maxn 1305 14 #define ll long long 15 #define mod 1000000007 16 #define INF 0x7fffffff 17 #define eps 1e-8 18 int n, m; 19 double a[maxn]; 20 int main(){ 21 /*int t; 22 scanf("%d", &t); 23 while (t--){ 24 scanf("%I64d", &n); 25 26 }*/ 27 scanf("%d", &n); 28 double ma = -INF; 29 int cnt = INF; 30 for (int i = 0; i < n; i++)scanf("%lf", &a[i]); 31 for (int i = 0; i < (1 << n); i++){ 32 double s = 1; 33 int k = 0; 34 for (int j = 0; j < n; j++) 35 if (i&(1 << j)){ s *= a[j]; k++; } 36 if (k == 0)s = -INF; 37 if (abs(ma - s)<0.0001){ if (cnt > k){ cnt = k; m = i; } } 38 if (ma < s){ ma = s; m = i; cnt = k; } 39 } 40 printf("%d\n", cnt); 41 for (int i = 0; i<n; i++) 42 if (m&(1 << i))printf(i == n - 1 ? "%d\n" : "%d ", i + 1); 43 return 0; 44 }
浙公网安备 33010602011771号