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

59 篇文章 0 订阅
3 篇文章 0 订阅
文章描述了一个涉及n个玩家的游戏,每轮游戏后玩家的存款会按照特定规则互相转移。经过2022^1204轮后,程序需要计算每个玩家的最终存款。通过观察规律发现,所有玩家的存款最终稳定并相等,且等于初始总存款除以(n+1)的2倍。提供的C++代码实现了这一计算过程。
摘要由CSDN通过智能技术生成

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 <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值