Codeforces Round #204 (Div. 2) C. Jeff and Rounding——数学规律
给予N*2个数字,改变其中的N个向上进位,N个向下进位,使最后得到得数与原来数的差的绝对值最小
考虑小数点后面的数字,如果这些数都非零,则就是 abs(原数小数部分相加-1*n), 多一个0 则 min( abs(原数小数部分相加-1*n) ,abs(原数小数部分相加-1*(n-1)) )以此类推
#include<stdio.h>
int abs(int a){
if(a<)return -a;
else return a;
} int Min(int a,int b){
if(a<b)return a;
else return b;
} int main(){
int n,i;
while(scanf("%d",&n)!=EOF){
int n2=n*;
int ret=,temp,all=,k=;
for(i=;i<=n2;i++){
scanf("%*d.%d",&temp);
all+=temp;
if(temp==)k++;
}
for(i=;i<=k;i++){
ret=Min(ret,abs(all-(*n-*i)));
}
printf("%d.%03d\n",ret/,ret%);
}
return ;
}
Codeforces Round #204 (Div. 2) C. Jeff and Rounding——数学规律的更多相关文章
- 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 ...
- 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百套计划3 Codeforces Round #204 (Div. 1) D. Jeff and Removing Periods
http://codeforces.com/problemset/problem/351/D 题意: n个数的一个序列,m个操作 给出操作区间[l,r], 首先可以删除下标为等差数列且数值相等的一些数 ...
- Codeforces Round #204 (Div. 2)->D. Jeff and Furik
D. Jeff and Furik time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- Codeforces Round #204 (Div. 2)->B. Jeff and Periods
B. Jeff and Periods time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #204 (Div. 2) A.Jeff and Digits
因为数字只含有5或0,如果要被90整除的话必须含有0,否则输出-1 如果含有0的话,就只需考虑组合的数字之和是9的倍数,只需要看最大的5的个数能否被9整数 #include <iostream& ...
- Codeforces Round #368 (Div. 2) C. Pythagorean Triples(数学)
Pythagorean Triples 题目链接: http://codeforces.com/contest/707/problem/C Description Katya studies in a ...
随机推荐
- Python写入CSV文件的问题
这篇文章主要是前几天我处理数据时遇到的三个问题: Python写入的csv的问题 Python2与Python3处理写入写入空行不同的处理方式 Python与Python3的编码问题 其实上面第3个问 ...
- LeetCode OJ:Burst Balloons(击破气球)
Given n balloons, indexed from 0 to n-1. Each balloon is painted with a number on it represented by ...
- 【实用工具】google访问不了比较好的解决办法
一.直接添加ip,74.125.128.(31~167)都可以,不过不稳定 二.不使用.hk的后缀名,使用.tw,co.jp等均可(同IE用户) 三.下载这个脚本,进行安装(右上角点击“install ...
- progressbar进度条组件
Progressbar 进度条组件 通过$.fn.progressbar.fn.defaults重写默认的defaults进度条(progressbar)提供了一种显示长时间操作进度的反馈.进度可被更 ...
- 简易安装ubuntu- -(虚拟机实现)
第一步:获取资源 安装vmware 百度上搜索vmware虚拟机,直接在百度上下载下来. 按平时安装东西步骤差不多 最后使用的时候有出现适用30天或者永久使用需要序列号 序列号可以使用 5A02H-A ...
- 剑指offer--41.扑克牌顺子
没有判断数组长度,导致{1,3,2,5,4}输出结果是false是什么鬼??? ------------------------------------------------------------ ...
- 20165202 2017-2018-2 《Java程序设计》第6周学习总结
教材学习内容总结 Ch8 String类: 程序可以直接使用,String类不能有子类 - 构造String对象 使用String类声明并创建对象 String s = new String(&quo ...
- mssqlserver SQL注释快捷键
注释快捷键 选中语句(快捷键:光标定位到需要注释块的最顶行,按住shift+home选中行,放开再按下shift+向下键,选中块) 按住Ctrl然后依次按K,C取消注释快捷键 选中语句 按住Ctrl然 ...
- 安装Spring报错An error occurred while collecting items to be installed
原因主要是eclipse和spring版本之间的匹配问题. An error occurred while collecting items to be installed session conte ...
- React-Native基础_5.列表视图ListView 网络数据展示
//获取网络数据 并用列表展示 豆瓣Top250 api /** * Sample React Native App * https://github.com/facebook/react-nativ ...