max average problem

本文介绍了一个用于解决园艺布置问题的高效算法。该算法通过计算不同区域种植园艺带来的满意度来寻找最优布置方案,旨在满足特定条件下获得最大的平均满意度。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

see

http://blog.163.com/lfw2565295@126/blog/static/122005162011512103838669/

http://hi.baidu.com/fhnstephen/blog/item/5eae830a3c929f8cd0581b30.html

http://acm.hdu.edu.cn/showproblem.php?pid=2993


参考代码: http://www.cppblog.com/huicpc0860/archive/2010/08/09/122835.html

#include <cstdio> using namespace std; #define N 100010 #define max(x,y) ((x)>(y)?(x):(y)) typedef long long LL; int s[N]; struct point { int x, y; point(){} point(int x,int y):x(x),y(y){} }p[N]; point operator - (const point &a, const point &b) { return point(a.x-b.x, a.y-b.y); } LL operator ^ (const point &a, const point &b) { return (LL)a.x*b.y - (LL)a.y*b.x; } inline int get(){ int s=0; char c; while(c=getchar(),c!=' '&&c!='\n')s=s*10+c-'0'; return s; } int main() { int n,k; s[0]=0; while (~scanf("%d ",&n)){ k=get();n++; for(int i=1;i<n;++i){ s[i]=get(); s[i]+=s[i-1]; } double ans=0; for(int i=k,m=-1,f=0;i<n;++i){ point now(i-k,s[i-k]); while(f<m&&(p[m]-p[m-1]^now-p[m-1])<0)--m; p[++m]=now; while(f<m&&(LL)(s[i]-p[f].y)*(i-p[f+1].x)<(LL)(s[i]-p[f+1].y)*(i-p[f].x))f++; ans=max(ans,double(s[i]-p[f].y)/(i-p[f].x)); } printf("%.2lf\n",ans); } }

第三题:园艺布置

近期,百度采纳了员工们的提议,计划在总部大楼内部种植园艺,以提供更加温馨的工作环境。公司将园艺设计的任务交给了度度熊同学。

公司总部大楼内部的构造可以分为n个区域,编号为0, 1, …, n–1,其中区域i与i + 1是相邻的(0 ≤ i < n – 1)。根据员工的投票和反馈,度度熊拿到了一份数据,表明在区域i种植园艺可以获得员工的满意度为Ai。度度熊希望园艺的布置方案满足条件:

1.至少覆盖m个区域;

2.布置园艺的区域是连续的。

请帮他找到一种满足条件的方案,使布置园艺区域的员工的满意度的平均值最大。

输入描述

输入的第一行包含两个整数nm,分别表示总区域数和至少覆盖的区域数。

第二行包含n个整数A0,A1,…,An– 1,依次表示在每个区域种植园艺可以获得员工的满意度。

输出描述

输出一行,表示员工的平均满意度的最大值。如果这个数是一个整数,则直接按整数格式输出;否则,请用最简分数表示,分子分母以“/”分割,格式见样例。

样例输入1

3 1

2 3 1

样例输入2

5 3

1 8 2 4 8

样例输出1

3

样例输出2

11/2

15

提示

样例2的正确答案为11/2,尽管22/4数值也相同,但由于没有化简,所以是错误的。

对于100%的数据,1 ≤mn≤ 106,1 ≤Ai≤ 106


