http://codeforces.com/problemset/problem/351/A

题意:

2*n个数,选n个数上取整,n个数下取整

最小化 abs(取整之后数的和-原来数的和)

先使所有的数都下取整,累积更改的sum

那么选1个小数上取整,就会使sum-1

整数上下取整不会产生影响

所以有1个整数就可以使上取整的小数少1个

所以ans=min(abs(i-sum)) i∈[n-整数个数,n]

#include<cmath>
#include<cstdio>
#include<algorithm> using namespace std; const double eps=1e-; int main()
{
int n;
scanf("%d",&n);
int m=n<<;
int cnt=;
double x;
double sum=;
for(int i=;i<=m;++i)
{
scanf("%lf",&x);
sum+=x-floor(x);
if(x-floor(x)<eps) cnt++;
}
double ans=1e9;
for(int i=n;i>=n-cnt;--i) ans=min(ans,abs(i-sum));
printf("%.3lf",ans);
}
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 (i ≠ j) 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.

CF&&CC百套计划3 Codeforces Round #204 (Div. 1) A. Jeff and Rounding的更多相关文章

  1. CF&&CC百套计划3 Codeforces Round #204 (Div. 1) D. Jeff and Removing Periods

    http://codeforces.com/problemset/problem/351/D 题意: n个数的一个序列,m个操作 给出操作区间[l,r], 首先可以删除下标为等差数列且数值相等的一些数 ...

  2. CF&&CC百套计划3 Codeforces Round #204 (Div. 1) E. Jeff and Permutation

    http://codeforces.com/contest/351/problem/E 题意: 给出一些数,可以改变任意数的正负,使序列的逆序对数量最少 因为可以任意加负号,所以可以先把所有数看作正数 ...

  3. CF&&CC百套计划3 Codeforces Round #204 (Div. 1) B. Jeff and Furik

    http://codeforces.com/contest/351/problem/B 题意: 给出一个n的排列 第一个人任选两个相邻数交换位置 第二个人有一半的概率交换相邻的第一个数>第二个数 ...

  4. CF&&CC百套计划4 Codeforces Round #276 (Div. 1) A. Bits

    http://codeforces.com/contest/484/problem/A 题意: 询问[a,b]中二进制位1最多且最小的数 贪心,假设开始每一位都是1 从高位i开始枚举, 如果当前数&g ...

  5. CF&&CC百套计划4 Codeforces Round #276 (Div. 1) E. Sign on Fence

    http://codeforces.com/contest/484/problem/E 题意: 给出n个数,查询最大的在区间[l,r]内,长为w的子区间的最小值 第i棵线段树表示>=i的数 维护 ...

  6. CF&&CC百套计划1 Codeforces Round #449 C. Willem, Chtholly and Seniorious (Old Driver Tree)

    http://codeforces.com/problemset/problem/896/C 题意: 对于一个随机序列,执行以下操作: 区间赋值 区间加 区间求第k小 区间求k次幂的和 对于随机序列, ...

  7. CF&&CC百套计划1 Codeforces Round #449 B. Ithea Plays With Chtholly

    http://codeforces.com/contest/896/problem/B 题意: 交互题 n张卡片填m个1到c之间的数,1<=n*ceil(c/2)<=m 最后填出一个单调非 ...

  8. CF&&CC百套计划1 Codeforces Round #449 A. Nephren gives a riddle

    http://codeforces.com/contest/896/problem/A 第i个字符串嵌套第i-1个字符串 求第n个字符串的第k个字母 dfs #include<map> # ...

  9. Codeforces Round #204 (Div. 2)->C. Jeff and Rounding

    C. Jeff and Rounding time limit per test 1 second memory limit per test 256 megabytes input standard ...

随机推荐

  1. 第二篇——VC++简单随机四则运算

    目标:编写最简单的四则运算,类似A+B=C: 想法:建立一个Win32控制台应用程序,A和B用随机数表示,运算符号用0~3的数字对应,然后计算并输出即可: 具体过程: 利用函数rand(),返回一个0 ...

  2. 软工实践-Beta 冲刺 (6/7)

    队名:起床一起肝活队 组长博客:博客链接 作业博客:班级博客本次作业的链接 组员情况 组员1(队长):白晨曦 过去两天完成了哪些任务 描述: 1.界面的修改与完善 展示GitHub当日代码/文档签入记 ...

  3. 利用python进行简单的图像处理:包括打开,显示以及保存图像

    利用python进行简单的图像处理:包括打开,显示以及保存图像 利用PIL处理 PIL(python image library) 是python用于图片处理的package.但目前这个package ...

  4. 一、SpringBoot热部署

    一.热部署优点: 1.无论本地还是线上都适用 2.无需重启服务器 (1)提高开发.调试效率 (2)提升发布.运维效率.降低运维成本 二.和热加载的区别

  5. 一个简单的加减乘除自动生成小程序(JAVA)

    在学习软件工程的时候,遇到一个这样的问题,一个程序员的儿子上小学二年级,老师让家长每天出30道加减题目给学生做,由于家长是个程序员,所以呢,他就自己写了个程序实现,我们可爱的老师于是也叫我们写了一个类 ...

  6. Software Defined Networking(Week 3, part 1)

    Control and Data Plane Seperation 课程地址 Overview 今天正式地学习一个控制与数据平面分离.学习完本节,应该要掌握何为控制和数据平面,了解它们的功能以及好处, ...

  7. C#简单窗体应用程序(一)

    使用C#创建控制台应用程序的基本步骤: (1)创建项目: (2)用户界面设计: (3)属性设置: (4)编写程序代码: (5)保存.调试.运行: 例题:创建一个Windows窗体应用程序,在窗体中添加 ...

  8. 结对项目作业报告——四则运算web项目

    成员:顾思宇2016011993 程羚2016012050   1.仓库地址:https://git.coding.net/DandelionClaw/WEB_Calculator.git 注: 本项 ...

  9. 手动解析Excel获取文件元数据

    工作中有遇到需要获取上传的Excel文件的列明.最大行数.大小等元数据信息.通常做法是通过Apache的POI工具加载文件然后再读取行列进行处理.这种方法很大的弊端就是需要把excel文件加载到内存, ...

  10. MongoDB中的数据导出为excel CSV 文件

    1.打开命令行,进入我们所安装的mongodb路径下的bin文件夹 2.我们采用bin文件夹下的mongoexport方法进行导出, mongoexport -d myDB -c user -f _i ...