博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
codeforces A. Jeff and Rounding (数学公式+贪心)
阅读量:4561 次
发布时间:2019-06-08

本文共 920 字,大约阅读时间需要 3 分钟。

 

算法思路:2n个整数,一半向上取整,一半向下。我们设2n个整数的小数部分和为sum.

ans = |A - B|;

sum = A +(n-b)-B;

所以ans = |sum - (n-b) |; 只有b未知,只需要枚举一下b就得到答案。

#include
#include
#include
#include
#include
using namespace std;const int maxn = 2005;const double eps = 1e-12;int dcmp(double x){ if(fabs(x) < eps) return 0; else return x < 0 ? -1 : 1;}int main(){ //freopen("E:\\acm\\input.txt","r",stdin); double sum = 0; int n; int num = 0; cin>>n; for(int i=1;i<=2*n;i++) { double a; scanf("%lf",&a); if(dcmp(floor(a)-a) == 0) num++; sum += a - floor(a); } double ans = 1e10; for(int i=max(num-n,0);i<=min(n,num);i++) { ans = min(ans,fabs(sum-(n-i))); } printf("%.3lf\n",ans);}
View Code

 

转载于:https://www.cnblogs.com/acmdeweilai/p/3352725.html

你可能感兴趣的文章
python code(1)
查看>>
利用反射生成JDK动态代理
查看>>
无奈的28句 思念的28句 痛心的28句 回忆的28句
查看>>
Django-建立网页
查看>>
iptables转发备忘
查看>>
【清华集训2016】数据交互
查看>>
备战省赛组队训练赛第七场(UPC)
查看>>
SQL puzzles and answers读书笔记——预算执行问题
查看>>
腾讯笔试
查看>>
Net基础恶补
查看>>
oracle不同用户间访问表不添加用户名(模式)前缀
查看>>
如何在windows xp professional安装iis的解决方法
查看>>
抽象类和接口
查看>>
使用ASP.NET Atlas AutoComplete Behavior或AutoComplete Extender实现自动完成功能(下)
查看>>
golang 常见疑惑总结
查看>>
aop动态代理 事务 threadlocal
查看>>
asp.net web api 2 对跨域资源共享的支持
查看>>
codeforces 510c (拓扑排序)
查看>>
优化算法索引
查看>>
【Linux】more命令
查看>>