A9254 | Jeff and Rounding
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Jeff got $2n$ real numbers $a_{1},a_{2},...,a_{2n}$ 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$ $(i≠j)$ that haven't been chosen yet;
- round element $a_{i}$ to the nearest integer that isn't more than $a_{i}$ (assign to $a_{i}$ : $⌊\ a_{i} ⌋$ );
- round element $a_{j}$ to the nearest integer that isn't less than $a_{j}$ (assign to $a_{j}$ : $⌈\ a_{j} ⌉$ ).
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.
- choose indexes $i$ and $j$ $(i≠j)$ that haven't been chosen yet;
- round element $a_{i}$ to the nearest integer that isn't more than $a_{i}$ (assign to $a_{i}$ : $⌊\ a_{i} ⌋$ );
- round element $a_{j}$ to the nearest integer that isn't less than $a_{j}$ (assign to $a_{j}$ : $⌈\ a_{j} ⌉$ ).
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.
输入格式
The first line contains integer $n$ $(1<=n<=2000)$ . The next line contains $2n$ real numbers $a_{1}$ , $a_{2}$ , $...$ , $a_{2n}$ $(0<=a_{i}<=10000)$ , given with exactly three digits after the decimal point. The numbers are separated by spaces.
输出格式
In a single line print a single real number — the required difference with exactly three digits after the decimal point.
输入输出样例
输入 #1
3 0.000 0.500 0.750 1.000 2.000 3.000
输出 #1
0.250
输入 #2
3 4469.000 6526.000 4864.000 9356.383 7490.000 995.896
输出 #2
0.279
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$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted