2513: Distribute the cows

 


StatusIn/OutTIME LimitMEMORY LimitSubmit TimesSolved UsersJUDGE TYPE
stdin/stdout1s16384K41781Standard

At the beginning ,I’ll tell you an old story . It was about how to distribute the cows between three people.Long long ago, an old man was sick in the bed,he know he would die soon ,left nineteen cows to his family .So he whote a testament,to his three sons,which said that the eldest son would get half of the cows ,the second one got one fourth of the cows,the youngest one got one fifth of them. Soon after the testament , he died. But how to distribute the cows,the sons was confused,because no one of them can got the absolute cows as told. So they asked the most sapiential man for help.The man thought a moment and he got it.He brought one cow from his own and there totalled 20 cows .After distributing the cows he got away his cow and the problem was solved perfectly. Now if the old man has N(0< N<=5) sons and M(M< 2^32) cows,he wrote N numbers, which means the proportion between the sons.Of course ,if your method is right ,I can promise every one of them can get integral number of cows and distribute the whole M cows.The proportion number will like “1/P”,“P”is an integer less than 50 and bigger than zero ,means that the son can get one P-th of the M cows. Then you should output the number of cows given to each son as the input sequence.between each case ,there is one blank line.

Sample Input

3 19
1/2 1/4 1/5
3 41
1/2 1/3 1/7

Sample Output

10 5 4

21 14 6

 

Problem Source: Keenas

 


This problem is used for contest: 120 

 

 

 #include<stdio.h>
double a[6];
int main()
{
 int i,j,k,p;
 double n,m;
 char c;
 bool flag=true;
 double sum,q;
 while(scanf("%lf%lf",&n,&m)!=EOF)
 {
  if(flag==false)
  printf("/n");
  flag=false;
  sum=0;
  for(i=1;i<=n;i++)
  {
   scanf("%lf%c%lf",&p,&c,&a[i]);
   a[i]=1/a[i];
   sum+=a[i];//计算所有数的和
  }
  q=m/sum;//表示每一份的实际大小
  for(i=1;i<=n;i++)
  {
   if(i==1)
   printf("%.0lf",q*a[i]);
   else
   printf(" %.0lf",q*a[i]);
  }
  printf("/n");
 }
 return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值