标签:*** tac stream 一个 ++ set algo scan string
给一个浮点数序列$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("*********\n") 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(思维)
标签:*** tac stream 一个 ++ set algo scan string
原文地址:https://www.cnblogs.com/zhang-Kelly/p/12686559.html