[HDOJ5461]Largest Point
2015-09-19 19:04
363 查看
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5461
比赛的时候没敢多想,直接把八个情况全部枚举出来。
比赛的时候没敢多想,直接把八个情况全部枚举出来。
#include <cstdio> #include <cstring> #include <algorithm> #include <cmath> using namespace std; typedef long long LL; const int INF = 0x3f3f3f3f; const int maxn = 5000000+100; int t[maxn]; int n; int a,b; int main() { int T; scanf("%d",&T); for(int tt = 1;tt <= T;++tt) { scanf("%d %d %d",&n,&a,&b); for(int i = 1;i <= n;++i) { scanf("%d",&t[i]); } int maxx1 = 0,maxx2 = 0; int mn1 = INF,mn2 = INF; int mm1 = -INF,mm2 = -INF; int nn1 = INF,nn2 = INF; for(int i = 1;i <= n;++i) { if(t[i] > mm1) { mm2 = mm1; mm1 = t[i]; } else if(t[i] > mm2) mm2 = t[i]; if(t[i] < nn1) { nn2 = nn1; nn1 = t[i]; } else if(t[i] < nn2) nn2 = t[i]; if(abs(t[i]) > abs(maxx1)) { maxx2 = maxx1; maxx1 = t[i]; } else if(abs(t[i]) > abs(maxx2)) maxx2 = t[i]; if(abs(t[i]) < abs(mn1)) { mn2 = mn1; mn1 = t[i]; } else if(abs(t[i]) < abs(mn2)) mn2 = t[i]; } LL res1,res2; if(a >= 0) { res1 = (LL)a*maxx1*maxx1; if(b >= 0) { if(mm1 != maxx1) res1 += (LL)b*mm1; else res1+= (LL)b*mm2; } else { if(nn1 != maxx1) res1 += (LL)b*nn1; else res1 += (LL)b*nn2; } } else { res1 = (LL)a*mn1*mn1; if(b >= 0) { if(mm1 != mn1) res1 += (LL)b*mm1; else res1 += (LL)b*mm2; } else { if(nn1 != mn1) res1 += (LL)b*nn1; else res1 += (LL)b*nn2; } } if(b >= 0) { res2 = (LL)b*mm1; if(a >= 0) { if(maxx1 != mm1) res2 += (LL)a*maxx1*maxx1; else res2 += (LL)a*maxx2*maxx2; } else { if(mn1 != mm1) res2 += (LL)a*mn1*mn1; else res2 += (LL)a*mn2*mn2; } } else { res2 = (LL)b*nn1; if(a >= 0) { if(maxx1 != nn1) res2 += (LL)a*maxx1*maxx1; else res2 += (LL)a*maxx2*maxx2; } else { if(mn1 != nn1) res2 += (LL)a*mn1*mn1; else res2 += (LL)a*mn2*mn2; } } printf("Case #%d: %I64d\n", tt, max(res1,res2)); } return 0; }
相关文章推荐
- Android多线程机制之Handler
- Juniper SRX防火墙系统会话链接的清除
- CoreTFManagerVC 强大的键盘躲避管理器,完全解耦版本!
- 保存图片到自定义相册文件夹中,实现处理相册被用户误删的情况
- 自信,有风范儿,人生处处有奇迹。
- 对似然函数的理解
- [HDOJ5455]Fang Fang
- 【转载】-java Socket用法详解
- 自定义View(三) switch开关按钮 ViewDragHelper的使用初级
- Android高级控件小练习
- HDU 5461 Largest Point(关键在于最值)——2015 ACM/ICPC Asia Regional Shenyang Online
- 使用ATL创建简单ActiveX控件(二) —— 添加方法/属性和枚举
- redis 集群性能测试以及与单机性能对比
- Oracle压缩总结2— 估计表压缩效应
- 软件工程
- 接口理解2
- 动画Animation 和 xml 解析Animation
- 博客之感想
- HTML5拖放代码
- 二维数组的指针复习