HDU 5504 GT and sequence 模拟
题目链接: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 ;
}
HDU 5504 GT and sequence 模拟的更多相关文章
- hdu 5504 GT and sequence
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5504 GT and sequence Time Limit: 2000/1000 MS (Java/O ...
- HDU - 1711 A - Number Sequence(kmp
HDU - 1711 A - Number Sequence Given two sequences of numbers : a[1], a[2], ...... , a[N], and b[1 ...
- HDU 5783 Divide the Sequence(数列划分)
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...
- 判断相同区间(lazy) 多校8 HDU 5828 Rikka with Sequence
// 判断相同区间(lazy) 多校8 HDU 5828 Rikka with Sequence // 题意:三种操作,1增加值,2开根,3求和 // 思路:这题与HDU 4027 和HDU 5634 ...
- HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011亚洲北京赛区网络赛)
HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011 亚洲北京赛区网络赛题目) Eliminate Witches! Time Limit: 2000/1000 ...
- hdu 4893 Wow! Such Sequence!(线段树)
题目链接:hdu 4983 Wow! Such Sequence! 题目大意:就是三种操作 1 k d, 改动k的为值添加d 2 l r, 查询l到r的区间和 3 l r. 间l到r区间上的所以数变成 ...
- Hdu 5496 Beauty of Sequence (组合数)
题目链接: Hdu 5496 Beauty of Sequence 题目描述: 一个整数序列,除去连续的相同数字(保留一个)后,序列的和成为完美序列和.问:一个整数序列的所有子序列的完美序列和? 解题 ...
- Hdu 5806 NanoApe Loves Sequence Ⅱ(双指针) (C++,Java)
Hdu 5806 NanoApe Loves Sequence Ⅱ(双指针) Hdu 5806 题意:给出一个数组,求区间第k大的数大于等于m的区间个数 #include<queue> # ...
- HDU 5063 Operation the Sequence(暴力)
HDU 5063 Operation the Sequence 题目链接 把操作存下来.因为仅仅有50个操作,所以每次把操作逆回去执行一遍,就能求出在原来的数列中的位置.输出就可以 代码: #incl ...
随机推荐
- 用户关注微信公众号后,获取该用户的openID存数据库失败
关注微信公众号后将关注人的openID存入数据库失败,而openID换成字符串写死却可以存入数据库: $wxid=$postObj->FromUserName; $data['wx_openid ...
- 编程&blog处女篇-用C#求100以内的质数
using System;namespace Loops{ class Program { static void Main(string[] args) { /*局部变量定义*/ int i, j; ...
- Javascript的RegExp对象(转载自网络)
正则表达式是一个描述字符模式的对象. JavaScript的RegExp对象和String对象定义了使用正则表达式来执行强大的模式匹配和文本检索与替换函数的方法. '***************** ...
- HDU 6055 Regular polygon
Regular polygon Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)T ...
- Fibonacci Check-up
Fibonacci Check-up Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- Log4j – Log4j 2 API
Overview The Log4j 2 API provides the interface that applications should code to and provides the ad ...
- Mysql修改已有数据的字符集
Mysql修改已有数据的字符集 问题 在生产环境中跑了很久,发现MysqlClient连接的字符集是默认的latin1,我们一直以为都是utf8,造成这样的误解,是因为在内网环境中,我们是源码编译的M ...
- instanceof 原理
运行流程 function instance_of(L, R) { //L 表示左表达式,R 表示右表达式 var O = R.prot ...
- 处理ASP.NET Core中的HTML5客户端路由回退
在使用由Angular,React,Vue等应用程序框架构建的客户端应用程序时,您总是会处理HTML5客户端路由,它将完全在浏览器中处理到页面和组件的客户端路由.几乎完全在浏览器中... HTML5客 ...
- [转载] 基于Redis实现分布式消息队列
转载自http://www.linuxidc.com/Linux/2015-05/117661.htm 1.为什么需要消息队列?当系统中出现“生产“和“消费“的速度或稳定性等因素不一致的时候,就需要消 ...