zoukankan      html  css  js  c++  java
  • 【Codeforces Round #420 (Div. 2) B】Okabe and Banana Trees

    【题目链接】:http://codeforces.com/contest/821/problem/B

    【题意】

    当(x,y)这个坐标中,x和y都为整数的时候;
    这个坐标上会有x+y根香蕉;
    然后给你一条直线的方程y=1mx+b
    给你m和b;
    让你在这条直线以下选一个长方形;
    (长方形的边都要和坐标轴平行,见样例图);
    然后你可以把整个长方形内的所有点上的香蕉都拿走;
    问你最多能拿走多少个香蕉;

    【题解】

    枚举长方形的右竖边的x轴坐标;
    可以得到上边的y坐标(当然取最大了);
    左竖边当然是x=0了;
    然后就是等差数列求和了;
    往右移动一格,banana就增加上边的y+1个,等差数列!
    然后x的上限是b*m;
    就是令y=0

    【Number Of WA

    0

    【反思】

    B题。不会多难的。
    往暴力想就好

    【完整代码】

    #include <bits/stdc++.h>
    using namespace std;
    #define lson l,m,rt<<1
    #define rson m+1,r,rt<<1|1
    #define LL long long
    #define rep1(i,a,b) for (int i = a;i <= b;i++)
    #define rep2(i,a,b) for (int i = a;i >= b;i--)
    #define mp make_pair
    #define pb push_back
    #define fi first
    #define se second
    #define ms(x,y) memset(x,y,sizeof x)
    #define Open() freopen("F:\rush.txt","r",stdin)
    #define Close() ios::sync_with_stdio(0)
    
    typedef pair<int,int> pii;
    typedef pair<LL,LL> pll;
    
    const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
    const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
    const double pi = acos(-1.0);
    const int N = 110;
    
    LL m,b,ans=0;
    
    int main(){
        //Open();
        Close();
        cin >> m >> b;
        for (LL x0 = 0;x0 <= m*b;x0++){
            LL y0 = (-1.0)*x0/(m*1.0) + b;
            //cout <<x0<<' '<<y0<<endl;
            LL b1 = (1+y0)*y0/2;
            LL d = y0+1,n = x0+1;
            LL temp = n*b1+d*n*(n-1)/2;
            //cout << temp << endl;
            ans = max(temp,ans);
        }
        cout << ans << endl;
        return 0;
    }
  • 相关阅读:
    551. 学生出勤纪录 I
    387. 字符串中的第一个唯一字符
    剑指OFFER 字符串的排列
    剑指OFFER 斐波那契数列
    剑指OFFER 重建二叉树
    剑指OFFER 二维数组中的查找
    剑指OFFER 和为S的两个数字
    剑指OFFER 左旋转字符串
    剑指OFFER 合并两个排序的链表
    剑指OFFER 从尾到头打印链表
  • 原文地址:https://www.cnblogs.com/AWCXV/p/7626235.html
Copyright © 2011-2022 走看看