摘要
题目链接 |
难度等级 |
完成状态 |
完成分数 |
最后编辑时间 |
失误原因(初次提交分数)
|
Inna, Dima and Song
|
★☆☆☆☆
|
答案正确
|
100
|
2015-02-26 14:07:03
|
遗漏条件(3)
|
题意
两个人合奏,每个人的音量为Xi,Yi,要求Xi+Yi=Bi且max(Xi,Yi)<=Ai,同时满足S=sum{Xi*Yi},求S的最大值。(无法满足条件输出-1)
题解
- 由基本不等式容易知道使得Xi,Yi尽量接近且满足要求即可(第一次做遗漏b=1情况,还以为精度不够,其实没必要高精度)。
代码
390B.java代码已折叠
展开折叠内容
|
- import java.io.*;
- import java.math.*;
- import java.util.*;
- public class Main{
- public static void main(String[] args) {
- Scanner cin = new Scanner(new BufferedInputStream(System.in));
- int n;
- BigInteger a[]=new BigInteger[100010],ans=BigInteger.ZERO;
- n=cin.nextInt();
- for(int i=1;i<=n;++i)
- a[i]=cin.nextBigInteger();
-
- for(int i=1;i<=n;++i)
- {
- BigInteger b=cin.nextBigInteger();
- if(a[i].multiply(BigInteger.valueOf(2)).compareTo(b)>=0 &&
- b.compareTo(BigInteger.ONE)>0)//fixed:b>1//
- ans=ans.add(b.divide(BigInteger.valueOf(2))
- .multiply((b.add(BigInteger.ONE)).divide(BigInteger.valueOf(2))));
- else
- ans=ans.subtract(BigInteger.ONE);
- }
- System.out.println(ans);
- return;
- }
- }
|