Codeforces Round #420 (Div. 2) - B
题目链接:http://codeforces.com/contest/821/problem/B
题意:二维每个整点坐标(x,y)拥有的香蕉数量为x+y,现在给你一个直线方程的m和b参数,让你找一个位于这个直线下方的点,该点与原点构成的长方形区域里面的香蕉数量最多。
思路:由方程可以得知y的取值在[0,b]之间,所以枚举y,然后通过方程解出一个最接近解的整数x,然后就是普通的计算了。 对于计算通过预处理一个等差数列的前缀和就可以O(1)计算结果了。
#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<time.h>
#include<cmath>
using namespace std;
typedef long long int LL;
const LL INF = ;
const int MAXN = 1e7 + ;
LL sum[MAXN];
void Init(){
sum[] = ;
for (int i = ; i < MAXN; i++){
sum[i] = sum[i - ] + i;
}
}
int main(){
//#ifdef kirito
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
//#endif
// int start = clock();
int m, b; Init();
while (~scanf("%d%d",&m,&b)){
LL ans = -;
for (int y = ; y <= b; y++){
LL x = (b - y)* m;
if (x >= ){
ans = max(ans, 1LL * (sum[y] * (x + ) + sum[x] * (y + )));
}
}
printf("%I64d\n", ans);
}
//#ifdef LOCAL_TIME
// cout << "[Finished in " << clock() - start << " ms]" << endl;
//#endif
return ;
}
Codeforces Round #420 (Div. 2) - B的更多相关文章
- 【Codeforces Round #420 (Div. 2) C】Okabe and Boxes
[题目链接]:http://codeforces.com/contest/821/problem/C [题意] 给你2*n个操作; 包括把1..n中的某一个数压入栈顶,以及把栈顶元素弹出; 保证压入和 ...
- 【Codeforces Round #420 (Div. 2) B】Okabe and Banana Trees
[题目链接]:http://codeforces.com/contest/821/problem/B [题意] 当(x,y)这个坐标中,x和y都为整数的时候; 这个坐标上会有x+y根香蕉; 然后给你一 ...
- 【Codeforces Round #420 (Div. 2) A】Okabe and Future Gadget Laboratory
[题目链接]:http://codeforces.com/contest/821/problem/A [题意] 给你一个n*n的数组; 然后问你,是不是每个位置(x,y); 都能找到一个同一行的元素q ...
- Codeforces Round #420 (Div. 2) - C
题目链接:http://codeforces.com/contest/821/problem/C 题意:起初有一个栈,给定2*n个命令,其中n个命令是往栈加入元素,另外n个命令是从栈中取出元素.你可以 ...
- Codeforces Round #420 (Div. 2) - E
题目链接:http://codeforces.com/contest/821/problem/E 题意:起初在(0,0),现在要求走到(k,0),问你存在多少种走法. 其中有n条线段,每条线段为(a, ...
- Codeforces Round #420 (Div. 2) - A
题目链接:http://codeforces.com/contest/821/problem/A 题意:给定一个n*n的矩阵. 问你这个矩阵是否满足矩阵里的元素除了1以外,其他元素都可以在该元素的行和 ...
- Codeforces Round #420 (Div. 2)
/*************************************************************************************************** ...
- Codeforces Round #420 (Div. 2) A,B,C
A. Okabe and Future Gadget Laboratory time limit per test 2 seconds memory limit per test 256 megaby ...
- Codeforces Round #420 (Div. 2) E. Okabe and El Psy Kongroo 矩阵快速幂优化dp
E. Okabe and El Psy Kongroo time limit per test 2 seconds memory limit per test 256 megabytes input ...
随机推荐
- JavaScript学习第一篇
在学习之前让我们了解了解JavaScript的由来 Javascript是一种web技术,最初起名叫LiveScript,它是Netscape开发出来一种脚本语言,其目的是为了扩展基本的Html的功能 ...
- CodeForces - Path Queries (并查集+离线查询)
题目:https://vjudge.net/contest/323699#problem/A 题意:给你一棵树,然后有m个查询,每次查询问一条路径最大边小于给定查询的数量 思路:首先我们看到,我们其实 ...
- [CSP-S模拟测试]:甜圈(线段树)
题目描述 $D$先生,是一个了不起的甜甜圈制造商.今天,他的厨房准备在日出之前制作甜甜圈.$D$先生瞬间完成了$N$个油炸圈饼.但是,这些油炸圈饼得先经过各种装饰任务才可以成为甜甜圈销售:填充奶油,浸 ...
- Java并发指南14:JUC中常用的Unsafe和Locksupport
本文转自网络,侵删 本系列文章将整理到我在GitHub上的<Java面试指南>仓库,更多精彩内容请到我的仓库里查看 https://github.com/h2pl/Java-Tutoria ...
- php面向对象编程(oop)基础知识示例解释
面向对象并不是一种技术,而是一种思想,是一种解决问题的最基本的思维方式!如何理解使用?OOP:面向对象编程 (直接代码说明) 1.面向对象的基本概念 示例demo: <?php header(& ...
- (转)运行pip报错:Fatal error in launcher: Unable to create process using '"'
转:https://blog.csdn.net/cjeric/article/details/73518782 在新环境上安装python的时候又再次遇到了这个情况,这次留意了一下,发现原来的文章有错 ...
- Delphi 快速读取TXT 指定行的数据
http://blog.csdn.net/MichaelJScofield/article/details/41869785 Delphi 快速读取TXT 指定行的数据 分类:Delphi个人挫品 ( ...
- Go-Mutex互斥量
先来看一段go1.12.5中Mutex的源码: // Copyright 2009 The Go Authors. All rights reserved. // Use of this source ...
- 操作系统 - Linux命令整理 - Ubuntu
镜像 http://mirrors.163.com/ubuntu-releases/ 系统相关 Ubuntu14.04相关 安装 - VMware Install Ubuntu Continue In ...
- C# 文件、byte相互转换
文件转byte数组: /// <summary> /// 将文件转换为byte数组 /// </summary> /// <param name="path&q ...