codeforces 821 B Okabe and Banana Trees
2017-06-26 22:22
330 查看
题目:http://codeforces.com/contest/821/problem/B
大致题意:
给两个正整数m,b,画出一条直线y = -x/m + b,求直线下的一个矩形使得获取的香蕉数最多,每个点(x,y)的香蕉数目为 x+y。
解法:
可推得公式,矩形右上角为(x,y)的香蕉总数为
(x+1) * x / 2 * (y+1) + (y+1) * y /2 * (x+1)
然后,依次遍历直线上的格点,求出矩形右上角为格点坐标的香蕉总数,取最大值。
代码:
大致题意:
给两个正整数m,b,画出一条直线y = -x/m + b,求直线下的一个矩形使得获取的香蕉数最多,每个点(x,y)的香蕉数目为 x+y。
解法:
可推得公式,矩形右上角为(x,y)的香蕉总数为
(x+1) * x / 2 * (y+1) + (y+1) * y /2 * (x+1)
然后,依次遍历直线上的格点,求出矩形右上角为格点坐标的香蕉总数,取最大值。
代码:
#include <iostream> #include <algorithm> using namespace std; int main(){ long long m,b; cin >> m >> b; long long ans = -1; for(long long i = 0 ; i <= b; i++){ long long j = m * (b-i); ans = max(ans, (1+i) * i / 2 * (j+1) + (1+j) * j /2 * (i+1)); } cout << ans << endl; }
相关文章推荐
- Codeforces 821 B. Okabe and Banana Trees
- Codeforces 821B-Okabe and Banana Trees
- codeforces -420-B. Okabe and Banana Trees
- Codeforces Round #420 B. Okabe and Banana Trees
- CF821B-Okabe and Banana Trees
- CF #420 B. Okabe and Banana Trees
- CF#420 B. Okabe and Banana Trees 思维|暴力|几何
- CF#420 Div.2 B. Okabe and Banana Trees(数学)
- Codeforces 821 A. Okabe and Future Gadget Laboratory
- Okabe and Banana Trees CodeForces - 821B
- Codeforces#420 Okabe and Banana Trees
- #420 B. Okabe and Banana Trees(Div.2)
- Codeforces 821 E. Okabe and El Psy Kongroo
- Okabe and Banana Trees
- Codeforces Round #420 (Div. 2) B. Okabe and Banana Trees
- Codeforces 821 C. Okabe and Boxes
- codeforces B. Okabe and Banana Trees 结论题
- Codeforces 821 D. Okabe and City
- #420 Div.2 B. Okabe and Banana Trees——数学&暴力
- 【Codeforces Round #420 (Div. 2) B】Okabe and Banana Trees