5937: 杰夫和四舍五入

内存限制:256 MB 时间限制:2 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:1 通过:1

题目描述

A. 杰夫和四舍五入
每次测试的时间限制
1 秒
每个测试的内存限制
256 兆字节
输入
标准输入
输出
标准输出
杰夫得到了 2 n 个实数 a1,a 2,...,a 2 n 作为生日礼物。这个男孩讨厌非整数,所以他决定稍微“调整”他得到的数字。也就是说,Jeff 连续执行 n 个操作,每个操作如下:
  • 选择尚未选择的索引 i 和 j (ij);
  • 将元素 a i 舍入到不大于 i 的最接近整数(分配给 i:⌊ i ⌋);
  • 将元素 a j 舍入到不小于 j 的最接近整数(分配给 j: ⌈ j⌉)。
尽管如此,杰夫不想伤害给他序列的人的感情。这就是为什么男孩想要执行操作,以使执行操作之前的元素总和和执行操作后的元素总和之间的差值的绝对值尽可能小。帮助 Jeff 找到差值的最小绝对值。
输入
第一行包含整数 n (1≤n≤2000)。下一行包含 2 n 个实数 a 1a 2...2 n (0≤ai≤10000),小数点后正好有三位数字。数字用空格分隔。
输出
在一行中打印一个实数 - 所需的差值,小数点后正好有三位数字
例子
输入
3
0.000 0.500 0.750 1.000 2.000 3.000
输出
0.250
输入
3
4469.000 6526.000 4864.000 9356.383 7490.000 995.896
输出
0.279
注意
在第一个测试用例中,您需要执行以下操作:(i=1,j=4)、(i=2,j=3)、i=5,j=6)。在这种情况下,差值将等于 |(0+0.5+0.75+1+2+3)-(0+0+1+1+2+3)|=0.25
A. Jeff and Rounding
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Jeff got 2n real numbers a1,a2,...,a2n as a birthday present. The boy hates non-integer numbers, so he decided to slightly "adjust" the numbers he's got. Namely, Jeff consecutively executes n operations, each of them goes as follows:
  • choose indexes i and j (ij) that haven't been chosen yet;
  • round element ai to the nearest integer that isn't more than ai (assign to ai: ai);
  • round element aj to the nearest integer that isn't less than aj (assign to aj: aj).
Nevertheless, Jeff doesn't want to hurt the feelings of the person who gave him the sequence. That's why the boy wants to perform the operations so as to make the absolute value of the difference between the sum of elements before performing the operations and the sum of elements after performing the operations as small as possible. Help Jeff find the minimum absolute value of the difference.
Input
The first line contains integer n (1≤n≤2000). The next line contains 2n real numbers a1, a2, ..., a2n (0≤ai≤10000), given with exactly three digits after the decimal point. The numbers are separated by spaces.
Output
In a single line print a single real number − the required difference with exactly three digits after the decimal point.
Examples
Input
3
0.000 0.500 0.750 1.000 2.000 3.000
Output
0.250
Input
3
4469.000 6526.000 4864.000 9356.383 7490.000 995.896
Output
0.279
Note
In the first test case you need to perform the operations as follows: (i=1,j=4), (i=2,j=3), (i=5,j=6). In this case, the difference will equal |(0+0.5+0.75+1+2+3)-(0+0+1+1+2+3)|=0.25.

输入样例 复制


输出样例 复制


分类标签