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. 实验二 四则运算 完成版 ver.1

    package size; import java.awt.EventQueue; import javax.swing.JFrame; import javax.swing.JMenuBar; im ...

  2. ORA-03113:通信通道的文件结尾-完美解决方案

    ORA-03113:通信通道的文件结尾-完美解决方案   oracle 文档中对这个错误这样解释: ORA-03113 错误就是说连接到数据库的网络中断了.有些错误由于频繁出现.原因复杂而被 Orac ...

  3. 面试问题总结二(技术能力-PHP)----Ⅰ

    1.你都做过什么项目? 答:第一份实习工作接触的项目是CRM 销售管理系统,一款用JSP语言开发的进销存管理系统.第一份正式工作是一款主打高质量图片社交社区网站项目,“美啦周末”(后改型为”聊会儿”) ...

  4. 网页正文提取,降噪的实现(readability/Document)

    安装: pip install readability-lxml 使用: # encoding:utf-8import html2textimport requestsimport refrom re ...

  5. 初入码田--ASP.NET MVC4 Web应用开发之二 实现简单的增删改查

    初入码田--ASP.NET MVC4 Web应用之创建一个空白的MVC应用程序 初入码田--ASP.NET MVC4 Web应用开发之一 实现简单的登录 2016-07-29  一.创建M002Adm ...

  6. Kafka日志存储原理

    引言 Kafka中的Message是以topic为基本单位组织的,不同的topic之间是相互独立的.每个topic又可以分成几个不同的partition(每个topic有几个partition是在创建 ...

  7. C++模式学习------代理模式

    Proxy代理模式 : 为其他对象提供一种代理以控制对这个对象的访问.代理类作为桥梁是请求方和执行方的中间者,将请求方和真正的执行方分割开来,也是两者之间调用的协调者.例如执行类也就是被代理类,可以在 ...

  8. [BZOJ3230] 相似字串 后缀数组+RMQ

    3230: 相似子串 Time Limit: 20 Sec  Memory Limit: 128 MB Description Input 输入第1行,包含3个整数N,Q.Q代表询问组数.第2行是字符 ...

  9. 【转】Microsoft Visio2010 如何画UML 图

    转载:http://sdoq19.blog.163.com/blog/static/1910392122012419103442292/ 1.在Microsoft Office2010中打开Micro ...

  10. Java多线程相关的

    很多小伙伴在学习Java的时候,总是感觉Java多线程在实际的业务中很少使用,以至于不会花太多的时间去学习,技术债不断累积!等到了一定程度的时候对于与Java多线程相关的东西就很难理解,今天需要探讨的 ...