Codeforces 415B Mashmokh and Tokens(贪心)

来源:互联网 发布:python中的iter 编辑:程序博客网 时间:2024/06/06 16:36

题目链接:Codeforces 415B Mashmokh and Tokens


题目大意:给出w,a,b,表示说有w天,每天给有x个令牌,然后根据公式可以将令牌换成钱,但是有可能1个令牌和两个令牌换到的钱数相同,那么久没有必要多花令牌,所以问说每一天最多节省多少令牌,在换取钱最多的情况。


解题思路:(x * a % b)/ a.


#include <stdio.h>#include <string.h>#include <iostream>using namespace std;const int N =1e5+5;typedef long long ll;int main () {ll n, a, b, c, w, ans[N];cin >> n >> a >> b;for (int i = 1; i <= n; i++) {cin >> w;ans[i] = (w * a % b)/a;}for (int i = 1; i < n; i++)cout << ans[i] << " ";cout << ans[n] << endl;return 0;}


0 0
原创粉丝点击