http://codeforces.com/contest/352/problem/C

题意:给予N*2个数字,改变其中的N个向上进位,N个向下进位,使最后得到得数与原来数的差的绝对值最小

对每一个浮点数都取其下限,得到的差值就是所有浮点数小数部分的和;然后则需要从2*n个数里面选出n个数取其上限,即下限加1,而如果这个数是个整数,那么不需要加1;因此统计加1个数的上限和下限即可;然后选择min abs(小数部分的和-加1的个数);

 #include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
const double eps=1e-;
int n;
double a[]; double min1(double a,double b)
{
if(a>b) return b;
else return a;
} int main()
{
scanf("%d",&n);
int t1=,t2=;
double sum=;
int s,t;
for(int i=; i<*n; i++)
{
scanf("%lf",&a[i]);
double m=a[i]-(int)a[i];
sum+=m;
if(m>eps) t1++;
else t2++;
}
double ans=1e11;
if(t1<=t2)
{
s=; t=t1;
}
else
{
s=n-t2; t=n;
}
for(int i=s; i<=t; i++)
{
ans=min1(ans,fabs(sum-i));
}
printf("%.3lf\n",ans);
return ;
}

cf C. Jeff and Rounding的更多相关文章

  1. CF 351A - Jeff and Rounding DP

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

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

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

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

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

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

  5. CF351A Jeff and Rounding 思维

    Jeff got 2n real numbers a1, a2, ..., a2n as a birthday present. The boy hates non-integer numbers, ...

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

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

  7. [CF 351B]Jeff and Furik[归并排序求逆序数]

    题意: 两人游戏, J先走. 给出一个1~n的排列, J选择一对相邻数[题意!!~囧], 交换. F接着走, 扔一硬币, 若正面朝上, 随机选择一对降序排列的相邻数, 交换. 若反面朝上, 随机选择一 ...

  8. cf B. Jeff and Periods

    http://codeforces.com/contest/352/problem/B #include <cstdio> #include <cstring> #includ ...

  9. cf A. Jeff and Digits

    http://codeforces.com/contest/352/problem/A #include <cstdio> #include <cstring> #includ ...

随机推荐

  1. cxgrid按条件计算合计值 TcxTreeList计算合计值

    在Footer的第一列显示[合计:] 加一个Summary项,Column设为Grid的第一列,Kind设为skNone 在该Summary项的OnGetText事件中,输入: procedure T ...

  2. 探讨c#中的unchecked是什么意思,起什么作用?

    Checked与Unchecked     对于因为整数类型参与算术操作和类型转换时产生的“溢出异常”——System.OverflowException,在某些算法来讲不算真正的“异常”,相反这种溢 ...

  3. 【转】C++动态创建二维数组,二维数组指针

    原作者博客:蒋国宝的IT技术博客 今天完成一道题目需要自己用指针创建一个二维的数组,不得不承认指针的确是恶心. int **result; ; ; result = new int*[row]; ; ...

  4. redis 网络流程图 <一>

    本来一直想好好读下redis源码.可是每次读了一点就不读了.  主要是没坚持每天都读. 隔几天看.就忘记前面的流程.就越来越不想看了.  很是蛋疼.这个还是要坚持读完的.打算这段时间都源码的时候.都大 ...

  5. JVM内存堆布局图解分析

    JAVA能够实现跨平台的一个根本原因,是定义了class文件的格式标准,凡是实现该标准的JVM都能够加载并解释该class文件,据此也可以知道,为啥Java语言的执行速度比C/C++语言执行的速度要慢 ...

  6. Java枚举7常见种用法

    DK1.5引入了新的类型——枚举.在Java中它虽然算个“小”功能,却给我的开发带来了“大”方便. 方法/步骤 用法一:常量 在JDK1.5之前,我们定义常量都是:publicstaticfianl. ...

  7. 简单的HDFS思维导图

  8. Hive 7、Hive 的内表、外表、分区(22)

    Hive 7.Hive 的内表.外表.分区   1.Hive的内表 Hive 的内表,就是正常创建的表,在 http://www.cnblogs.com/raphael5200/p/5208437.h ...

  9. solr安装

    Windows solr(tomcat) 1.1. 安装步骤 1.1.1准备工作 1. 服务器:apache-tomcat-7.0.40压缩版,http://localhost:8080/安装是否成功 ...

  10. pods 这两篇就够了

    http://www.cnblogs.com/gongyuhonglou/p/5801681.html http://blog.csdn.net/iunion/article/details/1701 ...