【A了两道题的沈阳赛】2015 ACM/ICPC Asia Regional Shenyang Online
2015-09-20 20:48
323 查看
L - Largest Point
时限:1000MS 内存:32768KB 64位IO格式:%I64d & %I64u
问题描述
Given the sequence A with n integers t1,t2,⋯,tn. Given the integral coefficients a and b. The fact that select two elements ti and tj of A and i≠j to maximize the value of at2i+btj, becomes the largest point.
输入
An positive integer T, indicating there are T test cases.
For each test case, the first line contains three integers corresponding to n (2≤n≤5×106), a (0≤|a|≤106) and b (0≤|b|≤106). The second line contains n integers t1,t2,⋯,tn where 0≤|ti|≤106 for 1≤i≤n.
The sum of n for all cases would not be larger than 5×106.
输出
The output contains exactly T lines.
For each test case, you should output the maximum value of at2i+btj.
样例输入
2
3 2 1
1 2 3
5 -1 0
-3 -3 0 3 3
样例输出
Case #1: 20
Case #2: 0
时限:1000MS 内存:32768KB 64位IO格式:%I64d & %I64u
问题描述
Given the sequence A with n integers t1,t2,⋯,tn. Given the integral coefficients a and b. The fact that select two elements ti and tj of A and i≠j to maximize the value of at2i+btj, becomes the largest point.
输入
An positive integer T, indicating there are T test cases.
For each test case, the first line contains three integers corresponding to n (2≤n≤5×106), a (0≤|a|≤106) and b (0≤|b|≤106). The second line contains n integers t1,t2,⋯,tn where 0≤|ti|≤106 for 1≤i≤n.
The sum of n for all cases would not be larger than 5×106.
输出
The output contains exactly T lines.
For each test case, you should output the maximum value of at2i+btj.
样例输入
2
3 2 1
1 2 3
5 -1 0
-3 -3 0 3 3
样例输出
Case #1: 20
Case #2: 0
#include<cstdio> #include<cstring> #include<cmath> #include<cstdlib> #include<ctime> #include<iostream> #include<algorithm> #include<sstream> #include<fstream> #include<vector> #include<map> #include<stack> #include<list> #include<set> #include<queue> #define LL long long #define lson l,m,rt<<1 #define rson m+1,r,rt<<1 | 1 /* 正反循环的宏定义 */ #define ffr(i,x,y) for(int i=(x),_en=(y);i<=_en;i++) #define rff(i,x,y) for(int i=(x),_en=(y);i>=_en;i--) #define clr(f,z) memset(f,z,sizeof(f)) using namespace std; const int maxn=1000005,inf=1<<29; int dir[][2]={ {0,1},{-1,0},{0,-1},{1,0},{-1,1},{-1,-1},{1,-1},{1,1}};//常用方向数组 vector<int>G[maxn];//常用邻接表 /* 函数重载,可根据参数类型,自动选择输入 */ bool sf(int &x) { return scanf("%d",&x)==1;} bool sf(char *x){return scanf("%s",x)==1;} bool sf(double &x){return scanf("%lf",&x)==1;} bool sf(LL &x) { return scanf("%I64d",&x)==1;} void pf(int x,int op) { op?printf("%d\n",x):printf("%d ",x);//op==0打印数字加空格,op==1打印数字加换行 } void pf(LL x,int op) { op?printf("%I64d\n",x):printf("%I64d ",x);//op==0打印数字加空格,op==1打印数字加换行 } int get_rand(int n) { return (int)((double)rand() / RAND_MAX * n) ; } LL a,b,num[maxn]; LL get(LL x,LL y) { return a*x*x+b*y; } struct node{ LL x; int id; } A[maxn],B[maxn]; bool cmp(node a,node b) { return a.x<b.x; } int main() { //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); //srand(time(NULL)); int n,t,Case=1; sf(t); while(t--) { sf(n);sf(a);sf(b); //pf(n,0),pf(a,1),pf(b,1); ffr(i,0,n-1) { sf(num[i]); A[i].x=a*num[i]*num[i]; A[i].id=i; B[i].x=b*num[i]; B[i].id=i; } sort(A,A+n,cmp);sort(B,B+n,cmp); LL ans; if(A[n-1].id!=B[n-1].id) ans=A[n-1].x+B[n-1].x; else { ans=max(A[n-1].x+B[n-2].x,A[n-2].x+B[n-1].x); } printf("Case #%d: %I64d\n",Case++,ans); } return 0; }
相关文章推荐
- 如何保证黑盒测试的覆盖率(转)
- eclipse的环境变量的配置
- java__反射、批处理、对象拷贝
- C++ primer 5 笔记3 chapter 3 字符串, 向量和数组
- memcache知识梳理
- 线程池中使用条件变量和信号量的性能比较
- 人际关系
- Android应用——用LayoutTransition在View动态显示和隐藏时候加上动画
- Centos下安装jdk8、tomcat8
- Linux 基础入门(新版)”实验报告一~十二
- DOM 操作方法的简单归纳
- 转 一次完整地http请求
- DNS相关概念
- c++设计模式----Flyweight(享元)
- 我的linux学习之路-文件的创建于删除
- 特斯拉遭保时捷奥迪宝马围攻 电动汽车格局变天?
- MSYS2开发环境搭建
- HttpServletResponse响应
- thinkphp的问题
- bash的循环语句和列表