CodeForces 415B Mashmokh and Tokens
2015-10-02 16:47
357 查看
链接:http://codeforces.com/problemset/problem/415/B
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.
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).
i-th of them is the number of tokens Mashmokh can save on the
i-th day.
Output
Input
Output
Input
Output
直接附上AC代码:
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <iomanip>
#include <ctime>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
#include <set>
#include <map>
//#pragma comment(linker, "/STACK:102400000, 102400000")
using namespace std;
typedef unsigned int li;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const double pi = acos(-1.0);
const double e = exp(1.0);
const double eps = 1e-8;
const int maxn = 100005;
ll ans[maxn];
int n, a, b;
int main()
{
ios::sync_with_stdio(false);
while (~scanf("%d%d%d", &n, &a, &b))
{
for (int i=0; i<n; i++)
scanf("%I64d", &ans[i]);
for (int i=0; i<n-1; i++)
printf("%I64d ", (ans[i]*a)%b/a);
printf("%I64d\n", (ans[n-1]*a)%b/a);
}
return 0;
}
Mashmokh and Tokens
time limit per test:1 secondmemory 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 integersn, 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. Thei-th of them is the number of tokens Mashmokh can save on the
i-th day.
Sample test(s)
Input5 1 4 12 6 11 9 1
Output
02 3 1 1
Input
3 1 2 1 2 3
Output
1 01
Input
1 1 1 1
Output
0
直接附上AC代码:
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <iomanip>
#include <ctime>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
#include <set>
#include <map>
//#pragma comment(linker, "/STACK:102400000, 102400000")
using namespace std;
typedef unsigned int li;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const double pi = acos(-1.0);
const double e = exp(1.0);
const double eps = 1e-8;
const int maxn = 100005;
ll ans[maxn];
int n, a, b;
int main()
{
ios::sync_with_stdio(false);
while (~scanf("%d%d%d", &n, &a, &b))
{
for (int i=0; i<n; i++)
scanf("%I64d", &ans[i]);
for (int i=0; i<n-1; i++)
printf("%I64d ", (ans[i]*a)%b/a);
printf("%I64d\n", (ans[n-1]*a)%b/a);
}
return 0;
}
相关文章推荐
- 1.一些 贪心算法 的简单思维题:
- 贪心算法——字典序最小问题
- 贪心算法——区间调度问题
- Codeforces Round #197 (Div. 2)
- Codeforces Round #198 (Div. 1)
- Codeforces 405E Codeforces Round #238 (Div. 2)E
- Codeforces 407C Codeforces Round #239 (Div. 1)C
- Jump Game I,II 贪心
- Wildcard Matching
- 贪心题目循环和控制台折行
- CodeForces 449A - Jzzhu and Chocolate
- CodeForces 449 B. Jzzhu and Cities
- Codeforces Round #265 (Div. 2)
- HDOJ 1009
- Codeforces #310 div2 C. Case of Matryoshkas
- 【解题报告】【USACO】酸奶工厂
- 【解题报告】【】交谊舞
- POJ 1328
- 状态压缩DP codeforces 244 Problem C. The Brand New Function 和 codeforces 165 E. Compatible Numbers
- codeforces 16 Problem E fish