CodeForces 351A Jeff and Rounding
来源:互联网 发布:js获得tr中第一个td 编辑:程序博客网 时间:2024/05/21 06:29
题目大意:给你2*n个数,然后你执行n个操作,每个操作选定两个数,一个数变成不大于它的整数,另一个是不小于它的整数,然后要你求出
n个操作后,原序列和操作后的差的绝对值的最小值。
思路:如果一个数的小数部分为 a,那么往下就是a,网上就是 1-a,然后要选n个数往下,n个数往上,a-(1-b) = a+b-1,而所有的a和是确定的,所以就是
-几个1的问题,使这个绝对值最小。这 1 也不能随便-,因为如果正好是整数,就不是 1-a,而是直接是 0,所以那些 a > 0的数才有可能往上增加,所以就是统计
一下就行了,然后取最小。
CF的A题啊,就是想不出来怎么搞,挫。。= =
n个操作后,原序列和操作后的差的绝对值的最小值。
思路:如果一个数的小数部分为 a,那么往下就是a,网上就是 1-a,然后要选n个数往下,n个数往上,a-(1-b) = a+b-1,而所有的a和是确定的,所以就是
-几个1的问题,使这个绝对值最小。这 1 也不能随便-,因为如果正好是整数,就不是 1-a,而是直接是 0,所以那些 a > 0的数才有可能往上增加,所以就是统计
一下就行了,然后取最小。
CF的A题啊,就是想不出来怎么搞,挫。。= =
代码如下:
#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>using namespace std;const int MAXN = 2222<<1;double a[MAXN];int main(){ int n; while(~scanf("%d",&n)) { double sum = 0; int z = 0; for(int i = 0;i < (n<<1);i++) { scanf("%lf",&a[i]); double tmp = a[i]-floor(a[i]); if(tmp > 0) z++; sum += tmp; } double ans = 1e9; for(int i = max(0,z-n);i <= min(z,n);i++) { ans = min(ans,fabs(sum-i)); } printf("%.3f\n",ans); } return 0;}
- CodeForces 351A Jeff and Rounding
- 351A Jeff and Rounding
- codeforces 351A A. Jeff and Rounding(智商题+枚举)
- codeforces 351A A. Jeff and Rounding(★)
- codeforces 351A Jeff and Rounding(区间枚举)
- 【CodeForces 351A】Jeff and Rounding(思维)
- [CF 351A]Jeff and Rounding[greedy]
- codeforces 204 Jeff and Rounding
- Codeforces Round #204 (Div. 1) A. Jeff and Rounding
- Codeforces 352C Jeff and Rounding【dp】
- A. Jeff and Rounding----思维题
- Jeff and Rounding
- Codeforces Round #204 (Div. 2) C. Jeff and Rounding
- Codeforces Round #204 (Div. 2) C Jeff and Rounding
- CodeForces 352A Jeff and Digits
- CodeForces-352A Jeff and Digits
- codeforces 352C Jeff and Rounding 很有趣的一道题
- CodeForce 204 Div2. C Jeff And Rounding
- [OpenGL ES 04]3D变换实践篇:平移,旋转,缩放
- Bootstrap
- [OpenGL ES 05]相对空间变换及颜色
- [OpenGL ES 06]使用VBO:顶点缓存
- 如何成为一个C++高级程序员(收藏)
- CodeForces 351A Jeff and Rounding
- Codeforces Round #211 (Div. 2) D题Renting Bikes
- [OpenGL ES 07]光照原理
- Virtual Box下配置Host-Only联网方式详解
- Tabhost的简单使用
- [OpenGL ES 08]Per-Pixel Light及卡通效果
- C语言 - 移动的小方块
- 数据结构之图用邻接矩阵实现赋值有向图
- 程序中如何打印日志?(三) VC++6.0和BCB6.0都不支持变长参数的宏