zoukankan      html  css  js  c++  java
  • K

    DreamGrid is the keeper of n rabbits. Initially, the i-th (1≤i≤n) rabbit has a weight of wi.

    Every morning, DreamGrid gives the rabbits a carrot of weight 1 and the rabbits fight for the only carrot. Only one rabbit wins the fight and eats the carrot. After that, the winner’s weight increases by 1. The whole process of fighting and eating ends before the next morning.

    DreamGrid finds that the heavier a rabbit is, the easier it is to win a fight. Formally, if the weights of the rabbits are w′1,w′2,…,w′n before a fight, the probability that the i-th rabbit wins the fight is
    w′i∑j=1nw′j
    He wants to know the expected weight of every rabbit after k days (k carrots are given and eaten).

    Input
    The input contains multiple cases. The first line of the input contains a single integer T (1≤T≤105), the number of cases.

    For each case, the first line of the input contains two integers n and k (1≤n≤105,1≤k≤109). The second line contains n integers w1,w2,…,wn (1≤i≤n,1≤wi≤109).

    It’s guaranteed that the sum of n over all cases doesn’t exceed 106.

    Output
    For each case, print a single line containing n space-separated real numbers, where the i-th (1≤i≤n) number should be equal to the expected weight of the i-th rabbit after k days.

    Your answer will be considered correct if the absolute or relative error does not exceed 10−4.

    #include<iostream>
    
    using namespace std;
    typedef long long ll;
    const int N = 1e5+5;
    double w[N],p[N];
    
    int main(){
    	ll t;
    	scanf("%lld",&t);
    	while(t--){
    		ll n,k;
    		scanf("%lld %lld",&n,&k);
    		double sum=0;
    		for(int i=1;i<=n;i++){
    			scanf("%lf",&w[i]);
    			sum+=w[i];
    		}
    		for(int i=1;i<=n;i++){
    			p[i]=(double)w[i]/(double)sum;
    			w[i]+=1.0*k*p[i];
    		}
    		for(int i=1;i<=n;i++){
    			if(i==1){
    				printf("%.10lf",w[i]);
    			}
    			else {
    				printf(" %.10lf",w[i]);
    			}
    		}
    		puts("");
    	}
    	
    	return 0;
    }
    
  • 相关阅读:
    PHP foreach 循环
    C#导出Excel时间格式问题
    vs2015 key
    C# 的Chart
    线程暂停与继续实现
    CCNA网络工程师学习进程(2)基本的网络设备
    CCNA网络工程师学习进程(1)网络的基本概述
    安卓学习进程(3)安卓开发工具的简介
    安卓学习进程(2)Android开发环境的搭建
    安卓学习进程(1)移动平台开发的简介
  • 原文地址:https://www.cnblogs.com/neflibata/p/12871810.html
Copyright © 2011-2022 走看看