Codeforces Round #571 (Div. 2)-D. Vus the Cossack and Numbers
Vus the Cossack has nn real numbers aiai. It is known that the sum of all numbers is equal to 00. He wants to choose a sequence bb the size of which is nn such that the sum of all numbers is 00 and each bibi is either ⌊ai⌋⌊ai⌋ or ⌈ai⌉⌈ai⌉. In other words, bibi equals aiai rounded up or down. It is not necessary to round to the nearest integer.
For example, if a=[4.58413,1.22491,−2.10517,−3.70387]a=[4.58413,1.22491,−2.10517,−3.70387], then bb can be equal, for example, to [4,2,−2,−4][4,2,−2,−4].
Note that if aiai is an integer, then there is no difference between ⌊ai⌋⌊ai⌋ and ⌈ai⌉⌈ai⌉, bibi will always be equal to aiai.
Help Vus the Cossack find such sequence!
The first line contains one integer nn (1≤n≤1051≤n≤105) — the number of numbers.
Each of the next nn lines contains one real number aiai (|ai|<105|ai|<105). It is guaranteed that each aiai has exactly 55 digits after the decimal point. It is guaranteed that the sum of all the numbers is equal to 00.
In each of the next nn lines, print one integer bibi. For each ii, |ai−bi|<1|ai−bi|<1 must be met.
If there are multiple answers, print any.
4
4.58413
1.22491
-2.10517
-3.70387
4
2
-2
-4
5
-6.32509
3.30066
-0.93878
2.00000
1.96321
-6
3
-1
2
2
The first example is explained in the legend.
In the second example, we can round the first and fifth numbers up, and the second and third numbers down. We can round the fourth number neither up, nor down.
题意:原来的浮点型数组之和为0,现在让你进行向上或者向下取整,使得变化后的数组之和也是0
思路:把浮点型数组进行一种取整方式,然后把小数部分保留一下,看最后的小数部分的进行四舍五入后的结果,然后根据最后小数部分的和进行不断地进行改变取整方式就可以了
代码:
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<vector>
#include<cmath> const int maxn=1e5+;
typedef long long ll;
using namespace std;
double a[maxn];
int b[maxn]; int main()
{
int n;
cin>>n;
double s=;
for(int t=;t<n;t++)
{
scanf("%lf",&a[t]);
b[t]=a[t];
s+=(a[t]-b[t]);
}
int ss=round(s);
if(ss>)
{ for(int t=;t<n;t++)
{
if(ss==)
{
break;
}
if(a[t]>b[t])
{
b[t]++;
ss--;
}
}
}
if(ss<)
{
for(int t=;t<n;t++)
{
if(ss==)
{
break;
}
if(a[t]<b[t])
{
b[t]--;
ss++;
}
}
}
for(int t=;t<n;t++)
{
cout<<b[t]<<endl;
} return ;
}
Codeforces Round #571 (Div. 2)-D. Vus the Cossack and Numbers的更多相关文章
- Codeforces Round #571 (Div. 2)
A. Vus the Cossack and a Contest 签. #include <bits/stdc++.h> using namespace std; int main() { ...
- Vus the Cossack and Strings(Codeforces Round #571 (Div. 2))(大佬的位运算实在是太强了!)
C. Vus the Cossack and Strings Vus the Cossack has two binary strings, that is, strings that consist ...
- Codeforces Round #552 (Div. 3) 题解
Codeforces Round #552 (Div. 3) 题目链接 A. Restoring Three Numbers 给出 \(a+b\),\(b+c\),\(a+c\) 以及 \(a+b+c ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
- Codeforces Round #262 (Div. 2) 1003
Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...
随机推荐
- 学Java必看!零基础小白再也不用退缩了
程序员们!请往这儿看 对于JAVA的学习,可能你还会有许多的顾虑 不要担心 接着往下看吧 学Java前 一.数学差,英语也不好是不是学不好Java? 答案是:是~ 因为你在问这个问题的时候说明你对自己 ...
- mac 教你如何在Mac上搭建自己的服务器——Nginx
WHAT 本篇主要是基于Nginx在Mac上搭建自己的服务器. 我相信很多朋友肯定是第一次听到Nginx,关于它具有怎样的传奇,这儿肯定说不完也说不透. 有兴趣的朋友可以自行google或者baidu ...
- 基于boost的bind与function的一个简单示例消息处理框架
前两年开始接触boost,boost库真是博大精深:今天简单介绍一下boost中之前用到的的bind与function,感觉挺实用的,分享给大家,我对boost用的也不多,让大家见笑了. 上次文发了一 ...
- Spark Streaming——Spark第一代实时计算引擎
虽然SparkStreaming已经停止更新,Spark的重点也放到了 Structured Streaming ,但由于Spark版本过低或者其他技术选型问题,可能还是会选择SparkStreami ...
- 十多位全球技术专家,为你献上近十个小时的.Net微服务介绍
.Net Conf: Focus on Microservices 是 .Net Conf 社区在 2020 年 7 月 30 日举办的线上分享活动.整个活动视频长达近 10 个小时.今天我们来看看都 ...
- SpringCloud Sidecar 整合.Net WebApi
在整合.Net的过程中遇到不少问题,一般网上的例子只是调用一个简单的NodeJS示例,并未有详细的介绍及采坑过程. 首先,我的项目结构是:Vue前端 + SpringCloud后端 + .Net的We ...
- 2020-04-07:说出Servlet的生命周期,并说出Servlet和CGI的区别。
Servlet的生命周期分为5个阶段:实例化:Servlet容器创建Servlet类的实例.初始化:该容器调用init()方法,通常会申请资源.服务:由容器调用service()方法,(也就是doGe ...
- scanf函数与getchar函数
#define _CRT_SECURE_NO_WARNINGS#include<stdio.h>#include<string.h>#include<stdlib.h&g ...
- Linux内核之 基本概念
一直想写写Linux内核的文章,特别是进程这方面的,说实话,不好写,也不太敢写:)直到遇到了一本好书.<Linux内核设计与实现>,原书<Linux Kernel Developme ...
- GaussDB连接与登出
连接 连接命令1: gsql -d ${dbName} -U ${userName} -p {port:默认为25308} -h {ip} -W {password} 连接命令2: gsql -d p ...