题目链接: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. C++ decltype

    #include <iostream> using namespace std; int main() { int ia{3}; decltype(ia) varr[3]={1,2,3}; ...

  2. 关于富文本复制word,里面掺杂图片上传的问题

    图片的复制无非有两种方法,一种是图片直接上传到服务器,另外一种转换成二进制流的base64码目前限chrome浏览器使用首先以um-editor的二进制流保存为例:打开umeditor.js,找到UM ...

  3. inline-block的间隙问题 box-orient属性 line-clamp属性 margin问题

    只要设了 display:inline-block 将元素变成行级块元素的时候,会自带空隙,即使你设了 margin 和 padding 依然没有效果! 解决办法:只要在父元素上加上font-size ...

  4. I am going to India on a business trip

    I think English is very important,and learn it must perseverant.So I determined to write diary on Bo ...

  5. 【经验分享】 解决CentOS7 安装VMTools提示找不到Kernel头文件的方案

    配置一个Linux的开发环境,用VM10+CentOS7(Kernel版本3.10.0-327.10.1.el7),之后发现VMTools功能不全,查证后发现需要卸载重装,于是开始折腾. 按照各种说明 ...

  6. 《图解设计模式》读书笔记4-2 STRATEGY模式

    目录 示例程序 角色 想法 Strategy模式即策略模式,在编程中,策略指的就是算法.利用此模式可以整体替换算法,即使用不同方式解决同一个问题.比如设计一个围棋程序,通过切换算法可以方便地切换AI的 ...

  7. 【黑科技】花几分钟和孩子动手DIY,即可用手机完成全息影像!

    http://baobao.sohu.com/20160902/n467277059.shtml [黑科技]花几分钟和孩子动手DIY,即可用手机完成全息影像! 杭州亲子圈2016-09-02 07:2 ...

  8. Nginx 模块 - ngx_http_rewrite_module

    原文地址 ngx_http_rewrite_module 模块用于通过 PCRE 正则表达式改变请求 URI,返回重定向并可以有条件地选择配置. break.if.return.rewrite 以及 ...

  9. HDU 6583 Typewriter 题解

    ——本题来自杭电多校第一场 题意:给定一个字符串,主角需要用打字机将字符串打出来,每次可以: 1.花费p来打出任意一个字符 2.花费q来将已经打出的某一段(子串)复制到后面去 对于这种最优化的问题,我 ...

  10. MapReduce(3): Partitioner, Combiner and Shuffling

    Partitioner: Partitioning and Combining take place between Map and Reduce phases. It is to club the ...