CF&&CC百套计划3 Codeforces Round #204 (Div. 1) A. Jeff and Rounding
http://codeforces.com/problemset/problem/351/A
题意:
2*n个数,选n个数上取整,n个数下取整
最小化 abs(取整之后数的和-原来数的和)
先使所有的数都下取整,累积更改的sum
那么选1个小数上取整,就会使sum-1
整数上下取整不会产生影响
所以有1个整数就可以使上取整的小数少1个
所以ans=min(abs(i-sum)) i∈[n-整数个数,n]
#include<cmath>
#include<cstdio>
#include<algorithm> using namespace std; const double eps=1e-; int main()
{
int n;
scanf("%d",&n);
int m=n<<;
int cnt=;
double x;
double sum=;
for(int i=;i<=m;++i)
{
scanf("%lf",&x);
sum+=x-floor(x);
if(x-floor(x)<eps) cnt++;
}
double ans=1e9;
for(int i=n;i>=n-cnt;--i) ans=min(ans,abs(i-sum));
printf("%.3lf",ans);
}
1 second
256 megabytes
standard input
standard output
Jeff got 2n real numbers a1, a2, ..., a2n as a birthday present. The boy hates non-integer numbers, so he decided to slightly "adjust" the numbers he's got. Namely, Jeff consecutively executes n operations, each of them goes as follows:
- choose indexes i and j (i ≠ j) that haven't been chosen yet;
- round element ai to the nearest integer that isn't more than ai (assign to ai: ⌊ ai ⌋);
- round element aj to the nearest integer that isn't less than aj (assign to aj: ⌈ aj ⌉).
Nevertheless, Jeff doesn't want to hurt the feelings of the person who gave him the sequence. That's why the boy wants to perform the operations so as to make the absolute value of the difference between the sum of elements before performing the operations and the sum of elements after performing the operations as small as possible. Help Jeff find the minimum absolute value of the difference.
The first line contains integer n (1 ≤ n ≤ 2000). The next line contains 2n real numbers a1, a2, ..., a2n (0 ≤ ai ≤ 10000), given with exactly three digits after the decimal point. The numbers are separated by spaces.
In a single line print a single real number — the required difference with exactly three digits after the decimal point.
3
0.000 0.500 0.750 1.000 2.000 3.000
0.250
3
4469.000 6526.000 4864.000 9356.383 7490.000 995.896
0.279
In the first test case you need to perform the operations as follows: (i = 1, j = 4), (i = 2, j = 3), (i = 5, j = 6). In this case, the difference will equal |(0 + 0.5 + 0.75 + 1 + 2 + 3) - (0 + 0 + 1 + 1 + 2 + 3)| = 0.25.
CF&&CC百套计划3 Codeforces Round #204 (Div. 1) A. Jeff and Rounding的更多相关文章
- CF&&CC百套计划3 Codeforces Round #204 (Div. 1) D. Jeff and Removing Periods
http://codeforces.com/problemset/problem/351/D 题意: n个数的一个序列,m个操作 给出操作区间[l,r], 首先可以删除下标为等差数列且数值相等的一些数 ...
- CF&&CC百套计划3 Codeforces Round #204 (Div. 1) E. Jeff and Permutation
http://codeforces.com/contest/351/problem/E 题意: 给出一些数,可以改变任意数的正负,使序列的逆序对数量最少 因为可以任意加负号,所以可以先把所有数看作正数 ...
- CF&&CC百套计划3 Codeforces Round #204 (Div. 1) B. Jeff and Furik
http://codeforces.com/contest/351/problem/B 题意: 给出一个n的排列 第一个人任选两个相邻数交换位置 第二个人有一半的概率交换相邻的第一个数>第二个数 ...
- CF&&CC百套计划4 Codeforces Round #276 (Div. 1) A. Bits
http://codeforces.com/contest/484/problem/A 题意: 询问[a,b]中二进制位1最多且最小的数 贪心,假设开始每一位都是1 从高位i开始枚举, 如果当前数&g ...
- CF&&CC百套计划4 Codeforces Round #276 (Div. 1) E. Sign on Fence
http://codeforces.com/contest/484/problem/E 题意: 给出n个数,查询最大的在区间[l,r]内,长为w的子区间的最小值 第i棵线段树表示>=i的数 维护 ...
- CF&&CC百套计划1 Codeforces Round #449 C. Willem, Chtholly and Seniorious (Old Driver Tree)
http://codeforces.com/problemset/problem/896/C 题意: 对于一个随机序列,执行以下操作: 区间赋值 区间加 区间求第k小 区间求k次幂的和 对于随机序列, ...
- CF&&CC百套计划1 Codeforces Round #449 B. Ithea Plays With Chtholly
http://codeforces.com/contest/896/problem/B 题意: 交互题 n张卡片填m个1到c之间的数,1<=n*ceil(c/2)<=m 最后填出一个单调非 ...
- CF&&CC百套计划1 Codeforces Round #449 A. Nephren gives a riddle
http://codeforces.com/contest/896/problem/A 第i个字符串嵌套第i-1个字符串 求第n个字符串的第k个字母 dfs #include<map> # ...
- 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 ...
随机推荐
- 配置JDBC
在数据库和MyEclipse都安装好的情况下进行配置: 1.将JDBC(sqljdbc_4.0.2206.100_chs.exe)文件解压到C盘program files下面(也可以将解压后的文件Mi ...
- 剑指offer:旋转数组的最小数字
题目描述: 把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转. 输入一个非减排序的数组的一个旋转,输出旋转数组的最小元素. 例如数组{3,4,5,1,2}为{1,2,3,4,5}的一个 ...
- [转帖]AMD、英特尔为何争相走向胶水多核处理器?真相在此
AMD.英特尔为何争相走向胶水多核处理器?真相在此 胶水多核到底好不好?这个事不是简单一句话能说明的,今天的超能课堂里我们就来聊聊MCM胶水多核技术的过去及未来. 作者:孟宪瑞来源:超能网|2018- ...
- Navicat for MySQL和Navicat Premium之间的区别
首先两款软件都可以用来管理数据库链接MySQL和MariaDB 相对于新手或者前端工程师使用Navicat for MySQL就够了,功能相对于Navicat Premium比较少Navicat fo ...
- Python高级特性:Python迭代、生成器、列表生成式
迭代 给定一个list或tuple,我们可以通过for循环来遍历这个list或tuple,这种遍历称为迭代(Iteration). 在java和C语言中,迭代是通过循环list的下标来完成的,Pyth ...
- BZOJ 2745: [HEOI2012]Bridge
2745: [HEOI2012]Bridge Time Limit: 30 Sec Memory Limit: 128 MBSubmit: 199 Solved: 90[Submit][Statu ...
- uoj318 [NOI2017]蔬菜 【贪心 + 堆 + 并查集】
题目链接 uoj 题解 以前看别人博客,在考场上用费用流做,一直以为这题是毒瘤网络流题 没想到竟然是贪心模拟题... 如果只有一个蔬菜呢?这就是一个经典的普及难度的贪心,正着推面临优先选择的困难,而逆 ...
- Corosync+Pacemaker+crmsh构建Web高可用集群
一.概述: 1.1 AIS和OpenAIS简介 AIS应用接口规范,是用来定义应用程序接口(API)的开放性规范的集合,这些应用程序作为中间件为应用服务提供一种开放.高移植性的程序接口.是在实现高可用 ...
- Moonraker:1靶机入侵
0x01 前言 攻击Moonraker系统并且找出存在最大的威胁漏洞,通过最大威胁漏洞攻击目标靶机系统并进行提权获取系统中root目录下的flag信息. Moonraker: 1镜像下载地址: h ...
- linux内核分析(网课期末&地面课期中)
堆栈变化过程: Linux内核分析——计算机是如何工作的 计算机是如何工作的?(总结)——三个法宝 存储程序计算机工作模型,计算机系统最最基础性的逻辑结构: 函数调用堆栈,高级语言得以运行的基础,只有 ...