Codeforces Round #420 (Div. 2) B. Okabe and Banana Trees
来源:互联网 发布:朝鲜生活 知乎 编辑:程序博客网 时间:2024/05/16 04:18
题目大意
给出一次函数y=-x/m+b,它与x轴y轴围成平面中,每个点(x,y)贡献(x+y),在这个平面中画一个矩形,所围成点的最大价值和是多少。
题解
分别计算纵坐标减1后在范围外的点和新增加的点。(要用long long,比赛时被max函数坑wa了2发)。
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int read(){ char ch=getchar();int f=0; while(ch<'0'||ch>'9') ch=getchar(); while(ch>='0'&&ch<='9') {f=(f<<1)+(f<<3)+ch-'0'; ch=getchar();} return f;}long long maxx(long long x,long long y){ return x>y?x:y;}long long a[10005];long long maxn=0,last[10005];int main(){ int m,b; cin>>m>>b; for(int i=b;i>=0;i--) { a[i]=(b-i)*m; //a[i]++; //cout<<a[i]<<" "; }// cout<<endl; maxn=((1+b)*b)/2; last[b]=maxn; for(int i=b-1;i>=0;i--) { last[i]=last[i+1]-((a[i+1]+1)*(i+1))-((1+a[i+1])*a[i+1])/2+(((a[i+1]+1+a[i])*(a[i]-a[i+1]))/2)*(i+1)+(((1+i)*i)/2)*(a[i]-a[i+1]); //cout<<last[i+1]<<" "<<((a[i+1]+1)*(i+1))<<" "<<((1+a[i+1])*a[i+1])/2<<" "<<(((a[i+1]+1+a[i])*(a[i]-a[i+1]))/2)*i<<" "<<(((1+i)*i)/2)*(a[i]-a[i+1])<<endl; maxn=maxx(last[i],maxn); } cout<<maxn;}
ps:还是大爷的代码好看。。。
#include<bits/stdc++.h>using namespace std;typedef long long LL;inline int rd(void) { int x = 0, c = 0, f = 1; for(;c<'0'||c>'9';c=getchar())f=c!='-'; for(;c>='0'&&c<='9';c=getchar())x=x*10+c-'0'; return f ? x : -x;}int m,b;int now,last;LL ans;LL cal(int n,int m){ return 1LL*(n+1)*(m+1)*(n+m)/2;}int main(){ m=rd(),b=rd(); for(int i=0;i<=b;i++) { ans=max(ans,cal(i,(b-i)*m)); } cout<<ans<<endl;}
阅读全文
1 0
- Codeforces Round #420 (Div. 2) B. Okabe and Banana Trees
- Codeforces Round #420 B. Okabe and Banana Trees
- codeforces -420-B. Okabe and Banana Trees
- #420 B. Okabe and Banana Trees(Div.2)
- Codeforces 821 B. Okabe and Banana Trees
- codeforces 821 B Okabe and Banana Trees
- Codeforces 821B-Okabe and Banana Trees
- Codeforces#420 Okabe and Banana Trees
- CF #420 B. Okabe and Banana Trees
- #420 Div.2 B. Okabe and Banana Trees——数学&暴力
- CF#420 Div.2 B. Okabe and Banana Trees(数学)
- Okabe and Banana Trees CodeForces
- Codeforces 821B Okabe and Banana Trees 题解
- CF#420 B. Okabe and Banana Trees 思维|暴力|几何
- Codeforces Round #420 (Div. 2) 821D Okabe and City
- Codeforces Round #420 (Div. 2) C. Okabe and Boxes
- CF-Codeforces Round #420 (Div. 2)-D-Okabe and City
- CF-Codeforces Round #420 (Div. 2)-C-Okabe and Boxes
- Android中抓取妹子图网页数据并展示给界面
- RabbitMQ 集群之镜像同步
- Eclipse中服务器发布时发现项目名后出现括号,括号中名字与项目名不一致的问题
- USB Type-C到底是什么
- android 利用广播监听usb连接状态
- Codeforces Round #420 (Div. 2) B. Okabe and Banana Trees
- 详解SpringMVC中Controller的方法中参数的工作原理[附带源码分析]
- 最新csdn有奖任务答案
- 给定一个整数数组,在该数组中,寻找三个数,分别代表三角形三条边的长度,问,可以寻找到多少组这样的三个数来组成三角形?
- 百度推广怎么快速提升关键词排名?
- LeetCode542. 01 Matrix题解
- 学习Linux命令(48)
- php实现post提交数据
- 人月落地实战体验