[思维][打表]Money Game 2022年ICPC杭州站D

Putata and Budada are organizing a game with nn players. Each player has some deposit, which is a real number. Player ii has aiai deposits in the beginning. During each round of the game, the followings happen in order:

  • Player 11 gives player 22 half of player 11's deposit.
  • Player 22 gives player 33 half of player 22's deposit.
  • ...
  • Player n−1n−1 gives player nn half of player n−1n−1's deposit.
  • Player nn gives player 11 half of player nn's deposit.

The nn players played this game for exactly 2022120420221204 rounds. Putata wonders how much deposit each player has after the game. Please write a program to answer his question.

Input

The first line contains an integer nn (2≤n≤1052≤n≤105), denoting the number of players.

The second line contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1061≤ai≤106), denoting the deposit player ii has in the beginning.

Output

Output one line with nn real numbers, denoting the deposit each player has after they played this game.

Your answer will be considered correct if its absolute or relative error does not exceed 10−610−6. Formally, let your answer be aa, and the jury's answer be bb. Your answer will be considered correct if |a−b|max(1,|b|)≤10−6|a−b|max(1,|b|)≤10−6.

Example

input

2
4 2

output

4.00 2.00

题意: 给出n个数字,在每轮操作中让a[1]分一半给a[2],a[2]分一半给a[3],......,a[n]分一半给a[1],问在2022^1204轮操作后最终数组每个数字大小。

分析: 首先可以打一个表来找找规律,通过打表可以发现在若干轮迭代后,最终整个数组都趋于稳定,每个数字都不再变化,并且满足a[1] = 2*a[2] = 2*a[3] = ...... = 2*a[n]这个规律,同时操作不会改变数组加和,设sum为数组元素加和,最终就是a[1] = sum/(n+1)*2,a[2] = a[3] = ...... = a[n] = sum/(n+1)。

具体代码如下:

#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;

signed main(){
	int n;
	scanf("%d", &n);
	long long sum = 0;
	for(int i = 1; i <= n; i++){
		int t;
		scanf("%d", &t);
		sum += t;
	}
	printf("%.12f", 2.0*sum/(n+1));
	for(int i = 2; i <= n; i++)
		printf(" %.12f", 1.0*sum/(n+1));
    return 0;
}

你可能感兴趣的:(题解,思维,打表,算法)