只能靠水题维持生活的样子
将数据存在一个一维数组中,然后排序
为了避免负海拔影响,记录一下最低海拔,然后将每个格子的海拔都减去最低海拔,那么最低的就变成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;
}