• B


    Description

     

    Bimokh is Mashmokh's boss. For the following n days he decided to pay to his workers in a new way. At the beginning of each day he will give each worker a certain amount of tokens. Then at the end of each day each worker can give some of his tokens back to get a certain amount of money. The worker can save the rest of tokens but he can't use it in any other day to get more money. If a worker gives back wtokens then he'll get  dollars.

    Mashmokh likes the tokens however he likes money more. That's why he wants to save as many tokens as possible so that the amount of money he gets is maximal possible each day. He has n numbers x1, x2, ..., xn. Number xi is the number of tokens given to each worker on the i-th day. Help him calculate for each of n days the number of tokens he can save.

    Input

    The first line of input contains three space-separated integers n, a, b (1 ≤ n ≤ 105; 1 ≤ a, b ≤ 109). The second line of input contains n space-separated integers x1, x2, ..., xn (1 ≤ xi ≤ 109).

    Output

    Output n space-separated integers. The i-th of them is the number of tokens Mashmokh can save on the i-th day.

     

    Sample Input

    Input
    5 1 4
    12 6 11 9 1
    
    Output
    0 2 3 1 1 
    Input
    3 1 2
    1 2 3
    
    Output
    1 0 1 
    Input
    1 1 1
    1
    
    Output
    0 
     
     

     

     

     

     

    这是一道数学题。仔细分析便有结果。

     y是向下取整,得到最少的金币数。在保证y不变的情况下,最小的w是多少呢?

      ===》》》   可以得到这个。  要先判断y*b%a?因为是向下取整,(x只能是整数,比如x=3.1,你总不能给员工3个令牌吧,工人不愿意啊。只能给4个)  所以,%a!=0时要加1。

     

    代码如下:

     

     1 #include<stdio.h>
     2 int x[100000];
     3 int main()
     4 {
     5     long long n,a,b,w,z;
     6     scanf("%lld%lld%lld",&n,&a,&b);
     7     int i;
     8     for(i=0; i<n; i++)
     9     {
    10         scanf("%lld",&x[i]);
    11          w=x[i]*a/b;
    12         if(w*b%a==0)
    13            z=w*b/a;
    14         else
    15             z=w*b/a+1;
    16             printf("%lld ",x[i]-z);
    17     }
    18     printf("
    ");
    19     return 0;

     

     

    精简之后还有一个更简单的方法。

    既然  ,那么当y不是整数时,余数是多少呢?  为:t=w*a%b;

     

    题里面说了,a<b ; 那么余数t和a的关系呢? 

     

    举个最简单的例子a=3,b=4,w=6;=4。 余数是2 。a,b都是不能变的

    那么在金额4不变的情况下,w能变化吗?变成5?3*5/4=3,金额减小了(工人不愿

    意)变成7?3*7/4=5 变大了(老板不愿意,不可能增大)。。。所以变不得。节省为0。

    那么当w=5时,余数t为3,这时候t是a的倍数。t/a正是能节省的令牌数。

    例子:3*5/4=3, 3*4/4=3。在金额不变的情况下,w-1。所以节省了1个。

    所以你只需要判断余数和a的关系即可。

    代码:

     

     1 #include<stdio.h>
     2 int x[100000];
     3 int main()
     4 {
     5     long long n,a,b,w;
     6     scanf("%lld%lld%lld",&n,&a,&b);
     7     int i;
     8     for(i=0; i<n; i++)
     9     {
    10         scanf("%lld",&x[i]);
    11         printf("%lld ",x[i]*a%b/a);
    12     }
    13     printf("
    ");
    14     return 0;
    15 }
    我愿付出努力,只为更好的明天
  • 相关阅读:
    Arduino开发版学习计划--直流电机
    Arduino开发版学习计划--蜂鸣器
    社交网络编程API之iOS系统自带分享
    iOS解析XML实现省市区选择
    Frameworks(不定时更新)
    NSLayoutConstraint
    Categories  VS Extensions (分类 vs 扩展)
    strong vs copy
    折半查找
    Block
  • 原文地址:https://www.cnblogs.com/castledrv/p/3672385.html
Copyright © 2020-2023  润新知