UVA815(洪水)。

关键就是给海拔排个序,找出有多少快地低于水平面。

要注意n=m=1的情况,和100%的情况。

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstdlib>
 4 #include <string>
 5 #include <vector>
 6 #include <cctype>
 7 #include <cstring>
 8 #include <algorithm>
 9 
10 using namespace std;
11 
12 int main()
13 {
14     int n,m,i,j,k;
15     int a[35][35];
16     int high[1010];
17     int flag = 0;
18     while(cin >> n >> m &&n&&m)
19     {
20         int t = 0;
21         memset(a,0,sizeof(a));
22         memset(high,0,sizeof(high));
23         for(i=0; i<n; i++)
24             for(j=0; j<m; j++)
25             {
26                 cin >> a[i][j];
27                 high[t++]=a[i][j];
28             }
29         cin >> k;
30         sort(high,high+t);
31         int Min = high[0];
32         int sum = 0,x = 0;
33         if(t==1)
34         {
35             double h = high[0]+k/(100*1.0);
36             double cnt = 100;
37             printf("Region %d\n",++flag);
38             printf("Water level is %.2f meters.\n",h);
39             printf("%.2f percent of the region is under water.\n\n",cnt);
40         }
41         else
42         {
43             for(i=1; i<=t; i++)
44             {
45                 sum+=100*i*(high[i]-high[i-1]);
46                 if(sum>=k)
47                 {
48                     x = i;
49                     break;
50                 }
51             }
52             if(i==t+1&&x == 0)
53                 x = n*m;
54             // printf("x=%d\n",x);
55             sum-=(high[x]-high[x-1])*100*(x);
56             int left = k-sum;
57             double h = left/(100*(x)*1.0)+high[x-1];
58             double cnt = (x)/(n*m*1.0)*100;
59             printf("Region %d\n",++flag);
60             printf("Water level is %.2f meters.\n",h);
61             printf("%.2f percent of the region is under water.\n\n",cnt);
62         }
63     }
64     return 0;
65 }

 

转载于:https://www.cnblogs.com/HsiaoYeekwan/p/6329721.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值