cf C. Jeff and Rounding
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的更多相关文章
- CF 351A - Jeff and Rounding DP
http://codeforces.com/problemset/problem/351/C 题意:有2*n个浮点数a1,a2,a3...a2*n,把他们分成n队,对于每对<A,B>,对A ...
- CF&&CC百套计划3 Codeforces Round #204 (Div. 1) A. Jeff and Rounding
http://codeforces.com/problemset/problem/351/A 题意: 2*n个数,选n个数上取整,n个数下取整 最小化 abs(取整之后数的和-原来数的和) 先使所有的 ...
- 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 ...
- CodeForces 352C. Jeff and Rounding(贪心)
C. Jeff and Rounding time limit per test: 1 second memory limit per test: 256 megabytes input: stan ...
- CF351A Jeff and Rounding 思维
Jeff got 2n real numbers a1, a2, ..., a2n as a birthday present. The boy hates non-integer numbers, ...
- codeforces A. Jeff and Rounding (数学公式+贪心)
题目链接:http://codeforces.com/contest/351/problem/A 算法思路:2n个整数,一半向上取整,一半向下.我们设2n个整数的小数部分和为sum. ans = |A ...
- [CF 351B]Jeff and Furik[归并排序求逆序数]
题意: 两人游戏, J先走. 给出一个1~n的排列, J选择一对相邻数[题意!!~囧], 交换. F接着走, 扔一硬币, 若正面朝上, 随机选择一对降序排列的相邻数, 交换. 若反面朝上, 随机选择一 ...
- cf B. Jeff and Periods
http://codeforces.com/contest/352/problem/B #include <cstdio> #include <cstring> #includ ...
- cf A. Jeff and Digits
http://codeforces.com/contest/352/problem/A #include <cstdio> #include <cstring> #includ ...
随机推荐
- row cache lock
SQL> col name format a30 SQL> select * from (select SAMPLE_TIME, SESSION_ID, NAME, P1, P2, P3, ...
- css属性之transition
浏览器支持 Internet Explorer 10.Firefox.Opera 和 Chrome 支持 transition 属性. Safari 支持替代的 -webkit-transition ...
- cf509C Sums of Digits
C. Sums of Digits time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- RSA算法python实现
RSA算法是一种非对称加密算法,是现在广泛使用的公钥加密算法,主要应用是加密信息和数字签名.详情请看维基:http://zh.wikipedia.org/wiki/RSA%E5%8A%A0%E5%AF ...
- libvirt-adabddad
kvm i686 libvirtError: internal error cannot load AppArmor profile 'libvirt-adabddad-35ba-b9ca-e250 ...
- java中paint repaint update 之间的关系
最近总结了一下java中的paint,repaint和updata三者之间的关系,首先咱们都知道用paint方法来绘图,用repaint重绘,用update来写双缓冲.但是他们之间是怎么来调用的呢,咱 ...
- 数据对接—kettle使用之二
这一篇开始进入kettle的一些常用插件的使用介绍,通过实例介绍不同插件的功能.这一篇说(Data Grid和文本文件输出)的使用. 文本文件输出介绍(可以略过,一般用不着): 1.Run ...
- windows 7 SDK和DDK下载地址
查个小资料,得到地址,顺便记录一下. Windows Driver Kit Version 7.1.0 http://www.microsoft.com/downloads/details.aspx? ...
- codeforces Arrival of the General 题解
A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command o ...
- C# 泛型多种参数类型与多重约束 示例
C# 泛型多种参数类型与多重约束 示例 interface IMyInterface { } class Dictionary<TKey, TVal> where TKey : IComp ...