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 ...
随机推荐
- java remote debug
1. java -Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=8000 -jar test.jar 2.会出现Listening for ...
- QT QString转char*,char*转QString;简单明了,看代码。
//原始QStringQString qs = QString::fromLocal8Bit("我的");std::string strQs = qs.toStdString(); ...
- 由C到C++的学习 ----Essential C++
一.array[] 与 vector<int> vector1 1 array[] <- 此中要填写数组的大小,而且array[]自己是不知道自己的大小的 2.1 vector< ...
- 批量缩放PNG图片.
最近需要缩放N多图片, 找遍了互联网也没有找到方便使用的批量缩放工具.. 趁着周末写一个练手.. #include <iostream> #include <vector> # ...
- 搭建VPN服务器之PPTP
搭建VPN服务器之PPTP 1. 查看系统是否支持PPP 一般自己的系统支持,VPS需要验证. [root@oldboyedu ~]# cat /dev/ppp cat: /dev/ppp: No s ...
- [CSS]cursor鼠标样式
用css控制鼠标样式的语法如下: <span style="cursor:*">文本或其它页面元素</span> 把 * 换成如下15个效果的一种: ...
- 结合使用 Oracle Database 11g 和 Python
结合使用 Oracle Database 11g 和 Python 本教程介绍如何结合使用 Python 和 Oracle Database 11g. 所需时间 大约 1 个小时 概述 Python ...
- linux下date命令实现时间戳与日期的转换
1.查看指定时间的时间戳 查看当前时间 #date +%s 查看指定时间 #date -d 2008-01-01 +%s 1199116800 #date -d 20080101 ...
- CentOS 6.0 图文安装教程
CentOS 6.0下载地址:wget http://ftp.riken.jp/Linux/centos/6.0/isos/i386/CentOS-6.0-i386-bin-DVD.iso 下边就是安 ...
- Python学习笔记(一)Python安装及环境变量的配置
1.下载python安装包. 下载地址:https://www.python.org/ 2.配置环境变量 找到python的安装路径.C:\Python27;script的路径:C:\Python27 ...