codeforces A. Jeff and Rounding (数学公式+贪心)
题目链接:http://codeforces.com/contest/351/problem/A
算法思路:2n个整数,一半向上取整,一半向下。我们设2n个整数的小数部分和为sum.

ans = |A - B|;
sum = A +(n-b)-B;
所以ans = |sum - (n-b) |; 只有b未知,只需要枚举一下b就得到答案。
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<iostream>
#include<cmath>
using namespace std; const int maxn = ;
const double eps = 1e-;
int dcmp(double x){
if(fabs(x) < eps) return ;
else return x < ? - : ;
}
int main()
{
//freopen("E:\\acm\\input.txt","r",stdin); double sum = ;
int n;
int num = ;
cin>>n;
for(int i=;i<=*n;i++)
{
double a;
scanf("%lf",&a);
if(dcmp(floor(a)-a) == ) num++;
sum += a - floor(a);
}
double ans = 1e10;
for(int i=max(num-n,);i<=min(n,num);i++)
{
ans = min(ans,fabs(sum-(n-i)));
}
printf("%.3lf\n",ans);
}
codeforces A. Jeff and Rounding (数学公式+贪心)的更多相关文章
- CodeForces 352C. Jeff and Rounding(贪心)
C. Jeff and Rounding time limit per test: 1 second memory limit per test: 256 megabytes input: stan ...
- CodeForces 352C Jeff and Rounding
题意 有一个含有\(2n(n \leqslant2000)\)个实数的数列,取出\(n\)个向上取整,另\(n\)个向下取整.问取整后数列的和与原数列的和的差的绝对值. 就是说,令\(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 437C The Child and Toy(贪心)
题目连接:Codeforces 437C The Child and Toy 贪心,每条绳子都是须要割断的,那就先割断最大值相应的那部分周围的绳子. #include <iostream> ...
- Codeforces Round #546 (Div. 2) D 贪心 + 思维
https://codeforces.com/contest/1136/problem/D 贪心 + 思维 题意 你面前有一个队列,加上你有n个人(n<=3e5),有m(m<=个交换法则, ...
- Codeforces Round #204 (Div. 2) C. Jeff and Rounding——数学规律
给予N*2个数字,改变其中的N个向上进位,N个向下进位,使最后得到得数与原来数的差的绝对值最小 考虑小数点后面的数字,如果这些数都非零,则就是 abs(原数小数部分相加-1*n), 多一个0 则 m ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- Codeforces Educational Codeforces Round 3 C. Load Balancing 贪心
C. Load Balancing 题目连接: http://www.codeforces.com/contest/609/problem/C Description In the school co ...
随机推荐
- ios动力特效,最重要的一点 属性保持(写了动力特效但是没效果的原因就在这里)
@property (nonatomic, strong) UIDynamicItemBehavior *square1PropertiesBehavior; @property (nonatomic ...
- OC - 14.NSOperation与NSOperationQueue
简介 通过NSOperation与NSOperationQueue的组合也能实现多线程 通常将任务封装成NSOperation对象,并将对象添加到NSOperationQueue中实现 NSOpera ...
- The version of CocoaPods used to generate the lockfile (*) is higher than the version of the current executable (*). Incompatibility issues may arise.
解决方法: sudo gem update cocoapod
- CSS 分组 和 嵌套 选择器
Grouping Selectors 在样式表中有很多具有相同样式的元素. h1{color:green;}h2{color:green;}p{color:green;} 为了尽量减少代码,你可以使用 ...
- 使用bind()扩充作用域
window.color = "blue"; var o = {color :"red"}; function sayColor(){ alert(this.c ...
- JAVA学习-基础知识
1.Java程序都是以类的形式编写的.2.存放源代码的文件叫源文件.(电脑不能直接看懂的,需要编译一下,电脑才能懂)如何编译源文件?用javac命令输入"javac 123.Java&quo ...
- 《Velocity java开发指南》中文版(上)转载
文章引自:http://sakyone.iteye.com/blog/524289 1.开始入门 Velocity是一基于java语言的模板引擎,使用这个简单.功能强大的开发工具,可以很容易的将数据对 ...
- 【elasticsearch】(1)centos7 使用yum安装elasticsearch 2.X
前言 elasticsearch(下面称为ES)是一个基于Lucene的搜索服务器(By 百度百科:查看).所以他需要java的环境即jdk,这里提供懒人一键安装方式 # yum install ja ...
- 关于C#的那点事........
起源 C#(读做C-sharp)编程语言是由微软公司的Anders Hejlsberg和 Scott Willamette领导的开发小组专门为.NET平台设计的语言,它可以使程序员移植到.NET上.这 ...
- scrollView and tableView
As we all know, tableView is the subclass of scrollView, tableView has every properties that scroll ...