UVa 815 Flood! (习题4-10)

本文介绍了一种用于模拟特定区域内水位变化的算法。通过处理地形数据并计算不同水位下区域的淹没比例,该算法能够精确预测水位上升对区域的影响。采用一维数组存储海拔数据,并进行排序,确保计算效率。通过调整海拔基准,避免负数带来的干扰,从而准确计算水位变化。最终,算法输出水位高度和被淹区域的百分比。

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

只能靠水题维持生活的样子

将数据存在一个一维数组中,然后排序

为了避免负海拔影响,记录一下最低海拔,然后将每个格子的海拔都减去最低海拔,那么最低的就变成0

然后最后答案再加上去

还有自己的一个坑点就是x在循环后会变成x=m*n+1,导致覆盖的地方超过100%

那么特判一下就行了

 

玄学RE,点错了题目

题目:https://vjudge.net/problem/UVA-815

代码:

//Decision's template
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cstdlib>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<set>
using namespace std;

#define DP_maxn 16
#define maxn 1000000+10
#define INF 1000000007
#define mod 1000000007
#define mst(s,k) memset(s,k,sizeof(s))
#define eps 1e-12

typedef long long ll;

struct Edge{
    int from,to,dist;
    Edge(int u,int v,int d):from(u),to(v),dist(d){}
};

/*-------------------------------template End--------------------------------*/

int h[1000],s[1000],v[1000];
int m,n,water,x,cnt = 0;
double now,ans_1,ans_2;

void init()
{
    s[1] = 100;
    v[1] = 0;
    for(int i = 2;i<=n*m;i++) s[i] = s[i-1] + 100,v[i] = v[i-1] + (h[i] - h[i-1])*s[i-1];
}

int main()
{
    while((cin>>m>>n)&&m!=0)
    {
        cnt++;
        mst(h,0);
        mst(s,0);
        mst(v,0);
        for(int i = 1;i<=n*m;i++) cin>>h[i];
        sort(h+1,h+n*m+1);
        for(int i = n*m;i>=1;i--) h[i] += h[1];
        cin>>water;
        init();
        for(x = 1;x<=n*m;x++) if(v[x]>=water) {x--;break;}
        now = (water - v[x])/(double)s[x];
        ans_1 = (double)h[x] + now;
        if(now<eps) ans_2 = (x-1)/(n*m)*100.00;
        else ans_2 = (double)x/(double)(n*m)*100.00;
        printf("Region %d\n",cnt);
        printf("Water level is %.2lf meters.\n",ans_1);
        printf("%.2lf percent of the region is under water.\n\n",ans_2);
    }
    return 0;
}

 

! Doble et al. (2011) - River Bank Slope and Unsaturated Flow Effects on Bank Storage ! HydroGeoSphere Model Setup for Generic Simulation (Vertical Bank Case) ! ---------------------------------------------------------------- ! ----------------------- Domain Geometry ----------------------- generate uniform rectangles 250 500 ! Domain length (250m) and blocks in X (500 cells = 0.5m/cell near river) 1 1 ! Domain width and blocks in Y (2D cross-section) generate layers interactive zone by layer base elevation elevation constant 0.0 ! Aquifer base at z=0m end new layer layer name Aquifer uniform sublayering 20 ! 20 vertical layers (4m thick / 0.2m per layer) elevation constant 4.0 ! Top of aquifer at z=4m end new layer layer name Overland uniform sublayering 1 ! Single layer for overland flow elevation constant 4.0 ! Ground surface at z=4m (will be modified for sloping banks) end end ! ----------------------- Simulation Parameters ----------------------- finite difference mode transient flow dual nodes for surface flow units: metre-day ! Consistent with paper's units fluid viscosity 1.139e-6 ! Kinematic viscosity for water at 20°C (m²/day) ! ----------------------- Material Properties ----------------------- use domain type porous media properties file doble_2011.mprops clear chosen zones choose zone number 1 read properties sandy_loam ! Parameters from Table 2 ! van Genuchten parameters for sandy loam: ! θs=0.41, θr=0.158, K=1.06 m/d, α=7.5 m⁻¹, n=1.89 ! ----------------------- Overland Flow Setup ----------------------- use domain type surface properties file doble_2011.oprops clear chosen faces choose faces top new zone 1 clear chosen zones choose zone number 1 read properties overland_flow ! Overland flow parameters: ! Manning's n = 1e-5 m^{-1/3} (minimal resistance) ! Rill storage height = 0.00001 m ! Obstruction height = 0 m ! ----------------------- Initial Conditions ----------------------- use domain type porous media clear chosen nodes choose nodes all initial pressure head -2.0 ! Initial water table at 2m depth (saturated thickness=2m) ! ----------------------- Boundary Conditions ----------------------- ! River flood pulse boundary (Specified head) clear chosen faces choose faces x-min ! River interface at x=0 specified head 2, ! Time-head pairs 0.0, 2.0, ! Initial stage (t=0): 2.0m 5.0, 3.0 ! Peak stage (t=5d): 3.0m (1m rise) ! Additional time points as needed ! Right boundary (constant head) clear chosen faces choose faces x-max specified head 2.0 ! Constant head = 2.0m ! Bottom boundary (no flow) clear chosen faces choose faces bottom no flow ! ----------------------- Temporal Controls ----------------------- head control 0.01 ! 1cm head change tolerance saturation control 0.05 ! 5% saturation change tolerance maximum timestep 0.1 ! Max 0.1 days (as in paper) initial timestep 0.001 ! Initial small timestep maximum timestep multiplier 2.0 minimum timestep multiplier 0.5 output times 0.1, 0.5, 1.0, 2.0, 5.0, 10.0, 20.0, 50.0 ! Key analysis times ! ----------------------- Solver Settings ----------------------- Newton maximum iterations 15 Jacobian epsilon 1.0e-9 Newton absolute convergence criteria 1e-4 Newton residual convergence criteria 1e-6 ! ----------------------- Bank Slope Configuration ----------------------- ! Note: For sloping banks (e.g., 8.5°), modify geometry in 'generate layers' section ! by adjusting elevation values to create inclined surface ! Example for 8.5° slope (1:6.67 gradient): ! elevation linear ! 0.0, 4.0, ! x=0m, z=4m ! 250.0, 4.0 + 250/6.67 ≈ 41.5m ! x=250m, z=45.5m ! ----------------------- Observation Points ----------------------- observation points ! Define points for flux monitoring (river-aquifer interface) 0.0, 0.5, 2.0 ! Example point at river bank ! ----------------------- End of Input File -----------------------Hydrogeosphere中grok运行器这段指令输入进去报错************************************** *** INPUT ERROR, HALTING EXECUTION *** ************************************** GRID GENERATION: Unrecognized instruction应该怎么调整
最新发布
07-02
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值