http://vjudge.net/contest/view.action?cid=51142#problem/C 精度转换的一道题。。。

文章详细介绍了如何公平地将一百卢布分配给在聚会中购买了更多饮料但实际消费较少的朋友。通过计算平均消费并根据个人消费超出平均值的金额进行分配,确保了公正性。
C - Get-Together at Den's
Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

Description

Advertising for beer and beer-based beverages must not use images of people and animals. Russia's Federal Law “On Advertising”, Ch. 3, Art. 22
Den invited n friends to his home. The friends were glad but first went to Auchan to buy some juice. The ith friend bought a i liters of juice. Then the friends came to Den and sat down to drink the juice. Everybody, including Den, drank the same amount of juice.
When there was no more juice, Misha started complaining about having bought more juice than he had drunk. Den didn't want Misha to get upset, so he took one hundred roubles out of his pocket and gave the money to Misha to compensate him for the juice he had bought but hadn't drunk himself. Then some more of Den's friends started complaining about the same issue. Den had no more money, so he suggested that all the friends who had bought more juice than they had drunk themselves should fairly divide his one hundred roubles between them. How should Den's friends divide the money? Assume that Den paid not only for the juice he had drunk but also for all the juice that had been drunk by the people who hadn't bought it.

Input

The first line contains the number n of Den's friends (2 ≤ n ≤ 100). In the second line you are given the integers a 1, …, a n (0 ≤ a i ≤ 100) . The sum of all  a i is positive.

Output

Output how much of the one hundred roubles the ith friend should take. Round the amounts down to an integer number of roubles.

Sample Input

inputoutput
3
10 10 10
33 33 33
2
10 0
100 0

 

 #include <iostream>
 #include <string.h>
 #include <stdio.h>

 using namespace std;

 int main()
 {
     int t;
     double a[105];
     double sum,avg,sum1;
     while(~scanf("%d",&t))
     {
         sum=0,avg=0,sum1=0;
         for(int i=0;i<t;i++)
         {
             cin>>a[i];
             sum+=a[i];
         }
         double avg=sum/(t+1.0);
         for(int i=0;i<t;i++)
         {
             if(a[i]-avg>0)
             {
                 sum1+=(a[i]-avg);
             }
         }
         for(int i=0;i<t;i++)
         {
             if(i!=0)
             printf(" ");
             if(a[i]-avg>0)
             printf("%d", (int)((a[i]-avg)/sum1*100 + 1e-5));
             ///cout << floor(100*b[i]/max+0.0001);  这也是OK的
             ///printf("%.0lf",(a[i]-avg)/sum1*100 + 1e-5));   就错    要屎啊
             else
             printf("0");
         }
         printf("\n");
     }
     return 0;
 }

 

转载于:https://www.cnblogs.com/zhangying/p/3871043.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值