zoukankan      html  css  js  c++  java
  • UVA

    /*
      后来发现思路最为清晰简洁的,是这个博主;
      http://blog.csdn.net/code4101/article/details/38540759
      
      他的代码让我感受到,只要将问题想得十分透彻,尤其是边界条件考虑得十分清楚,代码长度完全可以大大缩短,学习了,同时也照着此思路改了自己的冗长代码
      
      碎碎念:
      在vj上观察自己的程序的运行时间的时候,发现...有没有加这两句话
      cin.tie(0);
      cin.sync_with_stdio(false);
      真的是0ms 和 10ms的区别啊!
      怪不得之前忘了写的时候,总是被卡TLE,又想到了之前被POJ卡TLE的经历  T^T
    */


    #include <iostream>
    #include <algorithm>
    #include<iomanip>
    using namespace std;
    const int N = 1000;
    const int INF = 0x3f3f3f3f;
    int h[N]; // height
    int main()
    {
    	cin.tie(0);
    	cin.sync_with_stdio(false);
    	int kase = 0;
    	int n, m;
    	while (cin >> n >> m && n && m)
    	{
    		n *= m;
    		for (int i = 0; i < n; i++) cin >> h[i];
    		sort (h, h + n); //将海拔高度从小到大排序 
    		h[n] = INF;
    		
    		int k;
    		double sum;
    		cin >> sum;
    		sum /= 100.0; //体积除以底面积,得到洪水真正的高度 
    		for (k = 1; k <= n; k++)
    		{
    			sum += h[k - 1]; //将洪水高度与 单个格子高度 相加。
    			if (sum / k < h[k]) break; // 计算当前格子前面的格子的海拔高度,若小于当前格子的高度,说明当前格子一定不会被装满水,可以退出
    			// 为了处理边界情况,因此将a[n]设置为一个无穷大的数,使得若是所有格子都能装满,仍然可以用此循环正确退出,并得到正确的结果 
    		}
    		cout << "Region " << ++kase << endl;
    		cout << "Water level is " << fixed << setprecision(2) << 1.0 * sum / k << " meters." << endl;
    		cout << k * 100.0 / n << " percent of the region is under water." << endl << endl;
    		
    	}
    	return 0;
    }


  • 相关阅读:
    poj3720
    poj3099
    poj3734
    poj3112
    poj3723
    十二个开源UML工具推荐
    关于大型asp.net应用系统的架构—如何做到高性能高可伸缩性
    读《中央确定西部新十年战略》有感
    DirectShow基础编程 最简单的源Filter的编写步骤
    Access2007无法执行查询,操作或事件已被禁用模式阻止
  • 原文地址:https://www.cnblogs.com/mofushaohua/p/7789471.html
Copyright © 2011-2022 走看看