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. rsyslog 日志服务器接收日志权限问题

    rsyslog 权限: 默认 [root@dr-mysql01 zjzc_log]# ls -ltr zj-frontend0*-access*27 -rw------- 1 root root 32 ...

  2. BZOJ2659: [Beijing wc2012]算不出的算式

    2659: [Beijing wc2012]算不出的算式 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 668  Solved: 366[Submit] ...

  3. HDU_2033——时间加法

    Problem Description HDOJ上面已经有10来道A+B的题目了,相信这些题目曾经是大家的最爱,希望今天的这个A+B能给大家带来好运,也希望这个题目能唤起大家对ACM曾经的热爱.这个题 ...

  4. zabbix discovery

    preface(见面礼): 仅扫tcp端口: netstat -tnlp|egrep -i "$1"

  5. javascript中子类如何继承父类

    参考阮一峰的文章:http://javascript.ruanyifeng.com/oop/inheritance.html#toc4 function Shape() { this.x = 0; t ...

  6. JavaScript 自动分页插件 datatables

    DataTables Table plug-in for jQuery https://www.datatables.net/

  7. #python-dateutil下载地址

    http://www.lfd.uci.edu/~gohlke/pythonlibs/#python-dateutil

  8. [转]Android-网络通信框架Volley使用详解

    1 Volley发送get请求: public void getJson() { String url = "http://"+host+":8080/web/json. ...

  9. 300元差价选谁好 魅蓝note对比魅蓝手机

    http://mobile.pconline.com.cn/608/6089437.html [PConline 对比评测]999元的魅蓝note和699元的魅蓝手机先后被发布,代表着魅族中低端手机已 ...

  10. [转载]ios app 发布遇到的问题uinewsstandapp=true

    原文地址:ios app 发布遇到的问题uinewsstandapp=true 作者:Capacity To include newsstand features, the info.plist mu ...