个人博客链接:​​https://blog.nuoyanli.com/2020/04/03/hdu5504/​

题目链接

​http://acm.hdu.edu.cn/showproblem.php?pid=5504​

题意

HDU5504简单思路毒瘤_ios个数,选至少一个的最大乘积是多少,中间不会炸HDU5504简单思路毒瘤_#define_02

思路

比赛的时候的思路:

把非HDU5504简单思路毒瘤_#include_03的数乘起来,
如果HDU5504简单思路毒瘤_#include_04小于HDU5504简单思路毒瘤_#include_03,且HDU5504简单思路毒瘤_#include_04不等于最大的负数,就输出HDU5504简单思路毒瘤_#include_04/最大负数
如果全都是0,那么就输出HDU5504简单思路毒瘤_#include_03,否则输出HDU5504简单思路毒瘤_#include_04

感觉这个思路没有一点问题,但是就是错了,我写HDU5504简单思路毒瘤_ios_10了十几次了吧,不想改这个思路了,求大佬HDU5504简单思路毒瘤_ios_11

赛后HDU5504简单思路毒瘤_#include_12思路:

把非HDU5504简单思路毒瘤_#include_03的数乘起来,

  • 如果全部为HDU5504简单思路毒瘤_#define_14答案为HDU5504简单思路毒瘤_#define_14
  • 如果只有一个负数,其他都为HDU5504简单思路毒瘤_#define_14答案为HDU5504简单思路毒瘤_#define_14
  • 剩下的就是对负数的数量讨论:
  • 如果负数是偶数个,直接输出前面乘积即可
  • 如果负数是奇数个,输出前面乘积除最大负数即可

参考代码

// nuoyanli
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

//#include <bits/stdc++.h>
using namespace std;
#define
#define
#define
#define
#define
//#define in
#define
#define
#define
#define
const double pi = acos(-1.0);
const double eps = 1e-9;
typedef long long LL;
const int N = 1e5 + 10;
const int M = 1e3 + 10;
const int mod = 2015;
const LL inf = 1e18;
const double f = 2.32349;
int a[N], b[N];
void solve() {
IOS;
int t, k = 0;
cin >> t;
while (t--) {
int n;
cin >> n;
int tot = n, tot_0 = 0, tot_f = 0;
LL ans = 1, Max =-inf;
while (n--) {
LL x;
cin >> x;
if (x < 0) {
Max = max(Max, x);
tot_f++;
}
if (x != 0) {
ans *= x;
} else {
tot_0++;
}
}

if (tot_f & 1) {
if (tot_f == 1) {
if (tot_f + tot_0 == tot && tot_0 != 0) {
ans = 0;
} else if (tot_f != tot && tot_f + tot_0 != tot) {
ans = ans / Max;
}
} else {
ans = ans / Max;
}
} else if (tot == tot_0) {
ans = 0;
}
cout << ans << endl;
}
}
signed main() {
#ifdef
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
solve();
return 0;
}