Codeforces gym 100685 E

Description
standard input/output
Statements

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

Input
7
1 3 0 -1 -2 0.5 3

Output
4
2 4 5 7

思路:1.对于每个大于1的数,选择。 2.对于负数,从小到大排序,每次选择最小的两个, 若其乘积大于1,选择,否则,退出(负数其绝对值在减小,后面数一定不大于)。3.若此时选择集合为空,则比较最小的两个负数乘积(此时正数中全部小于1,相乘后变小)与整个数列最大的数,选择其中最大的。


#include<iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>
#include  <stack>

using namespace  std;

int main() {
#ifdef LOCAL
    freopen( "IN.txt" "r" , stdin);
#endif
    int N;
    cin  >> N;
    vector< int> ans;
    int max = - 100000000, max_pos;
    vector< pair< intint> > negative;
    for ( int i =  0; i < N; ++i) {
        double tmp;
        cin  >> tmp;
        int x = tmp *  100; //题目是两位小数,乘100扩展为整数
        if (x >  100) ans.push_back(i +  1);  //如果是大于1的,就一定要加到答案组中
        else {
            if (x > max) { //记录数组中不大于1的最大值及其位置
                max = x;
                max_pos = i;
            }
            negative.push_back(pair< intint>(x, i));
        }
    }

    sort(negative.begin(), negative.end());
    //如果两个负数相乘的值大于1,也给他加到答案中
    for ( int i =  1; i < negative.size() && negative [i ]. first && negative [i- 1 ]. first && ( long long)negative [i ]. first * ( long long)negative [i -  1 ]. first 10000; i +=  2) {
        ans.push_back(negative [i ]. second 1);
        ans.push_back(negative [i -  1 ]. second 1);
    }

    if (!ans.size()) {
        if (negative.size() >=  && negative [ 0 ]. first * negative [ 1 ]. first > max *  100) { //为什么是0.first * 1.first 和 max * 100 比呐,是因为0 和 1都是乘了100的,他俩再相乘肯定比max自己多乘了一个100,所以给max也乘一个100,就像上边 > 10000 一样
            ans.push_back(negative [ 0 ]. second 1);
            ans.push_back(negative [ 1 ]. second 1);
        }  else
            ans.push_back(max_pos +  1);
    }
    sort(ans.begin(), ans.end());
    cout  << ans.size()  << endl;
    for ( int i =  0; i < ans.size(); ++i) {
        if (i !=  0) cout  <<  ' ';
        cout  << ans [i ];
    }

    return  0;
}  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值