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 ...
随机推荐
- ios textView跟随键盘的移动
实现效果: textview 能够跟随键盘的移动而移动 效果图如下: 下边贴上主要的代码: 1.创建textview @interface ViewController ()<UITextVie ...
- Python高性能HTTP客户端库requests的使用
Python中有许多HTTP客户端.使用最广泛且最容易的是requests. 持续连接 很多人学习python,不知道从何学起.很多人学习python,掌握了基本语法过后,不知道在哪里寻找案例上手.很 ...
- JS DOM重点核心笔记
DOM重点核心 文档对象模型,是W3C推荐的处理可扩展的标记语言的标准编程接口 我们主要针对与勇士的操作,主要有创建.增加.删除.修改.查询.属性操作.事件操作 三种动态创建元素的 ...
- java_线程、同步、线程池
线程 Java使用 java.lang.Thread 类代表线程,所有的线程对象都必须是Thread类或其子类的实例 Thread类常用方法 构造方法 public Thread():分配一个新的线程 ...
- CSS 学习第二天
超链接的样式: 1.颜色变化:未访问时的样式a:link:鼠标点击后的样式a:visited;鼠标放上去的样式a:hover;鼠标点击时的样式a:active 2.鼠标变小手:cursor:point ...
- C#LeetCode刷题之#27-移除元素(Remove Element)
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3624 访问. 给定一个数组 nums 和一个值 val,你需要原 ...
- 高吞吐量消息系统—kafka
现在基本上大数据的场景中都会有kafka的身影,那么为什么这些场景下要用kafka而不用其他传统的消息队列呢?例如rabbitmq.主要的原因是因为kafka天然的百万级TPS,以及它对接其他大数据组 ...
- 漏洞重温之XSS(下)
XSS总结 XSS的可利用方式 1.在登录后才可以访问的页面插入xss代码,诱惑用户访问,便可直接偷取用户cookie,达到窃取用户身份信息的目的. 2.修改昵称,或个人身份信息.如果别的用户在登录状 ...
- 编译gawk出现问题,没有安装gawk。
今天编译kernal的时候出现了一个错误:GNU awk is required for lib/memtype.h made by memtypes.awk..查了资料,原来是没有安装gawk的缘故 ...
- java 工具类Integer
Integer 是lang包下的工具类 为了更加熟悉Integer中的方法使用和理解 进行了一部分代码和原代码的总结 Intrger工具类方法: * * int parseInt(String s) ...