HDU 5504 GT and sequence
2015-10-30 20:35
288 查看
坑点比较多的一个题目
#include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using namespace std; long long z[100],f[100]; int T,N; int totz,totf,tot0; long long ans,x; int main() { scanf("%d",&T); while(T--) { totz=0;totf=0;tot0=0; scanf("%d",&N); for(int i=0;i<N;i++) { scanf("%lld",&x); if(x==0) tot0++; else if(x>0) z[totz++]=x; else if(x<0) f[totf++]=x; } sort(f,f+totf); if(totz>0) { ans=1; for(int i=0;i<totz;i++) ans=ans*z[i]; if(totf%2==0)for(int i=0;i<totf;i++) ans=ans*f[i]; else for(int i=0;i<totf-1;i++) ans=ans*f[i]; } else { if(totf==0) ans=0; if(totf==1&&tot0==0) ans=f[0]; if(totf==1&&tot0!=0) ans=0; if(totf>=2) { ans=1; if(totf%2==0)for(int i=0;i<totf;i++) ans=ans*f[i]; else for(int i=0;i<totf-1;i++) ans=ans*f[i]; } } printf("%lld\n",ans); } return 0; }
相关文章推荐
- ResultSet rs = stmt.executeQuery(sql); 返回值问题判断
- ResultSet rs = stmt.executeQuery(sql); 返回值问题判断
- sicily 1122. Prerequisites?
- IOS开发—UIScrollView的contentSize、contentInset、contentOffset的理解
- UI --- Xcode7 模拟器运行时崩溃解决方法
- CloudSuite之Web Search Benchmark环境搭建
- UI --- UIView 画圆和矩形
- 2015 CCPC D- Pick The Sticks(UESTC 1218) (01背包变形)
- UITableView的图片自适应高度
- 详细讲解安装HUE
- UITableView的cell自适应高度
- Java 反编译利器 JD-GUI/Jad/JadClipse
- Codeforces Round #327 (Div. 2) D. Chip 'n Dale Rescue Rangers
- puer工具的使用
- RHEL5.8修改yum源为163的源
- STL-单向队列queue
- UIScrollView和UIPageControl 实现让图片无限循环播放和左右滑动
- 解决"mex setup或mbuild setup找不到编译器"问题
- ui router digest 10 time
- 1062. Talent and Virtue