标签:style blog http color os io for ar
水题,排序之后依次累加,模拟。
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> #include<map> #include<set> #include<list> #include<cmath> #include<string> #include<sstream> #include<ctime> using namespace std; #define _PI acos(-1.0) #define esp 1e-9 #define INF 1 << 30 typedef long long LL; typedef unsigned long long ULL; typedef pair<int,int> pill; /*=========================================== ===============KinderRiven=================== ===========================================*/ #define MAXD 1000 + 10 int n,m; int main(){ int Case = 1; while(scanf("%d%d",&n,&m)){ if(!n && !m) break; double array[MAXD],V; n = n * m; for(int i = 0 ; i < n ; i ++) scanf("%lf",&array[i]); scanf("%lf",&V); V /= 100; sort(array, array + n); int area = 0; while(V){ int i,j; for(i = 0 ; i < n - 1; i ++){ if(array[i] < array[i + 1]) break; } area = i + 1; if(i == n - 1){ double aver = V / n; V = 0; for(j = 0 ; j < n ; j++) array[j] += aver; } else{ double _V = (array[i + 1] - array[i]) * (i + 1); if(_V > V) _V = V; V -= _V; double aver = _V / (i + 1); for(j = 0 ; j <= i ; j++) array[j] += aver; } } printf("Region %d\n",Case++); printf("Water level is %.2f meters.\n",array[0]); printf("%.2f percent of the region is under water.\n",1.0 * area / n * 100); printf("\n"); } return 0; }
【UVA】815 - Flooded!,布布扣,bubuko.com
标签:style blog http color os io for ar
原文地址:http://blog.csdn.net/u013451221/article/details/38710097