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 backw 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.
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 containsn space-separated integers x1, x2, ..., xn (1 ≤ xi ≤ 109).
Output n space-separated integers. The i-th of them is the number of tokens Mashmokh can save on the i-th day.
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
题意:
给出 N(1 ~ 10 ^ 5),A(1 ~ 10 ^ 9),B(1 ~ 10 ^ 9),后给出这 N 个数(1 ~ 10 ^ 9),代表每天拥有的代币个数,每天都可以向雇主兑换钱币,兑换的规则是给 w 给雇主就可以换取 w * (a / b)(向下取整)这么多的钱币,问每天给代币从而每天都能获取最大的钱币数,输出能剩下的最大代币数。
思路:
数学。一开始单纯的想只要取模就好了,可是举例后发现不是这样的:
比如:a = 2,b = 3 。若 ai = 7 的话,( 7 X 2 ) % 3 = 2,取模的话是剩下两个,但是 ( 7 X 2 )/ 3 = 4.67 = 4,而 (6 X 2)/ 3 = 4,说明 7 个可以获得 4 个钱币,6 个也可以获得 4 个钱币,那么用 6 个,最大剩余代币量就是 1 而不是 2 。所以正确解法应该是:
先算出 ( ai * a )/ b 向下取整的可获得的最大兑换钱币数 k ,再返回去用这个 最大兑换钱币数k 算出 最少代币用量 ,总量 ai - 最少代币用量 剩下的自然就是 所剩的最大代币数了。
比如:a = 3,b = 4 。若 ai = 7,可得最大兑换钱币数是 5,而 (5 X 4 )/ 3 = 6,且不能整除,说明 6 个钱币是不能换到 5 个钱币的,只能换到 4 个,所以应该 6 要 + 1 = 7 才对。
返回去算出最少代币用量要判断 (k * b) 能不能整除 a,若能整除,说明这个数刚刚好为最少代币用量,若不能,则这个最少代币用量应该在除数的基础上 + 1。
AC:
#include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; typedef long long ll; ll res[100005]; int main () { int n, a, b; scanf("%d%d%d", &n, &a, &b); for (int i = 1; i <= n; ++i) { ll ans, t; scanf("%I64d", &ans); t = ((ll)ans * a) / (ll)b; res[i] = ans - (t * b) / (ll)a; if((t * b) % (ll)a) res[i]--; } printf("%I64d", res[1]); for (int i = 2; i <= n; ++i) printf(" %I64d", res[i]); printf("\n"); return 0; }
相关推荐
3 Multi-Application Smart Card Platforms and Operating Systems 4 Smart Cards and Security for Mobile Communications 5 Smart Cards for Banking and Finance 6 Security for Video Broadcasting 7 ...
Laravel开发-laravel-tokens Laravel认证的多令牌支持。
This document describes tokens and shows how to use them for non-volatile data storage in EmberZNet PRO.
1-【EDITOR】Magic Tokens Select Diverse Tokens for Multi-modal Object Re-Identification
批处理之 for _f 中的delims和tokens_tokens.pdf
tokens
通过区块浏览器抓取主流ERC-20代币,整理成json文件 ,包含logo图片 、token、 全称、 简称
**SOF** and **EOF** tokens have been inserted at the start and end of shell sessions, respectively. Sessions are concatenated by date order and tokens appear in the order issued within the shell ...
字符频率可以近似认为是难易程度排序
Over 60 effective recipes to ... Tagging Words and Tokens Chapter 5. Finding Spans in Text – Chunking Chapter 6. String Comparison and Clustering Chapter 7. Finding Coreference Between Concepts/People
including optimal token oating and pricing for both the utility tokens and the equity tokens (aka, security token oerings, STOs)|in the presence of product risk and demand uncertainty, make ...
"design-tokens": "design-tokens" } 然后执行: yarn design-tokens figma :如果要与figma同步。 yarn design-tokens build :如果要编译资产。 yarn design-tokens :如果您想同时与figma同步并编译资产。 ...
21个网页tokens钱包源码,是我在学习钱包开发的时候找到的,都是从GitHub上下载
var Tokens = require ( 'map-tokens' ) ; var tokens = new Tokens ( 'foo "bar" baz quux' ) ; // tokenize anything in double quotes tokens . pattern ( / \" ( [ ^ \" ] + ? ) \" / ) ; // replace tokens ...
js-tokens-源码.rar
PHP 微信公众平台 tokens 连接代码
Laravel开发-laravel-tokens .zip
Laravel开发-session-tokens Laravel的独特、可撤销的“记住我”代币
已激活的windows 7旗舰版pkeyconfig.xrm-ms和tokens.dat
Arc Py and Arc GIS Onlineb'Chapter 9: Arc Py and Arc GIS Online'b'Arc GIS Online REST services'b'URL parameters'b'Feature sets'b'Arc GIS Online tokens'b'Putting it all together'b'Summary'10: ...