首页 > 代码库 > 【UVA】815 - Flooded!
【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> #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; }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。