uva 815 Flooded!

题意:n*m的网格,每个网格10m的正方形,网格四周是无限大的墙壁,输入每个格子的高度和洪水的体积,求水位的高度和淹没的面积。

分析:水肯定是先淹没高度低的,后淹没高度高的,所以对所有海拔排序,从低向高遍历,直到遇到不能淹没的网格停止。

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<algorithm>
 4 using namespace std;
 5 const int mmax=35*35;
 6 int dp[mmax],n,m;
 7
 8 int main()
 9 {
10    for (int kase = 1; scanf("%d%d", &n, &m), n&&m; kase++)
11    {
12       n*=m;
13       for(int i=0;i<n;i++)
14          cin>>dp[i];
15       sort(dp,dp+n);
16       dp[n]=0x7fffffff;
17
18       int t;double sum;
19       cin>>sum;sum/=100;
20
21       for(t=1;t<=n;t++)
22       {
23          sum+=dp[t-1];
24          if(sum/t<=dp[t])
25             break;
26       }
27       printf("Region %d\n", kase);
28       printf("Water level is %.2lf meters.\n", sum/t);
29       printf("%.2lf percent of the region is under water.\n\n", t*100.0/n);
30    }
31    return 0;
32 }

时间: 2024-11-08 13:37:33

uva 815 Flooded!的相关文章

UVA - 815 Flooded!(模拟)

Flooded! Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Submit Status Description To enable homebuyers to estimate the cost of flood insurance, a real-estate firm provides clients with the elevation of each 10-meter by 10-m

uva 815 - Flooded!(点名要做的思路题~我觉得方法挺好)

#include<stdio.h> #include<string.h> #include<iostream> #include<algorithm> using namespace std; double a[100000]; double vol[100000]; int m,n; double v1,v2; bool cmp(double aa,double bb) { if(aa>bb) return true; } int main() {

【UVA】815 - Flooded!

水题,排序之后依次累加,模拟. 14069284 815 Flooded! Accepted C++ 0.032 2014-08-20 10:42:17 AC代码: #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<vector> #include<stack> #include<queue> #includ

【习题 4-9 UVA - 815】Flooded!

[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 题目很迷啊. 不会出现盆地? 可以理解为一条线. 从左往右高度上升的一座座山. 然后V升的水从最左边的山倒进去. 然后问你最后海拔多高.. (为什么是这样啊??? 鬼知道... 所以每次只要看看前i个山同时升高a[i+1]-a[i]是不是小于等于rest就好. 小于等于的话.就能持续升高. [代码] #include <bits/stdc++.h> #define rep1(i,a,b) for (int i = a;i &l

uvA Flooded!

Description To enable homebuyers to estimate the cost of flood insurance, a real-estate firm provides clients with the elevation of each 10-meter by 10-meter square of land in regions where homes may be purchased. Water from rain, melting snow, and b

UVA 562 Dividing coins --01背包的变形

01背包的变形. 先算出硬币面值的总和,然后此题变成求背包容量为V=sum/2时,能装的最多的硬币,然后将剩余的面值和它相减取一个绝对值就是最小的差值. 代码: #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; #define N 50007 int c[102],d

UVA 10341 Solve It

Problem F Solve It Input: standard input Output: standard output Time Limit: 1 second Memory Limit: 32 MB Solve the equation: p*e-x + q*sin(x) + r*cos(x) + s*tan(x) + t*x2 + u = 0 where 0 <= x <= 1. Input Input consists of multiple test cases and te

UVA 11014 - Make a Crystal(容斥原理)

UVA 11014 - Make a Crystal 题目链接 题意:给定一个NxNxN的正方体,求出最多能选几个整数点.使得随意两点PQ不会使PQO共线. 思路:利用容斥原理,设f(k)为点(x, y, z)三点都为k的倍数的点的个数(要扣掉一个原点O).那么全部点就是f(1),之后要去除掉共线的,就是扣掉f(2), f(3), f(5)..f(n).n为素数.由于这些素数中包括了合数的情况,而且这些点必定与f(1)除去这些点以外的点共线,所以扣掉.可是扣掉后会扣掉一些反复的.比方f(6)在f

[UVa] Palindromes(401)

UVA - 401 Palindromes Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Submit Status Description A regular palindrome is a string of numbers or letters that is the same forward as backward. For example, the string "ABCDED