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

Copy
3
0.000 0.500 0.750 1.000 2.000 3.000
Output

Copy
0.250
Input

Copy
3
4469.000 6526.000 4864.000 9356.383 7490.000 995.896
Output

Copy
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.

假设小数部分是x的话,向下取整为-x,向上为1-x;

可以发现不论是向下还是向上都是 -x,那么小数部分就可以统一处理;

那么问题就是当向上取整时,会+1----->求1的个数;

那么枚举就行了;

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<bitset>
#include<ctime>
#include<deque>
#include<stack>
#include<functional>
#include<sstream>
//#include<cctype>
//#pragma GCC optimize(2)
using namespace std;
#define maxn 200005
#define inf 0x7fffffff
//#define INF 1e18
#define rdint(x) scanf("%d",&x)
#define rdllt(x) scanf("%lld",&x)
#define rdult(x) scanf("%lu",&x)
#define rdlf(x) scanf("%lf",&x)
#define rdstr(x) scanf("%s",x)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int U;
#define ms(x) memset((x),0,sizeof(x))
const long long int mod = 1e9 + 7;
#define Mod 1000000000
#define sq(x) (x)*(x)
#define eps 1e-3
typedef pair<int, int> pii;
#define pi acos(-1.0)
//const int N = 1005;
#define REP(i,n) for(int i=0;i<(n);i++)
typedef pair<int, int> pii;
inline ll rd() {
ll x = 0;
char c = getchar();
bool f = false;
while (!isdigit(c)) {
if (c == '-') f = true;
c = getchar();
}
while (isdigit(c)) {
x = (x << 1) + (x << 3) + (c ^ 48);
c = getchar();
}
return f ? -x : x;
} ll gcd(ll a, ll b) {
return b == 0 ? a : gcd(b, a%b);
}
ll sqr(ll x) { return x * x; } /*ll ans;
ll exgcd(ll a, ll b, ll &x, ll &y) {
if (!b) {
x = 1; y = 0; return a;
}
ans = exgcd(b, a%b, x, y);
ll t = x; x = y; y = t - a / b * y;
return ans;
}
*/ int n;
int m; int main() {
//ios::sync_with_stdio(0);
cin >> n;
m = 2 * n;
double tmp;
int numeq = 0;
double sum = 0.0;
int numdb = 0;
for (int i = 1; i <= m; i++) {
rdlf(tmp);
ll intmp = (ll)tmp;
if (intmp == tmp)numeq++;
else {
sum += 1.0*(tmp - intmp);
numdb++;
}
}
int minn = min(n, numeq);
double ans = inf;
for (int i = 0; i <= minn; i++) {
ans = min(ans, (double)fabs(n - i - sum));
}
printf("%.3lf\n", 1.0*ans);
return 0;
}

CF351A Jeff and Rounding 思维的更多相关文章

  1. 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 ...

  2. CodeForces 352C. Jeff and Rounding(贪心)

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

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

    http://codeforces.com/problemset/problem/351/A 题意: 2*n个数,选n个数上取整,n个数下取整 最小化 abs(取整之后数的和-原来数的和) 先使所有的 ...

  4. codeforces A. Jeff and Rounding (数学公式+贪心)

    题目链接:http://codeforces.com/contest/351/problem/A 算法思路:2n个整数,一半向上取整,一半向下.我们设2n个整数的小数部分和为sum. ans = |A ...

  5. cf C. Jeff and Rounding

    http://codeforces.com/contest/352/problem/C 题意:给予N*2个数字,改变其中的N个向上进位,N个向下进位,使最后得到得数与原来数的差的绝对值最小 对每一个浮 ...

  6. Codeforces Round #204 (Div. 2) C. Jeff and Rounding——数学规律

    给予N*2个数字,改变其中的N个向上进位,N个向下进位,使最后得到得数与原来数的差的绝对值最小 考虑小数点后面的数字,如果这些数都非零,则就是  abs(原数小数部分相加-1*n), 多一个0 则 m ...

  7. CF 351A - Jeff and Rounding DP

    http://codeforces.com/problemset/problem/351/C 题意:有2*n个浮点数a1,a2,a3...a2*n,把他们分成n队,对于每对<A,B>,对A ...

  8. CodeForces 352C Jeff and Rounding

    题意 有一个含有\(2n(n \leqslant2000)\)个实数的数列,取出\(n\)个向上取整,另\(n\)个向下取整.问取整后数列的和与原数列的和的差的绝对值. 就是说,令\(a\)为原数列, ...

  9. 数学思维——cf351A

    把每个值的各种贡献算一下即可 /* ai的小数部分为xi,向下取整对答案贡献为xi 向上取整对答案的贡献是xi-1,如果这个数是0,那么对答案的贡献是xi,即如果0向上取整就可以免去-1 然后sum{ ...

随机推荐

  1. springmvc----demo1---hello---bai

    import java.util.HashMap; import java.util.Map; import javax.servlet.http.HttpServletRequest; import ...

  2. PowerDesigner生成sql脚本时去掉双引号并把字段名设为大写

    Database菜单—Edit Current RDBMS 找到Script---sql—Format--- CaseSensitivityUsingQuote,把它设置为NO 这样再用sql pre ...

  3. javascript——作用域与闭包

    http://www.cnblogs.com/lucio-yr/p/4047972.html 一.作用域: 在函数内部:用 var 声明的表示局部变量,未用var的是全局变量. 作用域取决于变量定义时 ...

  4. Android中Activity之间的数据传递

    在开发中,我们经常涌用到Activity,那么既然用到了Activity,就一定免不了在两个或者多个Activity之间传递数据.这里我们先说一说原理,然后在看看代码和例子. 情况A:我们需要从Act ...

  5. [patl2-020]功夫传人

    解题关键:dfs的简单应用,需要注意类型double与int #include<cstdio> #include<cstring> #include<algorithm& ...

  6. GCD学习(六) dispatch_async 和dispatch_sync

    dispatch_sync(),同步添加操作.他是等待添加进队列里面的操作完成之后再继续执行. dispatch_queue_t concurrentQueue = dispatch_queue_cr ...

  7. Damn Couples ZOJ - 3161

    传送门 题目大意 N个人,M组关系,每次选一种关系,如果两个人相邻,则任意删除其中一个,否则不变.问最坏情况下最多能剩多少人. 分析 为了留的人最多,我们可以先将原来不相邻的关系全部说完,这样我们只需 ...

  8. 查看类属性和方法---structure

  9. java的编码问题详解

    ucenter的中文问题终于解决,这也暴露我对Java编码知识的严重不足,经过多次试验和搜索,对这块知识终于有了一个新的认识,所以把理解的内容写道这里 1:JVM的内存中字符串的编码格式是统一的吗? ...

  10. C++面试笔记--单链表

    1.编程实现单链表删除节点.       解析:如果删除的是头节点,如下图: 则把head指针指向头节点的下一个节点.同时free p1,如下图所示: 如果删除的是中间节点,如下图所示: 则用p2的n ...