题目链接:http://poj.org/problem?id=1877
赛前水一题,希望明天的邀请赛能取得好的成绩!
1 //STATUS:C++_AC_110MS_200KB 2 #include <functional> 3 #include <algorithm> 4 #include <iostream> 5 #include <fstream> 6 #include <sstream> 7 #include <iomanip> 8 #include <numeric> 9 #include <cstring> 10 #include <cassert> 11 #include <cstdio> 12 #include <string> 13 #include <vector> 14 #include <bitset> 15 #include <queue> 16 #include <stack> 17 #include <cmath> 18 #include <ctime> 19 #include <list> 20 #include <set> 21 #include <map> 22 using namespace std; 23 //define 24 #define pii pair<int,int> 25 #define mem(a,b) memset(a,b,sizeof(a)) 26 #define lson l,mid,rt<<1 27 #define rson mid+1,r,rt<<1|1 28 #define PI acos(-1.0) 29 //typedef 30 typedef long long LL; 31 typedef unsigned long long ULL; 32 //const 33 const int N=1010; 34 const int INF=0x3f3f3f3f; 35 const int MOD=100000,STA=8000010; 36 const LL LNF=1LL<<60; 37 const double EPS=1e-8; 38 const double OO=1e15; 39 const int dx[4]={-1,0,1,0}; 40 const int dy[4]={0,1,0,-1}; 41 //Daily Use ... 42 inline int sign(double x){return (x>EPS)-(x<-EPS);} 43 template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;} 44 template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;} 45 template<class T> inline T Min(T a,T b){return a<b?a:b;} 46 template<class T> inline T Max(T a,T b){return a>b?a:b;} 47 template<class T> inline T Min(T a,T b,T c){return min(min(a, b),c);} 48 template<class T> inline T Max(T a,T b,T c){return max(max(a, b),c);} 49 template<class T> inline T Min(T a,T b,T c,T d){return min(min(a, b),min(c,d));} 50 template<class T> inline T Max(T a,T b,T c,T d){return max(max(a, b),max(c,d));} 51 //End 52 53 double ma[N]; 54 double v; 55 int n,m; 56 57 58 int main() 59 { 60 // freopen("in.txt","r",stdin); 61 // freopen("out.txt","w",stdout); 62 int i,j,cnt,k=1; 63 double h,vt,t[N]; 64 while(~scanf("%d%d",&n,&m) && (n || m) ) 65 { 66 n*=m; 67 for(i=0;i<n;i++) 68 scanf("%lf",&ma[i]); 69 scanf("%lf",&v); 70 71 sort(ma,ma+n); 72 for(i=0;i<n;i++)t[i]=ma[i+1]-ma[i]; 73 for(i=0;i<n-1;i++){ 74 vt=(i+1)*100*t[i]; 75 if(vt<=v)v-=vt; 76 else break; 77 } 78 cnt=i+1; 79 h=ma[i]+v/(cnt*100); 80 81 printf("Region %d\n",k++); 82 printf("Water level is %.2lf meters.\n",h); 83 printf("%.2lf percent of the region is under water.\n\n",(double)cnt*100/n); 84 } 85 return 0; 86 }