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

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-7;

int main()
{
    int n;
    scanf("%d",&n);
    int m=n<<1;
    int cnt=0;
    double x;
    double sum=0;
    for(int i=1;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

30.000 0.500 0.750 1.000 2.000 3.000

output

0.250

input

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

时间: 2024-10-13 22:07:29

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

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

http://codeforces.com/problemset/problem/351/D 题意: n个数的一个序列,m个操作 给出操作区间[l,r], 首先可以删除下标为等差数列且数值相等的一些数 然后可以对区间剩余数重排 继续删除下标为等差数列且数值相等的一些数 继续对区间进行重排 直至区间内没有数 问每次操作的最少删除次数 因为每次删除后可以重排 那么完全可以在第一次删除后就把区间相等的数排在一起 这样相等的数的下标就分别构成了公差为1的等差数列 所以问题转化为 设区间[l,r]内数有x

CF&amp;&amp;CC百套计划2 CodeChef December Challenge 2017 Chef And his Cake

https://www.codechef.com/DEC17/problems/GIT01 #include<cstdio> #include<algorithm> using namespace std; #define N 101 char s[N]; int main() { int T; scanf("%d",&T); int n,m; int OddG,OddR,EvenG,EvenR; int ans; while(T--) { OddG=O

CF&amp;&amp;CC百套计划2 CodeChef December Challenge 2017 Chef and Hamming Distance of arrays

https://www.codechef.com/DEC17/problems/CHEFHAM #include<cstdio> #include<cstring> #include<iostream> using namespace std; #define N 100001 int a[N],b[N]; int sum[N],wh[N][2]; int num1[N],num2[N]; void read(int &x) { x=0; char c=getc

CF&amp;&amp;CC百套计划2 CodeChef December Challenge 2017 Total Diamonds

https://www.codechef.com/DEC17/problems/VK18 #include<cstdio> #include<iostream> #include<algorithm> using namespace std; #define N 1000001 long long sum[N*2],dp[N]; int num[11]; void read(int &x) { x=0; char c=getchar(); while(!isdi

CF&amp;&amp;CC百套计划2 CodeChef December Challenge 2017 Penalty Shoot-out

https://www.codechef.com/DEC17/problems/CPLAY #include<cstdio> #include<algorithm> using namespace std; char s[21]; int main() { int sumA,sumB; while(scanf("%s",s+1)!=EOF) { sumA=sumB=0; int i; for(i=1;i<=10;++i) { if(i&1) { i

cf之路,1,Codeforces Round #345 (Div. 2)

 cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....       其实这个应该是昨天就写完的,不过没时间了,就留到了今天.. 地址:http://codeforces.com/contest/651/problem/A A. Joysticks time limit per test 1 second memory limit per test 256

【打CF,学算法——一星级】Codeforces Round #313 (Div. 2) A. Currency System in Geraldion

[CF简单介绍] 提交链接:http://codeforces.com/contest/560/problem/A 题面: A. Currency System in Geraldion time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output A magic island Geraldion, where Gerald lives,

【打CF,学算法——二星级】Codeforces Round #313 (Div. 2) B. Gerald is into Art(水题)

[CF简单介绍] 提交链接:http://codeforces.com/contest/560/problem/B 题面: B. Gerald is into Art time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Gerald bought two very rare paintings at the Sotheby's a

小蒟蒻初次CF滚粗+爆炸记 (Codeforces Round #466 Div.2)

比赛链接:http://codeforces.com/blog/entry/57981 小蒟蒻今天初次在ZCDHJ张大佬的带领下,打了一场CF (张大佬cnblogs链接:https://www.cnblogs.com/ZCDHJ)' 英文完全看不懂,后面几题直接放弃,各位dalao请见谅 T1: 题目链接:http://codeforces.com/contest/940/problem/A 题目大意: 给你一个n个数的集合,要求你删掉若干数,其中最大的差不应该超过d,求最小删除量. (小蒟蒻