poj 2018
来源:互联网 发布:c语言高级编程 编辑:程序博客网 时间:2024/06/02 13:34
题意:在所有长度大于等于m的区间中找一个平均值最大的,输出平均数。
solution:
对于
1.
2.
#include<cstdio>#include<cstdlib>#include<iostream>#include<algorithm>const int MAXN = 1e5+5;int n, m;int c[MAXN] = {0}, sum[MAXN] = {0};int f[MAXN] = {0}, num[MAXN] = {0};int ans = 0;int main(){#ifndef ONLINE_JUDGE freopen("poj2018.in","r",stdin); freopen("poj2018.out","w",stdout);#endif std::cin >> n >> m; for(int i = 1; i <= n; i++) {scanf("%d",c+i); sum[i] = sum[i-1]+c[i];} f[m] = sum[m], num[m] = m; for(int i = m+1; i <= n; i++) { f[i] = sum[i] - sum[i-m] ,num[i] = m; if((f[i-1]+c[i])*num[i] > f[i]*(num[i-1]+1) ) f[i] = f[i-1]+c[i], num[i] = num[i-1]+1; } for(int i = m; i <= n; i ++) ans = std::max(ans, f[i]*1000/num[i]); std::cout << ans << std::endl; #ifndef ONLINE_JUDGE fclose(stdin); fclose(stdout);#endif return 0;}
1 0
- poj 2018
- poj 2018
- poj 2018
- poj 2018 斜率优化
- POJ 2018 二分
- POJ
- poj
- POJ
- POJ
- poj
- poj
- POJ
- POJ
- poj
- POJ
- POJ
- POJ
- POJ
- 实现正在加载中界面的Android库:DynamicBox
- 第三章 第11题
- 用Swift开发Mac App(3)
- PCB设计后期检查的几大要素
- 微软致力开发新一代Azure应用服务
- poj 2018
- 一个简单的使用C++在运行时获取调用堆栈的类
- week9---4月28日
- Android paint方法介绍
- ZOJ Problem Set - 1049||I Think I Need a Houseboat
- 时代在前进——我的方向
- 第三章 第12题
- 谈一谈做iOS播放器库开发所涉及的知识点
- Makefile 学习