华师一附中OI组
标题:
UVA815 Flooded!
[打印本页]
作者:
admin
时间:
2018-5-1 15:05
标题:
UVA815 Flooded!
https://www.luogu.org/problemnew/show/UVA815
有一个 n × m (1≤ m , n <30)的网格,每个格子是边长10米的正方形,网格四周是无限大的墙壁。输入每个格子的海拔高度,以及网格内雨水的总体积,输出水位的海拔高度以及有多少百分比的区间有水(即高度严格小于水平面)。
作者:
吴语林
时间:
2018-9-1 15:21
#include <algorithm>
#include <iostream>
#include <cmath>
#include <cstring>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
using namespace std;
int n,m,cnt=0;
long long all,a[1000];
double ans;
int main()
{
scanf("%d%d",&n,&m);
while(n!=0&&m!=0)
{
memset(a,0,sizeof(a));
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
scanf("%lld",&a[i*m+j-m]);
sort(a+1,a+1+n*m);
a[n*m+1]=0x3f3f3f;
scanf("%lld",&all);
for(int i=1;i<=n*m;i++)
{
if(all>(a[i+1]-a[i])*100*i)
all-=((a[i+1]-a[i])*100*i);
else
{
ans=a[i];
ans+=((double)all/(double)(100*i));
printf("Region %d\n",++cnt);
printf("Water level is %.2lf meters.\n",ans);
printf("%.2lf percent of the region is under water.\n\n",(double)i*100.0/(m*n));
break;
}
}
scanf("%d%d",&n,&m);
}
return 0;
}
复制代码
作者:
黄煦喆
时间:
2018-9-2 12:49
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
int m,n,V,t=1;
double a[1000],v,l,r,mid,cnt,ans;
double const eps=1e-3;
int main()
{
cin>>m>>n;
while(m&&n)
{
l=r=999999.0;
for(int i=1;i<=m*n;i++)cin>>a[i],l=min(l,a[i]);
cin>>V;
v=V/100.0;
sort(a+1,a+m*n+1);
while(r-l>eps)
{
mid=(l+r)/2.0;
cnt=0.0;
for(int i=1;i<=m*n&&mid-a[i]>eps;i++)cnt+=mid-a[i];
if(cnt-v>=eps)r=mid-eps,ans=mid;
else l=mid+eps;
}
int k=1;
while(k<m*n&&a[k]-ans<eps)k++;
k--;
printf("Region %d\n",t++);
printf("Water level is %.2f meters.\n",ans);
printf("%.2f percent of the region is under water.\n",100*k/(1.0*m*n));
cin>>m>>n;
}
return 0;
}
复制代码
作者:
admin
时间:
2018-9-2 18:00
楼上两位还牛!
欢迎光临 华师一附中OI组 (http://hsyit.cn/)
Powered by Discuz! X3.2