本文主要是介绍815 - Flooded! (UVA),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
题目链接如下:
Online Judge
这道题要求“Follow the output for each region with a blank line.”,而不是region之间加空行,我在这个点上卡了很久……
然后我有点把题复杂化了,其实不用算currArea那么复杂,直接用一个for循环,循环到哪就有几块地被淹了,挺简单的....下面这个代码写得比较好。
https://www.cnblogs.com/zyb993963526/p/6297474.html
我的(复杂)代码如下:
#include <cstdio>
#include <vector>
#include <algorithm>
// #define debugint m, n, tot, currArea, pivot, kase = 0;
double waterLevel;int main(){#ifdef debugfreopen("0.txt", "r", stdin);freopen("1.txt", "w", stdout);#endifwhile(scanf("%d %d", &m, &n) == 2 && m && n){std::vector<int> vec(m * n);for(int i = 0; i < m * n; ++i){scanf("%d", &vec[i]);}sort(vec.begin(), vec.end());scanf("%d", &tot);currArea = 0;pivot = -1;waterLevel = vec[0];while(tot){do{pivot++;currArea += 100;} while(pivot < vec.size() - 1 && vec[pivot + 1] == vec[pivot]);if(pivot == vec.size() - 1 || tot * 1.0 / currArea <= vec[pivot + 1] - vec[pivot]){waterLevel = vec[pivot] + tot * 1.0 / currArea;break;}tot -= currArea * (vec[pivot + 1] - vec[pivot]);}printf("Region %d\nWater level is %.2f meters.\n%.2f percent of the region is under water.\n\n", ++kase, waterLevel, (pivot + 1) * 100.0 / m / n);}#ifdef debugfclose(stdin);fclose(stdout);#endifreturn 0;
}
这篇关于815 - Flooded! (UVA)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!