关键就是给海拔排个序,找出有多少快地低于水平面。
要注意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 }
时间: 2024-11-05 02:32:00