codeforces 1186D

http://codeforces.com/contest/1186/problem/D

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!

Input

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.

Output

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.

Examples

input

4
4.58413
1.22491
-2.10517
-3.70387

output

4
2
-2
-4

input

5
-6.32509
3.30066
-0.93878
2.00000
1.96321

output

-6
3
-1
2
2

Note

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.

题意概述:一个实数数列A,找到一个数列B,bi是ai向上取整或向下取整,使得B数列的和为0

解题思路:先把A数列转为int型,默认为正数向下取整,负数向上取整,求和,和为正则把负数向下取整,和为负则把正数向上取整

#include<iostream>
#include<queue>
#include<cstring> 
#include<cmath>
#include<map>
#include<algorithm>
#define up(i,x,y) for(i=x;i<=y;i++)  
#define down(i,x,y) for(i=x;i>=y;i--)  
#define MAX(a,b) a>b?a:b
#define MIN(a,b) a<b?a:b
#define MAX(a,b,c) (a>b?(a>c?a:c):(b>c?b:c))
#define MIN(a,b,c) (a<b?(a<c?a:c):(b<c?b:c))
using namespace std;

typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 1000000000;
const int maxn = 100;
const int MAXN = 2750131;
ll T,n,m,i,j;
ll gcd(ll p,ll q)
{return q==0?p:gcd(q,p%q);}
struct ddd{
	int z;
	double s;
	int flag;
}a[100050];
int main(){
	cin>>n;
	ll suma=0,sumb=0;
	for(i=0;i<n;i++){
		cin>>a[i].s;
		a[i].z=a[i].s;
		//cout<<a[i].z<<endl;
		if(a[i].s<0){
			
			sumb+=a[i].z;
		}
		else{
			suma+=a[i].z;
		}
		if(a[i].s==a[i].z){
			a[i].flag=0;
		}
		else{
			a[i].flag=1;
		}
		
	}
	ll fff=suma+sumb;
	//cout<<fff<<endl;
	for(i=0;i<n;i++){
		//cout<<fff<<" "<<a[i].z<<endl;
		if(fff>0){
			if(a[i].s<0&&a[i].flag){
				a[i].z--;
				fff--;
			}
		}
		else if(fff<0){
			if(a[i].s>0&&a[i].flag){
				a[i].z++;
				fff++;
			}
		}
		cout<<a[i].z<<endl;
	}
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值