Codeforces Round #420 B

Okabe and Banana Trees

题意:给一个y=b-x/m 在这条直线与x y正半轴围成的三角形里,找一个矩形,使得矩形内所有的点(包括矩形边缘)的权值和最大,每个点的权值为横坐标与纵坐标之和

思路:暴力枚举x= 0--m*b, 计算答案,取最大值,注意爆int,计算y值的时候去尾取整(强制类型转换即可)

AC代码:

#include "iostream"
#include "string.h"
#include "stack"
#include "queue"
#include "string"
#include "vector"
#include "set"
#include "map"
#include "algorithm"
#include "stdio.h"
#include "math.h"
#define ll long long
#define bug(x) cout<<x<<" "<<"UUUUU"<<endl;
#define mem(a) memset(a,0,sizeof(a))
using namespace std;
const int N=1e5+100;
ll mx,y,m,b,ans;
ll fun(int x){
    double y=b*1.0-x*1.0/m;
    return y;
}
int main(){
    cin>>m>>b;
    mx=m*b;
    for(ll i=0; i<=mx; ++i){
        y=fun(i);
        ll t=((1+i)*i/2*(y+1))+(1+y)*y/2*(i+1);
        ans=max(ans,t);
    }
    cout<<ans;
    return 0;
}
/*
1 5
2 3
*/
原文地址:https://www.cnblogs.com/max88888888/p/7101785.html