Codeforces 821B-Okabe and Banana Trees
来源:互联网 发布:公务员网络培训系统 编辑:程序博客网 时间:2024/06/05 06:31
Okabe needs bananas for one of his experiments for some strange reason. So he decides to go to the forest and cut banana trees.
Consider the point (x, y) in the 2D plane such that x and y are integers and 0 ≤ x, y. There is a tree in such a point, and it has x + ybananas. There are no trees nor bananas in other points. Now, Okabe draws a line with equation . Okabe can select a single rectangle with axis aligned sides with all points on or under the line and cut all the trees in all points that are inside or on the border of this rectangle and take their bananas. Okabe's rectangle can be degenerate; that is, it can be a line segment or even a point.
Help Okabe and find the maximum number of bananas he can get if he chooses the rectangle wisely.
Okabe is sure that the answer does not exceed 1018. You can trust him.
The first line of input contains two space-separated integers m and b (1 ≤ m ≤ 1000, 1 ≤ b ≤ 10000).
Print the maximum number of bananas Okabe can get from the trees he cuts.
1 5
30
2 3
25
The graph above corresponds to sample test 1. The optimal rectangle is shown in red and has 30 bananas.
题意:给你一条直线,在第一象限且在直线下画一个矩形,每个点(x,y)的香蕉数为x+y,矩形内包括边界上的香蕉可采,问最大香蕉数
解题思路:按y讨论,香蕉数可用y计算得到,首先计算出最右边界,然后用等差数列求和导出香蕉总数公式,若不这样计算,会超时
#include <iostream>#include <cstdio>#include <string>#include <cstring>#include <algorithm>#include <queue>#include <vector>#include <set>#include <stack>#include <map>#include <climits>using namespace std;#define LL long longconst int INF = 0x3f3f3f3f;int main(){LL m, b, sum, ans;while (~scanf("%lld %lld", &m, &b)){ans = 0;for (LL i = b; i >= 0; i--){LL k = b*m - i*m;sum = k*(k + 1)*(i + 1) / 2 + i*(i + 1)*(k + 1) / 2;ans = max(ans, sum);}printf("%lld\n", ans);}return 0;}
- Codeforces 821 B. Okabe and Banana Trees
- codeforces 821 B Okabe and Banana Trees
- Codeforces 821B-Okabe and Banana Trees
- codeforces -420-B. Okabe and Banana Trees
- Codeforces 821B Okabe and Banana Trees 题解
- Okabe and Banana Trees CodeForces
- Codeforces Round #420 (Div. 2) B. Okabe and Banana Trees
- Codeforces Round #420 B. Okabe and Banana Trees
- Codefroces 821B Okabe and Banana Trees(暴力)
- Codeforces#420 Okabe and Banana Trees
- CF #420 B. Okabe and Banana Trees
- CF821B-Okabe and Banana Trees
- Codeforces821B Okabe and Banana Trees
- #420 B. Okabe and Banana Trees(Div.2)
- CF#420 B. Okabe and Banana Trees 思维|暴力|几何
- Okabe and Banana Trees 思路题
- #420 Div.2 B. Okabe and Banana Trees——数学&暴力
- CF#420 Div.2 B. Okabe and Banana Trees(数学)
- 剑指offer——数组中只出现一次的数字(好题,熟悉位运算)
- SpringBoot之打包成war包部署到tomcat
- Git学习笔记
- 嵌入式C语言可靠性设计
- 僵尸进程与孤儿进程
- Codeforces 821B-Okabe and Banana Trees
- 8、插件(plugins)拦截器的配置详解
- Linux脚本下倒引号(`)与$()
- 八幅漫画理解使用 JSON Web Token 设计单点登录系统
- MySQL笔记
- mybatis
- Java 简单工厂模式
- SDUT 1122 判断素数(循环结构)
- JDBC 封装工具类