zoukankan      html  css  js  c++  java
  • cf C. Jeff and Rounding

    http://codeforces.com/contest/352/problem/C

    题意:给予N*2个数字,改变其中的N个向上进位,N个向下进位,使最后得到得数与原来数的差的绝对值最小

    对每一个浮点数都取其下限,得到的差值就是所有浮点数小数部分的和;然后则需要从2*n个数里面选出n个数取其上限,即下限加1,而如果这个数是个整数,那么不需要加1;因此统计加1个数的上限和下限即可;然后选择min abs(小数部分的和-加1的个数);

     1 #include <cstdio>
     2 #include <cstring>
     3 #include <cmath>
     4 #include <algorithm>
     5 using namespace std;
     6 const double eps=1e-20;
     7 int n;
     8 double a[10010];
     9 
    10 double min1(double a,double b)
    11 {
    12     if(a>b) return b;
    13     else return a;
    14 }
    15 
    16 int main()
    17 {
    18     scanf("%d",&n);
    19     int t1=0,t2=0;
    20     double sum=0;
    21     int s,t;
    22     for(int i=0; i<2*n; i++)
    23     {
    24         scanf("%lf",&a[i]);
    25         double m=a[i]-(int)a[i];
    26         sum+=m;
    27         if(m>eps) t1++;
    28         else t2++;
    29     }
    30     double ans=1e11;
    31     if(t1<=t2)
    32     {
    33         s=0; t=t1;
    34     }
    35     else
    36     {
    37         s=n-t2; t=n;
    38     }
    39     for(int i=s; i<=t; i++)
    40     {
    41         ans=min1(ans,fabs(sum-i));
    42     }
    43     printf("%.3lf
    ",ans);
    44     return 0;
    45 }
    View Code
  • 相关阅读:
    wpf Behavior
    wpf Trigger
    语法糖
    Lambda 表达式
    wpf 3D动画
    IEnumerable接口学习
    Delegates, Events, and Anonymous Methods 委托、事件与匿名方法
    wpf 平滑效果随记
    软件工程第一篇博客
    记考研高数第一课
  • 原文地址:https://www.cnblogs.com/fanminghui/p/3930390.html
Copyright © 2011-2022 走看看