HDU 5461 Largest Point(求ax^2+by的最大值)
来源:互联网 发布:天涯明月刀 mac 编辑:程序博客网 时间:2024/05/07 23:10
题目地址:点击打开链接
题意:求ax^2+by的最大值,x和y在一个数组中
思路:2层暴力超时,那就一层暴力ax^2的所有情况,参考学长A的,思路不是很清晰,等我问清楚了再写详细的
AC代码:
#include <iostream>#include <cstdio>#include <cstdlib>#include <algorithm>#include <queue>#include <stack>#include <map>#include <cstring>#include <climits>#include <cmath>using namespace std;const int maxn = 5e6 + 10;long long map1[maxn];int main(){ int t,i; int n,a,b,cas=1; scanf("%d",&t); while(t--) { long long ans = -9223372036854775; long long temp; scanf("%d%d%d",&n,&a,&b); for(i=1; i<=n; i++) { scanf("%I64d",&map1[i]); } if(a == 0 && b == 0) { int l = 0; printf("Case #%d: %d\n",cas++,l); continue; } sort(map1+1,map1+n+1); for(i=1; i<=n; i++) { temp = a * map1[i] * map1[i]; if(i != 1 && i != n) { temp += b * map1[1] > b * map1[n] ? b * map1[1] : b * map1[n]; } else if(i == n) { temp += b * map1[n-1] > b * map1[1] ? b * map1[n-1] : b * map1[1]; } else if(i == 1) { temp += b * map1[n] > b * map1[2] ? b * map1[n] : b * map1[2]; } if(temp > ans) ans = temp; } printf("Case #%d: %I64d\n",cas++,ans); } return 0;}
0 0
- HDU 5461 Largest Point(求ax^2+by的最大值)
- hdu 5461 Largest Point
- HDU 5461 Largest Point
- hdu 5461 Largest Point
- HDU 5461Largest Point
- HDU-5461 Largest Point
- hdu 5461 Largest Point
- HDU 5461:Largest Point
- hdu 5461 Largest Point
- HDU 5461 Largest Point
- hdu 5461 Largest Point
- HDU 5461 Largest Point
- hdu 5461 Largest Point
- HDU 5461 Largest Point (水)
- hdu 5461 Largest Point(杂题)
- HDU 5461 Largest Point(水)
- HDU 5461 Largest Point (水题)
- hdu 5461 Largest Point(水)
- 第4周实践项目1-- 建立单链表
- matlab 图像保存函数及使用方法
- 第3周 项目2——数据结构之自建算法库——顺序表(程序的多文件组织形式)
- 第三周——【项目2 - 建设“顺序表”算法库】
- 汉字机内码
- HDU 5461 Largest Point(求ax^2+by的最大值)
- Excel VBA中的等价(Eqv)和蕴含(Imp)
- phpstrom配置xdebug
- redis学习之 aof
- php中curl的详细解说
- [MySQL分享]--interactive_timeout和wait_timeout小结(interactive_timeout会覆盖wait_timeout)
- HTML style 属性
- 利用keepalive和timeout来判断死连接
- 第四周 项目2-建立“单链表”算法库