标签:des style blog http color java io strong
Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 263 Accepted Submission(s): 73
1 #include <cstdio> 2 #include <cstring> 3 #include <stack> 4 using namespace std; 5 6 #define eps 0.00000001 7 const int LEN = 100010; 8 9 int arr[LEN]; 10 struct line 11 { 12 int l, r, sum; 13 double rate; 14 }; 15 16 stack<line> s; 17 18 int main() 19 { 20 int T, n; 21 line tmp; 22 scanf("%d", &T); 23 while(T--){ 24 scanf("%d", &n); 25 for(int i = 0; i < n; i++) 26 scanf("%d", arr+i); 27 int h = 0; 28 while(arr[h] == 0) 29 h++; 30 int k = n - 1; 31 while(arr[k] == 1) 32 k--; 33 for(int i = h; i <= k; i++){ 34 if (i == h || i > h && arr[i-1] == 0 && arr[i] == 1){ 35 tmp.l = i; 36 tmp.sum = 0; 37 } 38 if (i < k && arr[i] == 0 && arr[i+1] == 1 || i == k){ 39 tmp.r = i; 40 //printf("l = %d, r = %d\n", tmp.l, tmp.r); 41 tmp.rate = tmp.sum * 1.0 / ((tmp.r - tmp.l + 1) * 1.0); 42 //printf("rate=%f\n", tmp.rate); 43 while(true){ 44 if (s.empty() || s.top().rate - tmp.rate < eps){ 45 s.push(tmp); 46 break; 47 } 48 if (s.top().rate - tmp.rate > eps){ 49 tmp.l = s.top().l; 50 tmp.sum += s.top().sum; 51 tmp.rate = tmp.sum*1.0 / ((tmp.r - tmp.l + 1)*1.0); 52 s.pop(); 53 } 54 } 55 } 56 if (arr[i] == 1) 57 tmp.sum++; 58 } 59 double ans = 0; 60 while(!s.empty()){ 61 ans += ((1 - s.top().rate) * (1 - s.top().rate) * s.top().sum + s.top().rate * s.top().rate * (s.top().r - s.top().l + 1 - s.top().sum)); 62 s.pop(); 63 } 64 printf("%f\n", ans); 65 } 66 return 0; 67 }
【HDU】4923 Room and Moor(2014多校第六场1003),布布扣,bubuko.com
【HDU】4923 Room and Moor(2014多校第六场1003)
标签:des style blog http color java io strong
原文地址:http://www.cnblogs.com/kevince/p/3898004.html