题目链接:http://codeforces.com/contest/821/problem/B

题意:二维每个整点坐标(x,y)拥有的香蕉数量为x+y,现在给你一个直线方程的m和b参数,让你找一个位于这个直线下方的点,该点与原点构成的长方形区域里面的香蕉数量最多。

思路:由方程可以得知y的取值在[0,b]之间,所以枚举y,然后通过方程解出一个最接近解的整数x,然后就是普通的计算了。 对于计算通过预处理一个等差数列的前缀和就可以O(1)计算结果了。

#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<time.h>
#include<cmath>
using namespace std;
typedef long long int LL;
const LL INF = ;
const int MAXN = 1e7 + ;
LL sum[MAXN];
void Init(){
sum[] = ;
for (int i = ; i < MAXN; i++){
sum[i] = sum[i - ] + i;
}
}
int main(){
//#ifdef kirito
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
//#endif
// int start = clock();
int m, b; Init();
while (~scanf("%d%d",&m,&b)){
LL ans = -;
for (int y = ; y <= b; y++){
LL x = (b - y)* m;
if (x >= ){
ans = max(ans, 1LL * (sum[y] * (x + ) + sum[x] * (y + )));
}
}
printf("%I64d\n", ans);
}
//#ifdef LOCAL_TIME
// cout << "[Finished in " << clock() - start << " ms]" << endl;
//#endif
return ;
}

Codeforces Round #420 (Div. 2) - B的更多相关文章

  1. 【Codeforces Round #420 (Div. 2) C】Okabe and Boxes

    [题目链接]:http://codeforces.com/contest/821/problem/C [题意] 给你2*n个操作; 包括把1..n中的某一个数压入栈顶,以及把栈顶元素弹出; 保证压入和 ...

  2. 【Codeforces Round #420 (Div. 2) B】Okabe and Banana Trees

    [题目链接]:http://codeforces.com/contest/821/problem/B [题意] 当(x,y)这个坐标中,x和y都为整数的时候; 这个坐标上会有x+y根香蕉; 然后给你一 ...

  3. 【Codeforces Round #420 (Div. 2) A】Okabe and Future Gadget Laboratory

    [题目链接]:http://codeforces.com/contest/821/problem/A [题意] 给你一个n*n的数组; 然后问你,是不是每个位置(x,y); 都能找到一个同一行的元素q ...

  4. Codeforces Round #420 (Div. 2) - C

    题目链接:http://codeforces.com/contest/821/problem/C 题意:起初有一个栈,给定2*n个命令,其中n个命令是往栈加入元素,另外n个命令是从栈中取出元素.你可以 ...

  5. Codeforces Round #420 (Div. 2) - E

    题目链接:http://codeforces.com/contest/821/problem/E 题意:起初在(0,0),现在要求走到(k,0),问你存在多少种走法. 其中有n条线段,每条线段为(a, ...

  6. Codeforces Round #420 (Div. 2) - A

    题目链接:http://codeforces.com/contest/821/problem/A 题意:给定一个n*n的矩阵. 问你这个矩阵是否满足矩阵里的元素除了1以外,其他元素都可以在该元素的行和 ...

  7. Codeforces Round #420 (Div. 2)

    /*************************************************************************************************** ...

  8. Codeforces Round #420 (Div. 2) A,B,C

    A. Okabe and Future Gadget Laboratory time limit per test 2 seconds memory limit per test 256 megaby ...

  9. Codeforces Round #420 (Div. 2) E. Okabe and El Psy Kongroo 矩阵快速幂优化dp

    E. Okabe and El Psy Kongroo time limit per test 2 seconds memory limit per test 256 megabytes input ...

随机推荐

  1. NIO编程模式示例

    1. 服务端 import java.net.InetSocketAddress; import java.nio.ByteBuffer; import java.nio.channels.*; im ...

  2. NIO之Buffer操作示例

    1. buffer常规操作 略 2. 只读buffer /** * 只读buffer */ public class BufferTest01 { public static void main(St ...

  3. Jenkins镜像

    https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json

  4. Influxdb根据配置文件启动(Influxdb的数据存储)

    1.在Influxdb文件夹下建立一个bat文件 2.文件内容如下: @echo offSETLOCAL :: 获取当前批处理所在路径SET InfluxdP==%~dp0 :: 开启influxdb ...

  5. Web上传文件的三种解决方案

    第一点:Java代码实现文件上传 FormFile file = manform.getFile(); String newfileName = null; String newpathname =  ...

  6. jsp选择文件夹上传

    文件夹数据库处理逻辑 publicclass DbFolder { JSONObject root; public DbFolder() { this.root = new JSONObject(); ...

  7. Python_014(面向对象之继承)

    一.面向对象之继承 1.初始继承 引入:面向对象的三大特性:继承,多态,封装 a.继承是创建新类的一种方式,在python中,新建的类可以继承一个或多个父类,父类又可称为基类或超类;新建的类称为派生类 ...

  8. C# 中获取路径

    string str1 =Process.GetCurrentProcess().MainModule.FileName;//可获得当前执行的exe的文件名. string str2=Environm ...

  9. C#用户自定义控件(含源代码)-透明文本框

    using System; using System.Collections; using System.ComponentModel; using System.Drawing; using Sys ...

  10. IntelliJ IDEA中创建xml文件

      1.file—setting,左上角输入template, 2.在左侧栏找到File And Code Templates 3.中间选中Files 4.点击+号,添加模板 5.输入模板名字:Nam ...