算法竞赛入门经典 第二版 习题4-10 洪水 Flooded uva815
来源:互联网 发布:zbrush for mac 编辑:程序博客网 时间:2024/04/28 08:37
题目:https://vjudge.net/problem/UVA-815
读题时间贼长,紫书点名能锻炼思维,然而我迟迟想不出算法TvT
思路:将海拔递增排序,然后开始从海拔最低的区域计算若洪水淹没到这个区域最多需要多少水(即水平面等于海拔更高的区域的海拔),是否大于等于洪水体积。若是,则被淹没的区域就是循环变量+1。然后算出来水平面和比例就好。
注:(1)将水的体积除以100就可以忽略单位影响。
(2)被水全部淹没时需要处理。
(3)注意格式Follow the output for each region with a blank line.
最后一行后面也有空行。
代码:c++
#include <cstdio>#include <iostream>#include <algorithm>using namespace std;int main(){ int elevation[1000],m,n,cases=0,sum,cot; double proportion,h,v_water,v_temp; int i; while(cin>>m>>n) { if(m==0&&n==0) { break; } cases++; for(i=0; i<m*n; i++) { cin >> elevation[i]; } cin >> v_water; v_water /= 100; sort(elevation,elevation+m*n); sum = 0; for(i=0; i<m*n; i++) { sum += elevation[i]; if(i+1!=n*m) { v_temp = elevation[i+1]*(i+1) - sum; if(v_temp>=v_water) { break; } } } cot = i==m*n?i:i+1; h = (v_water+sum)/cot; proportion = 100*(double)cot/m/n; cout << "Region " << cases << endl; printf("Water level is %.2lf meters.\n", h); printf("%.2lf percent of the region is under water.\n\n", proportion); } return 0;}
0 0
- 算法竞赛入门经典 第二版 习题4-10 洪水 Flooded uva815
- 算法竞赛入门经典(第2版)习题4-10 洪水! Flooded! UVa815
- 算法竞赛入门经典(第2版)习题4-10 洪水!UVa815
- [刷题]算法竞赛入门经典(第2版) 4-10/UVa815 - Flooded!
- 算法竞赛入门经典 UVa815 Flooded!
- 习题4-10 UVa815 Flooded!
- 习题4-10 洪水! UVa815
- 习题4-10 洪水 UVa815
- UVa815:Flooded(洪水)
- UVa815--Flooded--洪水
- 洪水(Flooded! uva815)
- 算法竞赛入门经典第二章习题
- 算法竞赛入门经典习题 第二章
- 算法竞赛入门经典(第二版)-刘汝佳-第四章 函数与递归 洪水!
- 算法竞赛入门经典(第二版) 习题训练
- 【算法竞赛入门经典第二版学习】第三章习题
- 算法竞赛入门经典第二版第三章习题
- 算法竞赛入门经典(第二版) 习题
- Hibernate知识架构
- leetcode 167 Two Sum II - Input array is sorted
- hadoop配置时新手易犯的错误总结
- 3730: 震波
- el表达式获取数据
- 算法竞赛入门经典 第二版 习题4-10 洪水 Flooded uva815
- 32.768KHZ晶振的含义与发展
- 他娘的快排
- Hibernate知识点一
- 中华民国
- Hibernate二
- HDU 1061 Rightmost Digit 【快速幂 Or 规律(瞎搞)】
- OpenCV实践(1)-怎样扫描图像、查找表和运行效率的测定
- ACM萌新体验