zoukankan      html  css  js  c++  java
  • CodeForces 351A Jeff and Rounding

    题意:给你一个2×n长的序列,进行n次操作,每次操作是选取两个从未选过的数,一个取上整,一个取下整,问你最后能得到最接近原来和的序列是多少。

    解题思路:先将所有小数和统计出来,然后再枚举向下取整的个数即可 ,利用的原则是  x + (1-x) = 1; 

    解题代码:

     1 // File Name: 351a.cpg
     2 // Author: darkdream
     3 // Created Time: 2015年03月08日 星期日 12时21分23秒
     4 
     5 #include<vector>
     6 #include<list>
     7 #include<map>
     8 #include<set>
     9 #include<deque>
    10 #include<stack>
    11 #include<bitset>
    12 #include<algorithm>
    13 #include<functional>
    14 #include<numeric>
    15 #include<utility>
    16 #include<sstream>
    17 #include<iostream>
    18 #include<iomanip>
    19 #include<cstdio>
    20 #include<cmath>
    21 #include<cstdlib>
    22 #include<cstring>
    23 #include<ctime>
    24 #define LL long long
    25 
    26 using namespace std;
    27 int a[5000];
    28 const double eps = 1e-8;
    29 int main(){
    30    int n ; 
    31    scanf("%d",&n);
    32    double sum = 0 ; 
    33    int n0 = 0 ; 
    34    for(int i = 1;i <= 2*n;i ++)
    35    {
    36       double tmp;
    37       scanf("%lf",&tmp);
    38       int x = (tmp*1000+eps);
    39       a[i] = x % 1000;
    40       if(a[i] == 0 )
    41           n0 ++ ; 
    42       sum += a[i]*1.0/1000;
    43    }
    44    double  ans = 1e9 ;
    45  //  if(n == 32)
    46    //printf("%f %d %d
    ",ans,min(2*n-n0,n),n0);
    47    for(int i = max(0,n-n0);i <= min(2*n-n0,n) ;i ++)
    48        ans = min(ans,fabs(sum-i));
    49    printf("%.3f
    ",ans); 
    50 return 0;
    51 }
    View Code
    没有梦想,何谈远方
  • 相关阅读:
    Appium安装教程
    方法(method)和函数(function)有什么区别?
    FTP两种工作模式:主动模式(Active FTP)和被动模式介绍
    python socket编程介绍
    面向对象基础篇
    python fishc.homework2
    python遇到的问题汇总
    我对 python 面向对象的理解
    深入理解JVM(五)JVM优化策略
    深入理解JVM(四)JVM性能监控与故障处理工具
  • 原文地址:https://www.cnblogs.com/zyue/p/4322306.html
Copyright © 2011-2022 走看看