Skip to content

Commit 48d1562

Browse files
committed
🚀 30-May-2021
1 parent 62c78ea commit 48d1562

17 files changed

+1357
-43
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
Mishka wants to buy some food in the nearby shop. Initially, he has s burles on his card.
3+
4+
Mishka can perform the following operation any number of times (possibly, zero): choose some positive integer number 1=x=s, buy food that costs exactly x burles and obtain ?x10? burles as a cashback (in other words, Mishka spends x burles and obtains ?x10? back). The operation ?ab? means a divided by b rounded down.
5+
6+
It is guaranteed that you can always buy some food that costs x for any possible value of x.
7+
8+
Your task is to say the maximum number of burles Mishka can spend if he buys food optimally.
9+
10+
For example, if Mishka has s=19 burles then the maximum number of burles he can spend is 21. Firstly, he can spend x=10 burles, obtain 1 burle as a cashback. Now he has s=10 burles, so can spend x=10 burles, obtain 1 burle as a cashback and spend it too.
11+
12+
You have to answer t independent test cases.
13+
14+
Input
15+
The first line of the input contains one integer t (1=t=104) — the number of test cases.
16+
17+
The next t lines describe test cases. Each test case is given on a separate line and consists of one integer s (1=s=109) — the number of burles Mishka initially has.
18+
19+
Output
20+
For each test case print the answer on it — the maximum number of burles Mishka can spend if he buys food optimally.
21+
22+
Example
23+
inputCopy
24+
6
25+
1
26+
10
27+
19
28+
9876
29+
12345
30+
1000000000
31+
outputCopy
32+
1
33+
11
34+
21
35+
10973
36+
13716
37+
1111111111
38+
39+
*/
40+
41+
42+
43+
44+
#include<bits/stdc++.h>
45+
using namespace std;
46+
47+
48+
int main(){
49+
ios_base::sync_with_stdio(false);
50+
cin.tie(NULL);
51+
52+
int t;
53+
cin >> t;
54+
55+
while (t--) {
56+
long long n;
57+
cin >> n;
58+
59+
long long res = 0;
60+
61+
while (n > 0) {
62+
if (n < 10) {
63+
res += n;
64+
n /= 10;
65+
} else {
66+
long long c = log10(n);
67+
res += (long long)pow(10, c);
68+
n = n - (long long)pow(10, c) + (long long)pow(10, c - 1);
69+
}
70+
}
71+
72+
cout << res << "\n";
73+
}
74+
75+
76+
return 0;
77+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
You are given some Tetris field consisting of n columns. The initial height of the i-th column of the field is ai blocks. On top of these columns you can place only figures of size 2×1 (i.e. the height of this figure is 2 blocks and the width of this figure is 1 block). Note that you cannot rotate these figures.
3+
4+
Your task is to say if you can clear the whole field by placing such figures.
5+
6+
More formally, the problem can be described like this:
7+
8+
The following process occurs while at least one ai is greater than 0:
9+
10+
You place one figure 2×1 (choose some i from 1 to n and replace ai with ai+2);
11+
then, while all ai are greater than zero, replace each ai with ai-1.
12+
And your task is to determine if it is possible to clear the whole field (i.e. finish the described process), choosing the places for new figures properly.
13+
14+
You have to answer t independent test cases.
15+
16+
Input
17+
The first line of the input contains one integer t (1=t=100) — the number of test cases.
18+
19+
The next 2t lines describe test cases. The first line of the test case contains one integer n (1=n=100) — the number of columns in the Tetris field. The second line of the test case contains n integers a1,a2,…,an (1=ai=100), where ai is the initial height of the i-th column of the Tetris field.
20+
21+
Output
22+
For each test case, print the answer — "YES" (without quotes) if you can clear the whole Tetris field and "NO" otherwise.
23+
24+
Example
25+
inputCopy
26+
4
27+
3
28+
1 1 3
29+
4
30+
1 1 2 1
31+
2
32+
11 11
33+
1
34+
100
35+
outputCopy
36+
YES
37+
NO
38+
YES
39+
YES
40+
Note
41+
The first test case of the example field is shown below:
42+
43+
44+
45+
Gray lines are bounds of the Tetris field. Note that the field has no upper bound.
46+
47+
One of the correct answers is to first place the figure in the first column. Then after the second step of the process, the field becomes [2,0,2]. Then place the figure in the second column and after the second step of the process, the field becomes [0,0,0].
48+
49+
And the second test case of the example field is shown below:
50+
51+
52+
53+
It can be shown that you cannot do anything to end the process.
54+
55+
In the third test case of the example, you first place the figure in the second column after the second step of the process, the field becomes [0,2]. Then place the figure in the first column and after the second step of the process, the field becomes [0,0].
56+
57+
In the fourth test case of the example, place the figure in the first column, then the field becomes [102] after the first step of the process, and then the field becomes [0] after the second step of the process.
58+
*/
59+
60+
61+
62+
63+
#include<bits/stdc++.h>
64+
using namespace std;
65+
66+
int main(){
67+
ios_base::sync_with_stdio(false);
68+
cin.tie(NULL);
69+
70+
int t;
71+
cin >> t;
72+
73+
while (t--) {
74+
int n;
75+
cin >> n;
76+
77+
vector <int> v(n);
78+
79+
for (auto &x: v) cin >> x;
80+
81+
int odd = 0;
82+
83+
for (auto &x: v) {
84+
if (x % 2) odd++;
85+
}
86+
87+
if (odd == n || n - odd == n) cout << "YES\n";
88+
else cout << "NO\n";
89+
}
90+
91+
92+
return 0;
93+
}
94+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
/*
2+
Orac is studying number theory, and he is interested in the properties of divisors.
3+
4+
For two positive integers a and b, a is a divisor of b if and only if there exists an integer c, such that a·c=b.
5+
6+
For n=2, we will denote as f(n) the smallest positive divisor of n, except 1.
7+
8+
For example, f(7)=7,f(10)=2,f(35)=5.
9+
10+
For the fixed integer n, Orac decided to add f(n) to n.
11+
12+
For example, if he had an integer n=5, the new value of n will be equal to 10. And if he had an integer n=6, n will be changed to 8.
13+
14+
Orac loved it so much, so he decided to repeat this operation several times.
15+
16+
Now, for two positive integers n and k, Orac asked you to add f(n) to n exactly k times (note that n will change after each operation, so f(n) may change too) and tell him the final value of n.
17+
18+
For example, if Orac gives you n=5 and k=2, at first you should add f(5)=5 to n=5, so your new value of n will be equal to n=10, after that, you should add f(10)=2 to 10, so your new (and the final!) value of n will be equal to 12.
19+
20+
Orac may ask you these queries many times.
21+
22+
Input
23+
The first line of the input is a single integer t (1=t=100): the number of times that Orac will ask you.
24+
25+
Each of the next t lines contains two positive integers n,k (2=n=106,1=k=109), corresponding to a query by Orac.
26+
27+
It is guaranteed that the total sum of n is at most 106.
28+
29+
Output
30+
Print t lines, the i-th of them should contain the final value of n in the i-th query by Orac.
31+
32+
Example
33+
inputCopy
34+
3
35+
5 1
36+
8 2
37+
3 4
38+
outputCopy
39+
10
40+
12
41+
12
42+
Note
43+
In the first query, n=5 and k=1. The divisors of 5 are 1 and 5, the smallest one except 1 is 5. Therefore, the only operation adds f(5)=5 to 5, and the result is 10.
44+
45+
In the second query, n=8 and k=2. The divisors of 8 are 1,2,4,8, where the smallest one except 1 is 2, then after one operation 8 turns into 8+(f(8)=2)=10. The divisors of 10 are 1,2,5,10, where the smallest one except 1 is 2, therefore the answer is 10+(f(10)=2)=12.
46+
47+
In the third query, n is changed as follows: 3?6?8?10?12.
48+
*/
49+
50+
51+
52+
/*
53+
#include<bits/stdc++.h>
54+
using namespace std;
55+
56+
int getFactor(int n) {
57+
for (int i = 2; i * i <= n; i++) {
58+
if (n % i == 0) return i;
59+
}
60+
return n;
61+
}
62+
63+
int main(){
64+
ios_base::sync_with_stdio(false);
65+
cin.tie(NULL);
66+
67+
int t;
68+
cin >> t;
69+
70+
while (t--) {
71+
int n, k;
72+
cin >> n >> k;
73+
74+
for (int i = 1; i <= k; i++) {
75+
if (n % 2 == 0) {
76+
n += 2 * (k - i + 1);
77+
break;
78+
} else {
79+
int lfactor = getFactor(n);
80+
n += lfactor;
81+
}
82+
}
83+
84+
cout << n << "\n";
85+
}
86+
87+
return 0;
88+
}
89+
*/
90+
91+
92+
93+
#include<bits/stdc++.h>
94+
using namespace std;
95+
96+
int getFactor(int n) {
97+
for (int i = 2; i * i <= n; i++) {
98+
if (n % i == 0) return i;
99+
}
100+
return n;
101+
}
102+
103+
int main(){
104+
ios_base::sync_with_stdio(false);
105+
cin.tie(NULL);
106+
107+
int t;
108+
cin >> t;
109+
110+
while (t--) {
111+
int n, k;
112+
cin >> n >> k;
113+
114+
if (n % 2 == 0) cout << n + (2 * k) << "\n";
115+
else cout << n + getFactor(n) + 2 * (k - 1) << "\n";
116+
}
117+
118+
return 0;
119+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
Polycarp has spent the entire day preparing problems for you. Now he has to sleep for at least a minutes to feel refreshed.
3+
4+
Polycarp can only wake up by hearing the sound of his alarm. So he has just fallen asleep and his first alarm goes off in b minutes.
5+
6+
Every time Polycarp wakes up, he decides if he wants to sleep for some more time or not. If he's slept for less than a minutes in total, then he sets his alarm to go off in c minutes after it is reset and spends d minutes to fall asleep again. Otherwise, he gets out of his bed and proceeds with the day.
7+
8+
If the alarm goes off while Polycarp is falling asleep, then he resets his alarm to go off in another c minutes and tries to fall asleep for d minutes again.
9+
10+
You just want to find out when will Polycarp get out of his bed or report that it will never happen.
11+
12+
Please check out the notes for some explanations of the example.
13+
14+
Input
15+
The first line contains one integer t (1=t=1000) — the number of testcases.
16+
17+
The only line of each testcase contains four integers a,b,c,d (1=a,b,c,d=109) — the time Polycarp has to sleep for to feel refreshed, the time before the first alarm goes off, the time before every succeeding alarm goes off and the time Polycarp spends to fall asleep.
18+
19+
Output
20+
For each test case print one integer. If Polycarp never gets out of his bed then print -1. Otherwise, print the time it takes for Polycarp to get out of his bed.
21+
22+
Example
23+
inputCopy
24+
7
25+
10 3 6 4
26+
11 3 6 4
27+
5 9 4 10
28+
6 5 2 3
29+
1 1 1 1
30+
3947465 47342 338129 123123
31+
234123843 13 361451236 361451000
32+
outputCopy
33+
27
34+
27
35+
9
36+
-1
37+
1
38+
6471793
39+
358578060125049
40+
Note
41+
In the first testcase Polycarp wakes up after 3 minutes. He only rested for 3 minutes out of 10 minutes he needed. So after that he sets his alarm to go off in 6 minutes and spends 4 minutes falling asleep. Thus, he rests for 2 more minutes, totaling in 3+2=5 minutes of sleep. Then he repeats the procedure three more times and ends up with 11 minutes of sleep. Finally, he gets out of his bed. He spent 3 minutes before the first alarm and then reset his alarm four times. The answer is 3+4·6=27.
42+
43+
The second example is almost like the first one but Polycarp needs 11 minutes of sleep instead of 10. However, that changes nothing because he gets 11 minutes with these alarm parameters anyway.
44+
45+
In the third testcase Polycarp wakes up rested enough after the first alarm. Thus, the answer is b=9.
46+
47+
In the fourth testcase Polycarp wakes up after 5 minutes. Unfortunately, he keeps resetting his alarm infinitely being unable to rest for even a single minute :(
48+
*/
49+
50+
51+
52+
53+
54+
#include<bits/stdc++.h>
55+
using namespace std;
56+
57+
int main(){
58+
ios_base::sync_with_stdio(false);
59+
cin.tie(NULL);
60+
61+
int t;
62+
cin >> t;
63+
64+
while (t--){
65+
int a, b, c, d;
66+
cin >> a >> b >> c >> d;
67+
68+
if (a <= b) cout << b << "\n";
69+
else if (c <= d) cout << -1 << "\n";
70+
else cout << (long long)(b + c * (long long)ceil((float)(a - b) / (c - d))) << "\n";
71+
}
72+
73+
return 0;
74+
}
75+

0 commit comments

Comments
 (0)