Codeforces Round #420 B. Okabe and Banana Trees

来源:互联网 发布:王者荣耀网络问卷调查 编辑:程序博客网 时间:2024/06/04 23:08

题目网址: Codeforces Round #420 B. Okabe and Banana Trees

题意分析:

  • 题意: 给定一条直线的方程, 求直线与x轴, y轴正方向所围成区域中的一个矩形,该矩形中的点(x, y), 使得矩形所有点 x+y的和最大.

  • 思路: 只要知道矩形的长和宽, 即 纵坐标最大值, 横坐标最大值, 根据推导, 可得, 每一条竖线 都会有 1….y, 每一条横线都有 1 … x, 所以 值等于 ans =(1+y)* y/2 * (x+1) + (1+x)* x/2 * (y+1), 求 ans最大值即可

代码:

#include <iostream>using namespace std;long long result(long long a, long long b){    return (a+1)*a/2*(b+1) + (b+1)*b/2*(a+1);}int main(int argc, char const *argv[]){    long long m, b;    while (~scanf("%I64d %I64d", &m, &b))    {        long long ans = 0;        for (long long y = b; y >= 0; --y)        {            long long x = (b-y)*m;            ans = max(ans, result(x, y));        }        printf("%I64d\n", ans);    }    return 0;}
原创粉丝点击