HDU 5504 GT and sequence 模拟

时间:2023-01-29 21:04:27

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5504

思路:模拟

代码:

 #include<stdio.h>//------杭电5504
#include<algorithm>
#include<math.h>
#include<iostream>
using namespace std;
int comp(const void*a, const void*b)
{
return *(int*)a - *(int*)b;
}
int main()
{
int t;
scanf("%d", &t);
while (t)
{
__int64 *a;
int n;
int count1 = ;//记录负数
int count2 = ;//记录0
int count3 = ;//记录正数
int i;
__int64 result = ;
__int64 maxx = -0x3f3f3f3f;
scanf("%d", &n);
a = (__int64*)malloc(n*sizeof(__int64));
for (i = ; i < n; i++)
{
scanf("%I64d", (a + i));
if (a[i] < )
{
count1++;
maxx = max(maxx, a[i]);
}
else if (a[i]>)
count3++;
else
count2++;
}
qsort(a, n, sizeof(__int64), comp);//对数组排序
if (count1 == )//没有负数
{
if (count3 != )
{
if (count2 == )
i = ;
else
i = count2;
for (i; i < n; i++)
{
result *= a[i];
}
}
else if (count3 == )//无正数
{
result = ;
}
}
else if (count1 == )//只有一个负数
{
if (count3 != )
{
if (count2 == )
i = ;
else
i = count2 + count1;
for (i; i < n; i++)
{
result *= a[i];
}
}
else if (count3 == )//无正数
{
if (count2 == )
result *= a[];
else
result = ;
}
}
else if (count1 % == )//偶数个负数
{
for (i = ; i < count1; i++)
{
result *= a[i];
}
if (count3 != )
{
if (count2 == )
i = count1;
else
i = count2 + count1;
for (i; i < n; i++)
{
result *= a[i];
}
}
else if (count3 == )//无正数,值保留
{
result = result;
}
}
else if (count1 % != )//奇数个负数
{
for (i = ; i < count1-; i++)
{
result *= a[i];
}
if (count3 != )
{
if (count2 == )
i = count1;
else
i = count2 + count1;
for (i; i < n; i++)
{
result *= a[i];
}
}
else if (count3 == )//无正数,值保留
{
result = result;
}
}
printf("%I64d\n", result);
t--;
}
return ;
}