Vus the Cossack and Numbers CF-1186D(思维)

Posted zhang-kelly

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Vus the Cossack and Numbers CF-1186D(思维)相关的知识,希望对你有一定的参考价值。

题意:

给一个浮点数序列$a$,其和为$0$。求一个序列$b$,满足$b[i]=ceil(a[i])$或者$b[i]=floor(a[i])$。

思路:

全部数字向下取整,赋值给$b$,统计$b$的和,若和不为$0$,则使原本不为整数的$a[i]$对应的$b[i]+1$,直到和为$0$。

代码:

 1 //#include<bits/stdc++.h>
 2 #include <set>
 3 #include <map>
 4 #include <stack>
 5 #include <cmath>
 6 #include <queue>
 7 #include <cstdio>
 8 #include <string>
 9 #include <vector>
10 #include <cstring>
11 #include <iostream>
12 #include <algorithm>
13 
14 #define ll long long
15 #define pll pair<ll,ll>
16 #define pii pair<int,int>
17 #define bug printf("*********
")
18 #define FIN freopen("input.txt","r",stdin);
19 #define FON freopen("output.txt","w+",stdout);
20 #define IO ios::sync_with_stdio(false),cin.tie(0)
21 #define ls root<<1
22 #define rs root<<1|1
23 #define pb push_back
24 
25 using namespace std;
26 const int inf = 2e9 + 7;
27 const ll Inf = 1e18 + 7;
28 const int maxn = 1e5 + 5;
29 const int mod = 1e9 + 7;
30 
31 double a[maxn];
32 int b[maxn];
33 
34 int main()
35 {
36     int n;
37     ll sum = 0;
38     scanf("%d", &n);
39     for (int i = 1; i <= n; ++i)
40     {
41         scanf("%lf", &a[i]);
42         b[i] = floor(a[i]);
43         sum += 1LL * b[i];
44     }
45     for (int i = 1; i <= n; ++i)
46     {
47         if (sum == 0)        break;
48         if (a[i] - b[i] < 1e-7)    continue;
49         b[i]++;
50         sum++;
51     }
52     for (int i = 1; i <= n; ++i)    cout << b[i] << endl;
53 }

 

以上是关于Vus the Cossack and Numbers CF-1186D(思维)的主要内容,如果未能解决你的问题,请参考以下文章

@codeforces - 1186E@ Vus the Cossack and a Field

Vus the Cossack and Numbers CF-1186D(思维)

Codeforces 1186F - Vus the Cossack and a Graph 模拟乱搞/欧拉回路

1562 Guess the number

为啥 .json 输出中的内置指标“vus”不反映控制台输出?

如何计算以下 #Vus、AVG 事务时间、loadrunner 中多个脚本的迭代?