Kolya Gerasimov loves kefir very much. He lives in year 1984 and knows all the details of buying this delicious drink. One day, as you probably know, he found himself in year 2084, and buying kefir there is much more complicated.
Kolya is hungry, so he went to the nearest milk shop. In 2084 you may buy kefir in a plastic liter bottle, that costs a rubles, or in glass liter bottle, that costs b rubles. Also, you may return empty glass bottle and get c (c < b) rubles back, but you cannot return plastic bottles.
Kolya has n rubles and he is really hungry, so he wants to drink as much kefir as possible. There were no plastic bottles in his 1984, so Kolya doesn’t know how to act optimally and asks for your help.
Input
First line of the input contains a single integer n (1 ≤ n ≤ 1018) — the number of rubles Kolya has at the beginning.
Then follow three lines containing integers a, b and c (1 ≤ a ≤ 1018, 1 ≤ c < b ≤ 1018) — the cost of one plastic liter bottle, the cost of one glass liter bottle and the money one can get back by returning an empty glass bottle, respectively.
Output
Print the only integer — maximum number of liters of kefir, that Kolya can drink.
input
10
11
9
8
output
2
input
10
5
6
1
output
2
题目链接:cf-625A
题目大意:一个人有n元钱买饮料。有两种购买方式:a元一瓶 or b元一瓶喝完退返c元
题目思路:两种购买方式:
- 全部买a饮料
- 尽可能多的去购买b饮料。
因为买第一瓶 n - b + c
第二瓶 n - 2b +2c
….
n - xb + xc > b 所以 ans 可以通过(n - b) / (b - c)计算得到。需要注意判断边界情况,如果剩余的钱还能买b,则ans+1
ps:如果剩余的钱买不了b,但是可能还能买a 所以最后结果还要判断剩余的钱以a的价格还能买几瓶
以下是代码:
#include <bits/stdc++.h>
#define mst(a) memset(a,0,sizeof (a))
#define FOR(i,n) for (int i = 0; i < n; i++)
#define INF 1e9
#define eps 1e-10
using namespace std;
typedef long long ll;
int main(){
ll n;
cin >> n;
ll n2 = n;
ll a,b,c,ans1 = 0,ans2 = 0;
cin >> a >> b >> c;
ans1 = n / a;
if (n >= b)
{
ll tmp2 = (n2 - b) / (b - c);
ans2 += tmp2;
if (n2 - tmp2 * (b - c) >= b) ans2++,n2 = n2-b+c;
n2 -= tmp2 * (b - c);
if (n2) ans2 += n2 / a;
}
cout << max(ans1,ans2) << endl;
return 0;
}
A long time ago, in a galaxy far far away two giant IT-corporations Pineapple and Gogol continue their fierce competition. Crucial moment is just around the corner: Gogol is ready to release it’s new tablet Lastus 3000.
This new device is equipped with specially designed artificial intelligence (AI). Employees of Pineapple did their best to postpone the release of Lastus 3000 as long as possible. Finally, they found out, that the name of the new artificial intelligence is similar to the name of the phone, that Pineapple released 200 years ago. As all rights on its name belong to Pineapple, they stand on changing the name of Gogol’s artificial intelligence.
Pineapple insists, that the name of their phone occurs in the name of AI as a substring. Because the name of technology was already printed on all devices, the Gogol’s director decided to replace some characters in AI name with “#”. As this operation is pretty expensive, you should find the minimum number of characters to replace with “#”, such that the name of AI doesn’t contain the name of the phone as a substring.
Substring is a continuous subsequence of a string.
Input
The first line of the input contains the name of AI designed by Gogol, its length doesn’t exceed 100 000 characters. Second line contains the name of the phone released by Pineapple 200 years ago, its length doesn’t exceed 30. Both string are non-empty and consist of only small English letters.
Output
Print the minimum number of characters that must be replaced with “#” in order to obtain that the name of the phone doesn’t occur in the name of AI as a substring.
input
intellect
tell
output
1
input
google
apple
output
0
input
sirisiri
sir
output
2
题目链接:cf-625B
题目思路:找有多少个子串就可以了,边界情况处理需要注意
以下是代码:
#include <bits/stdc++.h>
#define mst(a) memset(a,0,sizeof (a))
#define FOR(i,n) for (int i = 0; i < n; i++)
#define INF 1e9
#define eps 1e-10
using namespace std;
typedef long long ll;
int main(){
string s,sub;
cin >> s;
cin >> sub;
int ans = 0;
int len = s.size() - sub.size();
for (int i = 0; i <= len;)
{
int begin = i,ok = 1;
for (int j = 0; j < sub.size(); j++)
{
if (sub[j] != s[begin++]) {
ok = 0;
break;
}
}
if (ok)
{
i = i + sub.size();
ans++;
}
else i++;
}
cout << ans << endl;
return 0;
}
People do many crazy things to stand out in a crowd. Some of them dance, some learn by heart rules of Russian language, some try to become an outstanding competitive programmers, while others collect funny math objects.
Alis is among these collectors. Right now she wants to get one of k-special tables. In case you forget, the table n × n is called k-special if the following three conditions are satisfied:
every integer from 1 to n2 appears in the table exactly once;
in each row numbers are situated in increasing order;
the sum of numbers in the k-th column is maximum possible.
Your goal is to help Alice and find at least one k-special table of size n × n. Both rows and columns are numbered from 1 to n, with rows numbered from top to bottom and columns numbered from left to right.
Input
The first line of the input contains two integers n and k (1 ≤ n ≤ 500, 1 ≤ k ≤ n) — the size of the table Alice is looking for and the column that should have maximum possible sum.
Output
First print the sum of the integers in the k-th column of the required table.
Next n lines should contain the description of the table itself: first line should contains n elements of the first row, second line should contain n elements of the second row and so on.
If there are multiple suitable table, you are allowed to print any.
input
4 1
output
28
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
input
5 3
output
85
5 6 17 18 19
9 10 23 24 25
7 8 20 21 22
3 4 14 15 16
1 2 11 12 13
题目链接:cf-625C
题目思路:构造,详见代码
以下是代码:
#include <bits/stdc++.h>
#define mst(a) memset(a,0,sizeof (a))
#define FOR(i,n) for (int i = 0; i < n; i++)
#define INF 1e9
#define eps 1e-10
using namespace std;
typedef long long ll;
int ans[505][505];
int main(){
int n,k;
cin >> n >> k;
int cnt = 1,sum = 0;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j < k; j++)
{
ans[i][j] = cnt++;
}
}
for (int i = 1; i <= n; i++)
{
for (int j = k; j <= n; j++)
{
if (j == k) sum += cnt;
ans[i][j] = cnt++;
}
}
cout << sum << endl;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
cout << ans[i][j] << " ";
}
cout << endl;
}
return 0;
}