Round #240 B. Mashmokh and Tokens(Div.2)
Posted 浅忆
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Round #240 B. Mashmokh and Tokens(Div.2)相关的知识,希望对你有一定的参考价值。
Bimokh is Mashmokh‘s boss. For the following ndays 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 numbersx1,?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.
Example
5 1 4
12 6 11 9 1
0 2 3 1 1
3 1 2
1 2 3
1 0 1
1 1 1
1
0
1 /* 2 题意:老板一天发x张代币券,员工能用它来换大洋,用w张代币券可换[a*w/b](下取整)块大洋,代币券只能当天适用,求换最多大洋时最多能留多少代币券 3 比如a=3,b=7,x=4时,我最多能换3×4/7=1块大洋,但是我显然用3张代币券就能换1块大洋,所以多的1块就应该被保留 4 设t为当天最多换得的大洋有t=a*x/b,因为是下取整,有不等式t<=ax/b成立,我们现在只要找一个最小的x使得不等式成立, 5 为了将变量区分开,设至少用y张代币券换t块大洋,有不等式t<=ay/b成立,化简得y>=bt/a,x-y即所求 6 注意数据范围a,b,x可达10^9,相乘将达到10^18,所以需要用long long 7 */ 8 9 /* 10 #include <iostream> 11 #include <stdio.h> 12 using namespace std; 13 int main(){ 14 long long n,a,b,i,x,temp,t; 15 scanf("%I64d",&n,&a,&b); 16 for(i=0;i<n;i++){ 17 scanf("%I64d",&x); 18 t=(x*a)/b; /// 19 if((t*b)%a==0) temp=(t*b)/a; 20 else temp=(t*b)/a+1; 21 printf("%I64d",x-temp); 22 } 23 printf(" "); 24 return 0; 25 } 26 27 */ 28 #include<stdio.h> 29 #include<iostream> 30 using namespace std; 31 32 int main() 33 { 34 long long n,a,b,t,y,l,r,mid; 35 scanf("%I64d%I64d%I64d",&n,&a,&b); 36 long long x,ans; 37 for (int i=0;i<n;i++){ 38 scanf("%I64d",&x); 39 t=a*x/b; 40 if ((t*b)%a==0) y=t*b/a; 41 else y=t*b/a + 1; 42 printf("%I64d ",x-y); 43 printf(" "); 44 } 45 return 0; 46 }
以上是关于Round #240 B. Mashmokh and Tokens(Div.2)的主要内容,如果未能解决你的问题,请参考以下文章
Codeforces Round #352 (Div. 2) B. Different is Good
Codeforces Round #340 (Div. 2) B. Chocolate
Codeforces Round #720 (Div. 2), B. Nastia and a Good Array
Codeforces Round #353 (Div. 2) B. Restoring Painting __ map or set 思维题
Codeforces Round #343 (Div. 2) B. Far Relative’s Problem
Codeforces Round #257 (Div. 2) B. Jzzhu and Sequences (矩阵快速幂)