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

Submit Status Practice URAL 1864

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 ai 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 a1, …, an (0 ≤ ai ≤ 100) . The sum of all  ai 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

input output
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;
 }
时间: 2024-11-09 02:18:36

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

暑假集训第一周比赛G题http://acm.hust.edu.cn/vjudge/contest/view.action?cid=83146#problem/G

G - 向 Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Description 把一个字符三角形掏空,就能节省材料成本,减轻重量,但关键是为了追求另一种视觉效果.在设计的过程中,需要给出各种花纹的材料和大小尺寸的三角形样板,通过电脑临时做出来,以便看看效果. Input 每行包含一个

暑假集训第一周比赛C题http://acm.hust.edu.cn/vjudge/contest/view.action?cid=83146#problem/C

C - 学 Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Description Ray又对数字的列产生了兴趣: 现有四张卡片,用这四张卡片能排列出很多不同的4位数,要求按从小到大的顺序输出这些4位数. Input 每组数据占一行,代表四张卡片上的数字(0<=数字<=9),如

HDU5120 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=93642#problem/I

这题求的是圆环相交的面积,画图可知  圆环相交面积=大交大-2×大交小+小交小 这题需要用到圆的相交面积公式 AC代码: 1 #include <stdio.h> 2 #include <string.h> 3 #include <math.h> 4 #include <algorithm> 5 #define exp 1e-10 6 #define PI 3.141592654 7 using namespace std; 8 typedef long l

POJ-3126 暑假集训-搜索进阶F题http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82828#problem/F

经验就是要认真细心,要深刻理解.num #include<iostream>#include<algorithm>#include<stdio.h>#include<stdlib.h>#include<math.h>#include<string.h>#include<ctype.h>#include<queue>using namespace std;#define N 11000 typedef struc

HDU2612 -暑假集训-搜索进阶N http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82828#problem/N

这两天总是因为一些小错误耽误时间,我希望自己可以细心点.珍惜时间,珍爱生命!#include<iostream> #include<algorithm> #include<string.h> #include<ctype.h> #include<stdio.h> #include<stdlib.h> #include<math.h> #include<limits.h> #include<queue>

E - 最大报销额 http://219.216.96.122/contest/view.action?cid=3#problem/E

E - 最大报销额 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Description 现有一笔经费可以报销一定额度的发票.允许报销的发票类型包括买图书(A类).文具(B类).差旅(C类),要求每张发票的总额不得超过1000元,每张发票上,单项物品的价值不得超过600元.现请你编写程序,在给出的一堆发票中找出可以报销的.不超过给定额度的最大报销额. Input

POJ3156 暑假集训-最短路H题floyd http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82829#rank

  http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82829#rank#include<iostream> #include<algorithm> #include<string.h> #include<stdio.h> #include<stdlib.h> #include<ctype.h> #include<limits.h> #include<mat

8.14比赛j题 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87813#overview

就我个人来说我觉得这道题其实不用写题解,只是因为做的时候错了一次,如果不是队友细心,我根本会错下去,所以我感觉自己必须强大#include<stdio.h> #include<string.h> #include<ctype.h> #include<queue> #include<algorithm> using namespace std; #define N 300100 int n, m, cnt; char str[N]; int v[N

论坛:Error:No result defined for action cn.itcast.oa.view.action.TopicAction and result

使用了<s:hidden name="forumId" value="#forum.id"/> 可以改为: <s:hidden name="forumId" value="%{#forum.id} <input type="hidden" name="forumId" value="${forumId}" />