max average problem

本文介绍了一个关于园艺布置的问题及解决方法。问题的目标是在给定的区域内种植园艺以获得最大的员工满意度平均值,要求至少覆盖指定数量的连续区域。文章提供了一段C++代码作为解决方案。

摘要生成于 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个整数A0A1,…, 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 ≤ m ≤ n ≤ 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
<think>好的,我现在需要解决用户在OpenFOAM中遇到的checkMesh错误,包括高歪斜面、低质量或负体积分解四面体、凹面单元、小单元行列式以及不连续区域的问题。首先,我需要回顾用户的问题和之前的对话历史,确保回答的连贯性。用户提到的问题主要是网格质量问题,这通常会导致计算不稳定甚至崩溃,比如之前的浮点异常。首先,我应该详细解释每个错误的原因和解决方法。例如,高歪斜面可能由网格生成不当引起,需要调整网格划分参数或局部加密。负体积四面体可能意味着存在严重变形的单元,需要检查运动网格的设置。凹面单元和小行列式通常与网格的几何形状有关,可能需要使用网格修复工具。接下来,我需要考虑如何结构化回答。用户可能希望分步骤解决每个问题,因此应该按错误类型分点,每个点包含原因、解决方法和相关命令。同时,需要引用OpenFOAM的文档或最佳实践,比如使用snappyHexMesh时的参数调整,或者checkMesh输出的具体处理。另外,用户可能需要具体的命令示例,比如如何运行checkMesh,如何调整网格参数。还要注意数学表达式的正确使用,例如行列式的小值应使用$det(J)<0.1$这样的格式。还需要检查是否有遗漏的问题,比如不连续区域可能涉及多区域网格的连接问题,需要确保区域之间的耦合正确。此外,并行计算中的数据同步问题也可能导致错误,但用户当前问题可能主要集中在网格质量上。最后,生成的相关问题需要围绕网格质量、求解器设置、后处理等方面,帮助用户进一步排查其他潜在问题。比如如何优化动态网格,如何选择离散格式提高稳定性等。总结来说,回答需要分门别类,详细解释每个错误的原因和解决方法,提供具体的命令和参数调整建议,并引用相关文档,同时确保数学表达式的正确格式。</think>在OpenFOAM中处理checkMesh报错需要系统分析网格质量问题,以下是典型问题的解决策略: ### 1. 高歪斜面 (High skewness) 当单元面歪斜度超过$skewness > 4$时,会导致数值发散。修正方法: ```bash # 生成网格时调整snappyHexMesh参数 castellatedMeshParams { maxLocalCells 100000; maxGlobalCells 2000000; minRefinementCells 10; // 增加最小加密单元数 nCellsBetweenLevels 3; // 增加层级过渡单元 } # 检查时过滤高歪斜面 checkMesh -allGeometry -allTopology -meshQuality -skewness -setFormat vtk ``` 数学上,面歪斜度定义为: $$skewness = \frac{|\vec{c_f} - \vec{c_{f,proj}}|}{|\vec{c_f} - \vec{c_{f,proj}}| + |\vec{c_{f,proj}} - \vec{c_c}|}$$ 其中$\vec{c_f}$为面中心,$\vec{c_{f,proj}}$为面在单元质心的投影点 ### 2. 负体积分解四面体 (Negative tet decomposition) 通常出现在运动网格或边界层区域,处理方法: ```cpp // 修改dynamicMeshDict参数 motionSolverLibs ("libfvMotionSolvers.so"); solver displacementLaplacian; diffusivity quadratic inverseDistance 1/(max(mag(distance), 0.1)); ``` ### 3. 凹面单元 (Concave cells) 可通过以下步骤修正: ```bash # 使用自动修复工具 surfaceTransformPoints -scale "(1.01 1.01 1.01)" input.stl output.stl foamCleanTutorials snappyHexMesh -overwrite ``` ### 4. 小单元行列式 (Small cell determinant) 当行列式值$det(J) < 0.1$时需处理: $$det(J) = \frac{\partial(x,y,z)}{\partial(\xi,\eta,\zeta)}$$ 调整方法: ```cpp // system/controlDict增加质量检查 meshQuality { maxNonOrtho 75; maxBoundarySkewness 20; maxInternalSkewness 4; maxConcave 80; minVol 1e-13; minTetQuality 1e-15; } ``` ### 5. 不连续区域 (Disconnected regions) 处理流程: 1. 使用`splitMeshRegions`分离区域 2. 检查边界条件匹配性 3. 重新设置区域耦合: ```cpp // system/meshRegionSet regions { fluid1 { cellZone fluid1; faceZone fluid1; cellZoneInside inside; } fluid2 { // 类似设置... } } ``` ### 质量优化策略矩阵 | 问题类型 | 检测阈值 | 修正方法 | 典型参数调整 | |----------------|---------------|-----------------------------------|----------------------------| | 高歪斜面 | skewness>4 | 局部重划网格/加密过渡层 | nCellsBetweenLevels=3 | | 负体积单元 | vol<0 | 调整运动网格扩散率 | diffusivity quadratic | | 凹面单元 | concavity>80 | 表面膨胀+重划分 | surfaceTransformPoints | | 小行列式 | det(J)<0.1 | 增加最小体积限制 | minVol=1e-13 | | 区域不连续 | regions>1 | 设置区域耦合/重定义边界 | splitMeshRegions | **调试建议**: 1. 分阶段验证网格: ```bash # 仅生成背景网格 snappyHexMesh -stage castellated # 检查各阶段质量 checkMesh -stage write -meshQuality ``` 2. 使用ParaView可视化问题区域: ```bash paraFoam -builtin -touch -new -case caseDir ``` [^1]: OpenFOAM User Guide v9 第5章网格生成质量规范 [^2]: snappyHexMesh 官方文档最佳实践指南
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值