Largest Point(2015年吉林网络赛)
来源:互联网 发布:mac电脑pdf转换成ppt 编辑:程序博客网 时间:2024/04/29 15:10
思路:
所求多项式由两项相加
贪心思路:
每项尽可能大
扫描集合元素统计其最大值
可能会出现两项取相同的数时值最大
所以需要统计次大值和所取元素的位置标记
重合时替换其中一个为次大值
替换方案有两种,取较大的即可
#include <algorithm>#include <stdio.h>#include <math.h>#define LL long long#define MIN (-1e18-1)using namespace std;struct node{ int key; LL v;};int main(){int T;scanf("%d", &T);for(int j = 1; j <= T; j++){ node res1a, res1b, res2a, res2b; res1a.v = MIN; res1b.v = MIN; res2a.v = MIN; res2b.v = MIN; LL node_num, a, b;scanf("%lld %lld %lld", &node_num, &a, &b);for (int i = 0; i < node_num; ++i){LL temp, temp2, temp_res1, temp_res2;scanf("%lld", &temp);temp2 = temp*temp;temp_res1 = a*temp2;temp_res2 = b*temp;if(temp_res1 > res1a.v) // 统计二次项最大值 { res1b.v = res1a.v; res1a.v = temp_res1; res1a.key = i; } else if(temp_res1 > res1b.v) // 统计二次项次大值 { res1b.v = temp_res1; res1b.key = i; } if(temp_res2 > res2a.v) // 统计一次项最大值 { res2b.v = res2a.v; res2a.v = temp_res2; res2a.key = i; } else if(temp_res2 > res2b.v) // // 统计一次项次大值 { res2b.v = temp_res2; res2b.key = i; }}LL res;if(res1a.key!=res2a.key) // 判重 res = res1a.v+res2a.v; else { res = res1a.v+res2b.v; res = max(res, res1b.v+res2a.v); }printf("Case #%d: %lld\n",j, res);}}
0 0
- Largest Point(2015年吉林网络赛)
- HDU5461 Largest Point 贪心(2015acm沈阳网络赛)
- HDU 5461 2015沈阳网络赛 Largest Point (暴力)
- Minimum Cut(2015年吉林网络赛)
- Jesus Is Here(2015年吉林网络赛)
- HDU 5461 Largest Point(2015沈阳赛区网络赛+技巧水题)
- HDOJ 5461 Largest Point(沈阳网络赛)
- HDU 5461 2015沈阳网络赛水题 Largest Point
- Largest Point
- Largest Point
- Largest Point
- hdu5461 Largest Point(沈阳网赛)
- hdu 5461 Largest Point
- HDU 5461 Largest Point
- HDU5461 Largest Point 贪心
- hdu 5461 Largest Point
- HDU 5461Largest Point
- HDU-5461 Largest Point
- OCPV13.02-638
- StoryBoard和代码结合 按比例快速兼容iPhone6/6 Plus教程
- 调整数组顺序使奇数位于偶数前面
- 三级联动
- iOS8下,如何去掉系统自带的滑动返回手势?
- Largest Point(2015年吉林网络赛)
- WatchOS 2 Glance Interface 数据内容更新
- web前端学习常遇到的坑
- c++ primer第五版(中文)习题答案 第十章第二节第二小节-写容器元素的算法
- 关于堆上的内存释放
- uCOS-II时钟相关函数介绍
- 最大间隔
- linux守护进程
- IT大牛的数据挖掘算法到架构师等的职业进化