max average problem

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

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


ymtan@ecs-lj-openfoam:~/OpenFOAM/ymtan-v2412/run/250425/rigidBodyHull/background$ checkMesh -allGeometry -allTopology /*---------------------------------------------------------------------------*\ | ========= | | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | | \\ / O peration | Version: 2412 | | \\ / A nd | Website: www.openfoam.com | | \\/ M anipulation | | \*---------------------------------------------------------------------------*/ Build : _8dbc61e11c-20241220 OPENFOAM=2412 version=v2412 Arch : "LSB;label=32;scalar=64" Exec : checkMesh -allGeometry -allTopology Date : May 28 2025 Time : 17:22:26 Host : ecs-lj-openfoam PID : 1115230 I/O : uncollated Case : /home/ymtan/OpenFOAM/ymtan-v2412/run/250425/rigidBodyHull/background nProcs : 1 trapFpe: Floating point exception trapping enabled (FOAM_SIGFPE). fileModificationChecking : Monitoring run-time modified files using timeStampMaster (fileModificationSkew 5, maxFileModificationPolls 20) allowSystemOperations : Allowing user-supplied system call operations // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // Create time Create mesh for time = 0 Check mesh... Enabling all (cell, face, edge, point) topology checks. Enabling all geometry checks. Time = 0 Mesh stats points: 1171077 faces: 3255026 internal faces: 3144844 cells: 1045876 faces per cell: 6.119148 boundary patches: 13 point zones: 1 face zones: 0 cell zones: 0 Overall number of cells of each type: hexahedra: 970669 prisms: 12876 wedges: 7 pyramids: 0 tet wedges: 65 tetrahedra: 0 polyhedra: 62259 Breakdown of polyhedra by number of faces: faces number of cells 4 5946 5 4504 6 14031 7 110 8 139 9 26892 10 25 11 68 12 7666 13 3 14 35 15 2620 16 1 17 6 18 212 21 1 Checking topology... ****Problem with boundary patch 0 named oversetPatch of type overset. The patch should start on face no 3144844 and the patch specifies 3243735. Possibly consecutive patches have this same problem. Suppressing future warnings. ***Boundary definition is in error. Cell to face addressing OK. Point usage OK. Upper triangular ordering OK. Face vertices OK. Topological cell zip-up check OK. <<Number of duplicate (not baffle) faces found: 22. This might indicate a problem. <<Number of faces with non-consecutive shared points: 22. This might indicate a problem. <<Writing 66 faces with non-standard edge connectivity to set edgeFaces *Number of regions: 3 The mesh has multiple regions which are not connected by any face. <<Writing region information to "0/cellToRegion" <<Writing region 0 (fully disconnected) with 517350 cells to cellSet region0 <<Writing region 1 (fully disconnected) with 383501 cells to cellSet region1 <<Writing region 2 (fully disconnected) with 145025 cells to cellSet region2 Checking patch topology for multiply connected surfaces... Patch Faces Points Surface topology Bounding box oversetPatch 11291 11345 ok (closed singly connected) (-3.5137747 -0.11385833 0.015782884) (-3.3823898 0.11380627 0.24342155) overset-1 8440 8442 ok (closed singly connected) (-4.9998287 -1.1765634 -0.4005183) (5.0000125 1.1765635 2.6677242) outlet 3060 3172 ok (non-closed singly connected) (-7 -3 -1.8) (-7 3 5.28) inlet 3060 3172 ok (non-closed singly connected) (7 -3 -1.8) (7 3 5.28) ymin 7200 7381 ok (non-closed singly connected) (-7 -3 -1.8) (7 -3 5.28) ymax 7200 7381 ok (non-closed singly connected) (-7 3 -1.8) (7 3 5.28) zmin 6120 6292 ok (non-closed singly connected) (-7 -3 -1.8) (7 3 -1.8) atmosphere 6120 6292 ok (non-closed singly connected) (-7 -3 5.28) (7 3 5.28) HULL 29179 29931 ok (non-closed singly connected) (-3.600006 -0.60945788 -1.9512023e-06) (3.5892613 0.60945883 1.933472) HULL_DISK 87 105 ok (non-closed singly connected) (-3.3732875 -0.019542581 0.10979212) (-3.3724382 0.019934195 0.14859714) BLADES 26507 33135 ok (non-closed singly connected) (-3.4375999 -0.095075928 0.041281019) (-3.4059672 0.098815381 0.23087751) HUB_DISK 88 114 ok (non-closed singly connected) (-3.3985371 -0.020660421 0.10878564) (-3.3972407 0.020647007 0.15033154) HUB 1830 2674 ok (non-closed singly connected) (-3.4603339 -0.020660421 0.10878564) (-3.39743 0.020647007 0.15033154) ".*" 98891 106359 ok (closed singly connected) (-7 -3 -1.8) (7 3 5.28) Checking faceZone topology for multiply connected surfaces... No faceZones found. Checking basic cellZone addressing... No cellZones found. Checking basic pointZone addressing... PointZone PointsBoundingBox frozenPoints 0(1e+150 1e+150 1e+150) (-1e+150 -1e+150 -1e+150) Checking geometry... Overall domain bounding box (-7 -3 -1.8) (7 3 5.28) Mesh has 3 geometric (non-empty/wedge) directions (1 1 1) Mesh has 3 solution (non-empty) directions (1 1 1) Boundary openness (-2.1191257e-16 -1.1701675e-16 1.0552411e-15) OK. Max cell openness = 3.4499493e-16 OK. Max aspect ratio = 10.58398 OK. Minimum face area = 1.8622712e-09. Maximum face area = 0.015462575. Face area magnitudes OK. Min volume = 6.7187714e-11. Max volume = 0.0020033185. Total volume = 662.9577. Cell volumes OK. Mesh non-orthogonality Max: 69.978861 average: 5.2077846 Non-orthogonality check OK. Face pyramids OK. ***Max skewness = 18.358061, 36 highly skew faces detected which may impair the quality of the results <<Writing 36 skew faces to set skewFaces Coupled point location match (average 0) OK. ***Error in face tets: 2 faces with low quality or negative volume decomposition tets. <<Writing 2 faces with low quality or negative volume decomposition tets to set lowQualityTetFaces *Edges too small, min/max edge length = 3.0158475e-06 0.12979014, number too small: 18 <<Writing 18 points on short edges to set shortEdges *There are 1128 faces with concave angles between consecutive edges. Max concave angle = 79.784669 degrees. <<Writing 1128 faces with concave angles to set concaveFaces Face flatness (1 = flat, 0 = butterfly) : min = 0.35091858 average = 0.99944701 *There are 66 faces with ratio between projected and actual area < 0.8 Minimum ratio (minimum flatness, maximum warpage) = 0.35091858 <<Writing 66 warped faces to set warpedFaces Cell determinant (wellposedness) : minimum: 0.00098934483 average: 1.3639416 ***Cells with small determinant (< 0.001) found, number of cells: 1 <<Writing 1 under-determined cells to set underdeterminedCells ***Concave cells (using face planes) found, number of cells: 854 <<Writing 854 concave cells to set concaveCells Face interpolation weight : minimum: 0.065401151 average: 0.48202057 Face interpolation weight check OK. Face volume ratio : minimum: 0.011817813 average: 0.91971027 Face volume ratio check OK. Failed 4 mesh checks. Time = 0.1 Checking geometry... Overall domain bounding box (-7.0010041 -3.0000007 -1.8081815) (6.9989959 2.9999993 5.2718185) Mesh has 3 geometric (non-empty/wedge) directions (1 1 1) Mesh has 3 solution (non-empty) directions (1 1 1) Boundary openness (-1.4247891e-16 -4.8513891e-17 1.0347421e-15) OK. Max cell openness = 3.3602158e-16 OK. Max aspect ratio = 10.65007 OK. Minimum face area = 1.8622712e-09. Maximum face area = 0.015462575. Face area magnitudes OK. Min volume = 6.7187714e-11. Max volume = 0.0020033185. Total volume = 662.9577. Cell volumes OK. Mesh non-orthogonality Max: 69.978861 average: 5.2077846 Non-orthogonality check OK. Face pyramids OK. ***Max skewness = 18.358061, 36 highly skew faces detected which may impair the quality of the results <<Writing 36 skew faces to set skewFaces Coupled point location match (average 0) OK. ***Error in face tets: 2 faces with low quality or negative volume decomposition tets. <<Writing 2 faces with low quality or negative volume decomposition tets to set lowQualityTetFaces *Edges too small, min/max edge length = 3.0158475e-06 0.12979014, number too small: 18 <<Writing 18 points on short edges to set shortEdges *There are 1128 faces with concave angles between consecutive edges. Max concave angle = 79.784669 degrees. <<Writing 1128 faces with concave angles to set concaveFaces Face flatness (1 = flat, 0 = butterfly) : min = 0.35091858 average = 0.99944701 *There are 66 faces with ratio between projected and actual area < 0.8 Minimum ratio (minimum flatness, maximum warpage) = 0.35091858 <<Writing 66 warped faces to set warpedFaces Cell determinant (wellposedness) : minimum: 0.00098934483 average: 1.3639416 ***Cells with small determinant (< 0.001) found, number of cells: 1 <<Writing 1 under-determined cells to set underdeterminedCells ***Concave cells (using face planes) found, number of cells: 854 <<Writing 854 concave cells to set concaveCells Face interpolation weight : minimum: 0.065401151 average: 0.48202057 Face interpolation weight check OK. Face volume ratio : minimum: 0.011817813 average: 0.91971027 Face volume ratio check OK. Failed 4 mesh checks. Time = 0.2 Checking geometry... Overall domain bounding box (-7.004549 -3.0000049 -1.8351793) (6.995451 2.9999951 5.2448207) Mesh has 3 geometric (non-empty/wedge) directions (1 1 1) Mesh has 3 solution (non-empty) directions (1 1 1) Boundary openness (-1.3099804e-16 -9.8277796e-17 1.0607913e-15) OK. Max cell openness = 3.2277216e-16 OK. Max aspect ratio = 10.943125 OK. Minimum face area = 1.8622712e-09. Maximum face area = 0.015462575. Face area magnitudes OK. Min volume = 6.7187714e-11. Max volume = 0.0020033185. Total volume = 662.9577. Cell volumes OK. Mesh non-orthogonality Max: 69.978861 average: 5.2077846 Non-orthogonality check OK. Face pyramids OK. ***Max skewness = 18.358061, 36 highly skew faces detected which may impair the quality of the results <<Writing 36 skew faces to set skewFaces Coupled point location match (average 0) OK. ***Error in face tets: 2 faces with low quality or negative volume decomposition tets. <<Writing 2 faces with low quality or negative volume decomposition tets to set lowQualityTetFaces *Edges too small, min/max edge length = 3.0158475e-06 0.12979014, number too small: 18 <<Writing 18 points on short edges to set shortEdges *There are 1128 faces with concave angles between consecutive edges. Max concave angle = 79.784669 degrees. <<Writing 1128 faces with concave angles to set concaveFaces Face flatness (1 = flat, 0 = butterfly) : min = 0.35091858 average = 0.99944701 *There are 66 faces with ratio between projected and actual area < 0.8 Minimum ratio (minimum flatness, maximum warpage) = 0.35091858 <<Writing 66 warped faces to set warpedFaces Cell determinant (wellposedness) : minimum: 0.00098934483 average: 1.3639416 ***Cells with small determinant (< 0.001) found, number of cells: 1 <<Writing 1 under-determined cells to set underdeterminedCells ***Concave cells (using face planes) found, number of cells: 854 <<Writing 854 concave cells to set concaveCells Face interpolation weight : minimum: 0.065401151 average: 0.48202057 Face interpolation weight check OK. Face volume ratio : minimum: 0.011817813 average: 0.91971027 Face volume ratio check OK. Failed 4 mesh checks. Time = 0.3 Checking geometry... Overall domain bounding box (-7.0097797 -3.0000129 -1.8732831) (6.9902203 2.9999871 5.2067169) Mesh has 3 geometric (non-empty/wedge) directions (1 1 1) Mesh has 3 solution (non-empty) directions (1 1 1) Boundary openness (-1.7685801e-16 -1.5646894e-16 1.0557562e-15) OK. Max cell openness = 3.6004607e-16 OK. Max aspect ratio = 8.296384 OK. Minimum face area = 1.8622712e-09. Maximum face area = 0.015462575. Face area magnitudes OK. Min volume = 6.7187714e-11. Max volume = 0.0020033185. Total volume = 662.9577. Cell volumes OK. Mesh non-orthogonality Max: 69.978861 average: 5.2077846 Non-orthogonality check OK. Face pyramids OK. ***Max skewness = 18.358061, 36 highly skew faces detected which may impair the quality of the results <<Writing 36 skew faces to set skewFaces Coupled point location match (average 0) OK. ***Error in face tets: 2 faces with low quality or negative volume decomposition tets. <<Writing 2 faces with low quality or negative volume decomposition tets to set lowQualityTetFaces *Edges too small, min/max edge length = 3.0158475e-06 0.12979014, number too small: 18 <<Writing 18 points on short edges to set shortEdges *There are 1128 faces with concave angles between consecutive edges. Max concave angle = 79.784669 degrees. <<Writing 1128 faces with concave angles to set concaveFaces Face flatness (1 = flat, 0 = butterfly) : min = 0.35091858 average = 0.99944701 *There are 66 faces with ratio between projected and actual area < 0.8 Minimum ratio (minimum flatness, maximum warpage) = 0.35091858 <<Writing 66 warped faces to set warpedFaces Cell determinant (wellposedness) : minimum: 0.00098934483 average: 1.3639416 ***Cells with small determinant (< 0.001) found, number of cells: 1 <<Writing 1 under-determined cells to set underdeterminedCells ***Concave cells (using face planes) found, number of cells: 854 <<Writing 854 concave cells to set concaveCells Face interpolation weight : minimum: 0.065401151 average: 0.48202057 Face interpolation weight check OK. Face volume ratio : minimum: 0.011817813 average: 0.91971027 Face volume ratio check OK. Failed 4 mesh checks. End
最新发布
05-29
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值