Codeforces Round #240 (Div. 2)B. Mashmokh and Tokens

探讨了一个关于代币兑换的问题,员工每天获得一定数量的代币,可以用来兑换现金,目标是在每天最大化现金收益的同时,保存尽可能多的代币。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

B. Mashmokh and Tokens
time limit per test
 1 second
memory limit per test
 256 megabytes
input
 standard input
output
 standard output

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 w tokens 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 test(s)
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 


题意:老板一天发x张代币券,员工能用它来换大洋,用w张代币券可换[a*w/b](下取整)块大洋,代币券只能当天适用,求换最多大洋时最多能留多少代币券

比如a=3,b=7,x=4时,我最多能换3×4/7=1块大洋,但是我显然用3张代币券就能换1块大洋,所以多的1块就应该被保留

设t为当天最多换得的大洋有t=a*x/b,因为是下取整,有不等式t<=ax/b成立,我们现在只要找一个最小的x使得不等式成立,为了讲变量区分开,设至少用y张代币券换t块大洋,有不等式t<=ay/b成立,化简得y>=bt/a,x-y即所求

注意数据范围a,b,x可达10^9,相乘将达到10^18,所以需要用long long(因为没用long long WA了半个小时)

[cpp]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. #include<cstdio>  
  2. #include<iostream>  
  3. #include<cstdlib>  
  4. #include<algorithm>  
  5. #include<ctime>  
  6. #include<cctype>  
  7. #include<cmath>  
  8. #include<string>  
  9. #include<cstring>  
  10. #include<stack>  
  11. #include<queue>  
  12. #include<vector>  
  13. #include<map>  
  14. #define sqr(x) (x)*(x)  
  15. #define LL long long  
  16. #define INF 0x3f3f3f3f  
  17. #define PI 3.14159265358979  
  18. #define eps 1e-10  
  19. #define mm  
  20.   
  21. using namespace std;  
  22.   
  23. int main()  
  24. {  
  25.     #ifndef ONLINE_JUDGE  
  26.         freopen("t","r",stdin);  
  27.     #endif  
  28.     long long n,a,b,t,y,l,r,mid;  
  29.   
  30.     scanf("%I64d%I64d%I64d",&n,&a,&b);  
  31.     long long x,ans;  
  32.   
  33.     for (int i=0;i<n;i++)  
  34.     {  
  35.         scanf("%I64d",&x);  
  36.         t=a*x/b;  
  37.         if ((t*b)%a==0)  
  38.         {  
  39.             y=t*b/a;  
  40.         }  
  41.         else  
  42.         {  
  43.             y=t*b/a + 1;  
  44.         }  
  45.         printf("%I64d ",x-y);  
  46.     }  
  47.     puts("");  
  48.   
  49.   
  50.     return 0;  
  51. }  



http://codeforces.com/contest/415/problem/C

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值