zoukankan      html  css  js  c++  java
  • CodeForces 1186D Vus the Cossack and Numbers(构造)

    A - Vus the Cossack and Numbers

    题意:

    给你一些实数,可以向上取证也可以向下取整,要求取整之后序列的和为零

    思路:

    把能向下取整的数字全部向下取取整(已经是整数的数字是不能向下取整的),然后看总和比零小多少,再把一些数字改成向上取整的

     1 #include<cstdio>
     2 #include<string.h>
     3 #include<algorithm>
     4 #include<cmath>
     5 #include<iostream>
     6 #include<vector>
     7 #include<queue>
     8 #include<set>
     9 #include<map>
    10 #include<cctype>
    11 #define ios ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
    12 #define mem(a,x) memset(a,x,sizeof(a))
    13 #define lson rt<<1,l,mid
    14 #define rson rt<<1|1,mid + 1,r
    15 #define P pair<int,int>
    16 #define ull unsigned long long
    17 using namespace std;
    18 typedef long long ll;
    19 const int maxn = 1e6 + 10;
    20 const ll mod = 998244353;
    21 const int inf = 0x3f3f3f3f;
    22 const long long INF = 0x3f3f3f3f3f3f3f3f;
    23 const double eps = 1e-7;
    24 inline ll read()
    25 {
    26     ll X = 0, w = 0; char ch = 0;
    27     while (!isdigit(ch)) { w |= ch == '-'; ch = getchar(); }
    28     while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();
    29     return w ? -X : X;
    30 }
    31 
    32 double arr[maxn];
    33 int brr[maxn];
    34 int main()
    35 {
    36     int n;
    37     while (~scanf("%d", &n))
    38     {
    39         int sum = 0;
    40         for (int i = 1; i <= n; ++i)
    41         {
    42             scanf("%lf", &arr[i]);
    43             if (arr[i] < 0)
    44             {
    45                 brr[i] = (int)(arr[i] - 0.99999999);
    46             }
    47             else
    48             {
    49                 brr[i] = (int)arr[i];
    50             }
    51             sum += brr[i];
    52         }
    53         for (int i = 1; i <= n; ++i)
    54         {
    55             if (sum == 0) break;
    56             if (arr[i] - (int)arr[i] == 0) continue;
    57             if (arr[i] < 0) brr[i] = (int)arr[i], sum++;
    58             else
    59                 brr[i] = (int)(arr[i] + 0.99999999) , sum++;
    60         }
    61         for (int i = 1; i <= n; ++i)
    62         {
    63             cout << brr[i] << endl;
    64         }
    65     }
    66     return 0;
    67 }
    View Code
  • 相关阅读:
    伟大的微软,太智能了
    ASP.NET MVC中的统一化自定义异常处理
    去除无用的文件查找路径
    关于easyUI的一些js方法
    easyUI小技巧-纯干货
    easyui tree tabs
    ueditor初始化
    多图联动
    饼图tooltip
    配色
  • 原文地址:https://www.cnblogs.com/DreamACMer/p/12694111.html
Copyright © 2011-2022 走看看