2513: Distribute the cows

 

Status In/Out TIME Limit MEMORY Limit Submit Times Solved Users JUDGE TYPE
stdin/stdout 1s 16384K 417 81 Standard

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;
}

你可能感兴趣的:(Integer,less,input,each,output,Numbers)