PS D:\zhWork\202501gsykj\control_map> npm run serve > app@0.1.0 serve D:\zhWork\202501gsykj\control_map > vue-cli-service serve Browserslist: caniuse-lite is outdated. Please run: npx update-browserslist-db@latest Why you should do it regularly: https://github.com/browserslist/update-db#readme INFO Starting development server... [24%] building (3/381 modules) [24%] building (19/426 modules) [BABEL] Note: The code generator has deoptimised the styling of D:\zhWork\202501gsykj\control_map\node_modules\element-ui\lib\element-ui.common.js as it exceeds the max of[38%] building (486/800 modules) [BABEL] Note: The code generator has deoptimised the styling of D:\zhWork\202501gsykj\control_map\node_modules\lodash\lodash.js as it exceeds the max of 500KB. <--- Last few GCs ---> [4820:000001E7C4609C20] 54577 ms: Mark-sweep (reduce) 4088.9 (4101.7) -> 4088.5 (4102.7) MB, 495.5 / 0.0 ms (+ 0.1 ms in 323 steps since start of marking, biggest step 0.0 ms, walltime since start of marking 655 ms) (average mu = 0.590, current mu = 0[4820:000001E7C4609C20] 55203 ms: Mark-sweep (reduce) 4089.5 (4104.7) -> 4089.0 (4105.2) MB, 620.5 / 0.0 ms (average mu = 0.379, current mu = 0.008) allocation failure scavenge might not succeed <--- JS stacktrace ---> FATAL ERROR: MarkCompactCollector: young object promotion failed Allocation failed - JavaScript heap out of memory 1: 00007FF62825412F napi_wrap+133311 2: 00007FF6281EDD06 SSL_get_quiet_shutdown+63062 3: 00007FF6281EEB9D node::OnFatalError+301 4: 00007FF628AD19CE v8::Isolate::ReportExternalAllocationLimitReached+94 5: 00007FF628AB67BD v8::SharedArrayBuffer::Externalize+781 6: 00007FF62895FFCC v8::internal::Heap::EphemeronKeyWriteBarrierFromCode+1516 7: 00007FF62894AA4B v8::internal::NativeContextInferrer::Infer+59739 8: 00007FF62892FD1F v8::internal::MarkingWorklists::SwitchToContextSlow+56975 9: 00007FF628943A0B v8::internal::NativeContextInferrer::Infer+31003 10: 00007FF62893AAED v8::internal::MarkCompactCollector::EnsureSweepingCompleted+6285 11: 00007FF628942C5E v8::internal::NativeContextInferrer::Infer+27502 12: 00007FF628946CAB v8::internal::NativeContextInferrer::Infer+43963 13: 00007FF6289506A2 v8::internal::ItemParallelJob::Task::RunInternal+18 14: 00007FF628950631 v8::internal::ItemParallelJob::Run+641 15: 00007FF628923C93 v8::internal::MarkingWorklists::SwitchToContextSlow+7683 16: 00007FF62893AF9C v8::internal::MarkCompactCollector::EnsureSweepingCompleted+7484 17: 00007FF6289397D4 v8::internal::MarkCompactCollector::EnsureSweepingCompleted+1396 18: 00007FF628937348 v8::internal::MarkingWorklists::SwitchToContextSlow+87224 19: 00007FF628965DB1 v8::internal::Heap::LeftTrimFixedArray+929 20: 00007FF628967EA5 v8::internal::Heap::PageFlagsAreConsistent+789 21: 00007FF62895D0C1 v8::internal::Heap::CollectGarbage+2049 22: 00007FF62895B2C5 v8::internal::Heap::AllocateExternalBackingStore+1349 23: 00007FF628975155 v8::internal::GCIdleTimeHandler::ShouldDoContextDisposalMarkCompact+1029 24: 00007FF6289755A5 v8::internal::Factory::AllocateRaw+37 25: 00007FF628986DA6 v8::internal::FactoryBase<v8::internal::Factory>::AllocateRawArray+38 26: 00007FF628986EBF v8::internal::FactoryBase<v8::internal::Factory>::AllocateRawFixedArray+31 27: 00007FF6289769E1 v8::internal::Factory::CopyFixedArrayAndGrow+65 28: 00007FF62879F7E4 v8::internal::WeakArrayList::AddToEnd+3300 29: 00007FF6289ACC2A v8::internal::Isolate::CaptureSimpleStackTrace+1146 30: 00007FF6289AC971 v8::internal::Isolate::CaptureSimpleStackTrace+449 31: 00007FF6289AC0BD v8::internal::Isolate::CaptureAndSetSimpleStackTrace+45 32: 00007FF6289A28A0 v8::internal::MessageLocation::MessageLocation+3664 33: 00007FF6289A63BC v8::internal::MessageFormatter::Format+13100 34: 00007FF62897ADB6 v8::internal::Factory::NewError+134 35: 00007FF628984AF2 v8::internal::Factory::NewTypeError+162 36: 00007FF6289A6561 v8::internal::MessageHandler::MakeMessageObject+337 37: 00007FF6286ABF7C v8::internal::interpreter::JumpTableTargetOffsets::iterator::operator=+9596 38: 00007FF628B5CDFD v8::internal::SetupIsolateDelegate::SetupHeap+474253 39: 00007FF628AED1C9 v8::internal::SetupIsolateDelegate::SetupHeap+16473 40: 00007FF628AF2FC2 v8::internal::SetupIsolateDelegate::SetupHeap+40530 41: 0000010772004690 npm ERR! code ELIFECYCLE npm ERR! errno 134 npm ERR! app@0.1.0 serve: `vue-cli-service serve` npm ERR! Exit status 134 npm ERR! npm ERR! Failed at the app@0.1.0 serve script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: npm ERR! D:\softwareInstall\nvmInstall\nodejs\node_cache\_logs\2025-07-19T15_03_28_775Z-debug.log
最新发布
07-20
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值