CodeForces
来源:互联网 发布:php开发流程 编辑:程序博客网 时间:2024/06/07 23:50
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.
题意:给出函数的m和b。函数图像与X轴,Y轴围成的区域中选取一个矩形。求该矩形所围区域各坐标(X+Y)的和的最大值,要求X和Y都是整数;
思维和数学。这个点一定是在函数图像上。y的取值范围是[0,b],x的取值范围是[0,m*b]。所以我们依次枚举y,这样也可以避免x为小数的情况。
矩形所围的横纵坐标各构成公差为1的等差数列
所以 对于所有横坐标的和有:(i+1)*(x*(x+1)/2) 对于纵坐标有:(x+1)*(i*(i+1)/2) i为所枚举的纵坐标
最后依次遍历取最大;
#include<stdio.h>#include<algorithm>using namespace std;int main(){ long long m,b,y,i,j,k,x,t; while(scanf("%lld%lld",&m,&b)!=EOF) { long long ans=0; for(i=b;i>=0;i--) { x=(b-i)*m; long long t=(i+1)*(x*(x+1)/2)+(x+1)*(i*(i+1)/2); ans=max(ans,t); } printf("%lld\n",ans); }}
- codeforces~~~
- Codeforces
- codeforces
- Codeforces
- codeforces
- codeforces
- Codeforces
- Codeforces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- 双色球中奖
- 入门级RxJava
- 正则表达式 re.findall 用法
- 目前普遍使用的框架是ssm框架,ssh框架基本是以前的项目中用到
- 项目编译报错 未配置输出路径
- CodeForces
- CTreeCtrl基本使用
- Codevs 3304 水果姐逛水果街Ⅰ
- 高级程序员的自我修养
- C# ORM 泛型与反射的交叉应用
- 23种设计模式(4):建造者模式
- 算法竞赛入门经典--训练指南 笔记
- Java线程(一)
- vue-cli手脚架模板使用sass