A. Buy a Shovel
time limit per test:1 second
memory limit per test:256 megabytes
input:standard input
output:standard output
Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for k burles. Assume that there is an unlimited number of such shovels in the shop.
In his pocket Polycarp has an unlimited number of “10-burle coins” and exactly one coin of r burles (1 ≤ r ≤ 9).
What is the minimum number of shovels Polycarp has to buy so that he can pay for the purchase without any change? It is obvious that he can pay for 10 shovels without any change (by paying the requied amount of 10-burle coins and not using the coin of r burles). But perhaps he can buy fewer shovels and pay without any change. Note that Polycarp should buy at least one shovel.
Input
The single line of input contains two integers k and r (1 ≤ k ≤ 1000, 1 ≤ r ≤ 9) — the price of one shovel and the denomination of the coin in Polycarp’s pocket that is different from “10-burle coins”.
Remember that he has an unlimited number of coins in the denomination of 10, that is, Polycarp has enough money to buy any number of shovels.
Output
Print the required minimum number of shovels Polycarp has to buy so that he can pay for them without any change.
Examples
Input
117 3
Output
9
Input
237 7
Output
1
Input
15 2
Output
2
Note
In the first example Polycarp can buy 9 shovels and pay 9·117 = 1053 burles. Indeed, he can pay this sum by using 10-burle coins and one 3-burle coin. He can’t buy fewer shovels without any change.
In the second example it is enough for Polycarp to buy one shovel.
In the third example Polycarp should buy two shovels and pay 2·15 = 30 burles. It is obvious that he can pay this sum without any change
题意:给你两个数。每次第一个数加上本身,问最少几次使得第一个数的个位是0或者是第二个数。
题解:模拟题姿势优美即可。
代码:
#include <bits/stdc++.h>
using namespace std;
int main()
{
int a,b;
cin>>a>>b;
int k=a;
while(a%10!=b&&a%10!=0)
{
a+=k;
}
cout<<a/k<<endl;
}
B. Cormen — The Best Friend Of a Man
time limit per test:1 second
memory limit per test:256 megabytes
input:standard input
output:standard output
Recently a dog was bought for Polycarp. The dog’s name is Cormen. Now Polycarp has a lot of troubles. For example, Cormen likes going for a walk.
Empirically Polycarp learned that the dog needs at least k walks for any two consecutive days in order to feel good. For example, if k = 5 and yesterday Polycarp went for a walk with Cormen 2 times, today he has to go for a walk at least 3 times.
Polycarp analysed all his affairs over the next n days and made a sequence of n integers a1, a2, …, an, where ai is the number of times Polycarp will walk with the dog on the i-th day while doing all his affairs (for example, he has to go to a shop, throw out the trash, etc.).
Help Polycarp determine the minimum number of walks he needs to do additionaly in the next n days so that Cormen will feel good during all the n days. You can assume that on the day before the first day and on the day after the n-th day Polycarp will go for a walk with Cormen exactly k times.
Write a program that will find the minumum number of additional walks and the appropriate schedule — the sequence of integers b1, b2, …, bn (bi ≥ ai), where bi means the total number of walks with the dog on the i-th day.
Input
The first line contains two integers n and k (1 ≤ n, k ≤ 500) — the number of days and the minimum number of walks with Cormen for any two consecutive days.
The second line contains integers a1, a2, …, an (0 ≤ ai ≤ 500) — the number of walks with Cormen on the i-th day which Polycarp has already planned.
Output
In the first line print the smallest number of additional walks that Polycarp should do during the next n days so that Cormen will feel good during all days.
In the second line print n integers b1, b2, …, bn, where bi — the total number of walks on the i-th day according to the found solutions (ai ≤ bi for all i from 1 to n). If there are multiple solutions, print any of them.
Examples
Input
3 5
2 0 1
Output
4
2 3 2
Input
3 1
0 0 0
Output
1
0 1 0
Input
4 6
2 4 3 5
Output
0
2 4 3 5
题意:给你n天,要求相邻两天的和>=k。问最少增加数和变化后每天的数。
题解:很明显。如果相邻两天不够k,在第二天补上即可。(CF没有输出格式的限制。)
代码:
#include <bits/stdc++.h>
using namespace std;
int a[1000];
int main()
{
int n,k;
int ans=0;
scanf("%d%d",&n,&k);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
for(int i=1;i<n;i++)
{
if(a[i]+a[i+1]<k)
{
ans+=k-a[i]-a[i+1];
a[i+1]=k-a[i];
}
}
cout<<ans<<endl;
for(int i=1;i<=n;i++)
{
cout<<a[i]<<" ";
}
}