F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Monotone SE Min

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 452    Accepted Submission(s): 141


Problem Description
Given a sequence of bits (0's and 1's), we want to find an arbitrary monotonically increasing curve (单调递增函数)that best fits the bits. That is, the i-th bit is b(i), and we want to find some curve, f, such that for x<y, f(x) <= f(y), and the sum over i of (f(i)-b(i))^2 (the squared error)(方差) is minimized. Given the sequence of bits as a string, return the minimum possible squared error.
 

Input
Multiple test cases!
For each case the input contains a string consisting of only 0 and 1 in one line. The bits string will contain between 1 and 200 elements.
 

Output
For each case, output the minimum possible squared error in one line, accurate up to 3 decimal places.
 

Sample Input
00 101
 

Sample Output
0.000 0.500 Hint: For example 1, we can make f(1) = 0, f(2) = 0. For example 2, we can make f(1) = 0.5, f(2) = 0.5, f(3) = 1.
 

Author
scnu
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-05-11 12:14:46, Gzip enabled