Skip to content

Commit 62c78ea

Browse files
committed
🚀 21-May-2021
1 parent 2d2495d commit 62c78ea

32 files changed

+2262
-2
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
On a chessboard with a width of n and a height of n, rows are numbered from bottom to top from 1 to n, columns are numbered from left to right from 1 to n. Therefore, for each cell of the chessboard, you can assign the coordinates (r,c), where r is the number of the row, and c is the number of the column.
3+
4+
The white king has been sitting in a cell with (1,1) coordinates for a thousand years, while the black king has been sitting in a cell with (n,n) coordinates. They would have sat like that further, but suddenly a beautiful coin fell on the cell with coordinates (x,y)...
5+
6+
Each of the monarchs wanted to get it, so they decided to arrange a race according to slightly changed chess rules:
7+
8+
As in chess, the white king makes the first move, the black king makes the second one, the white king makes the third one, and so on. However, in this problem, kings can stand in adjacent cells or even in the same cell at the same time.
9+
10+
The player who reaches the coin first will win, that is to say, the player who reaches the cell with the coordinates (x,y) first will win.
11+
12+
Let's recall that the king is such a chess piece that can move one cell in all directions, that is, if the king is in the (a,b) cell, then in one move he can move from (a,b) to the cells (a+1,b), (a-1,b), (a,b+1), (a,b-1), (a+1,b-1), (a+1,b+1), (a-1,b-1), or (a-1,b+1). Going outside of the field is prohibited.
13+
14+
Determine the color of the king, who will reach the cell with the coordinates (x,y) first, if the white king moves first.
15+
16+
Input
17+
The first line contains a single integer n (2=n=1018) — the length of the side of the chess field.
18+
19+
The second line contains two integers x and y (1=x,y=n) — coordinates of the cell, where the coin fell.
20+
21+
Output
22+
In a single line print the answer "White" (without quotes), if the white king will win, or "Black" (without quotes), if the black king will win.
23+
24+
You can print each letter in any case (upper or lower).
25+
26+
Examples
27+
inputCopy
28+
4
29+
2 3
30+
outputCopy
31+
White
32+
inputCopy
33+
5
34+
3 5
35+
outputCopy
36+
Black
37+
inputCopy
38+
2
39+
2 2
40+
outputCopy
41+
Black
42+
Note
43+
An example of the race from the first sample where both the white king and the black king move optimally:
44+
45+
The white king moves from the cell (1,1) into the cell (2,2).
46+
The black king moves form the cell (4,4) into the cell (3,3).
47+
The white king moves from the cell (2,2) into the cell (2,3). This is cell containing the coin, so the white king wins.
48+
49+
An example of the race from the second sample where both the white king and the black king move optimally:
50+
51+
The white king moves from the cell (1,1) into the cell (2,2).
52+
The black king moves form the cell (5,5) into the cell (4,4).
53+
The white king moves from the cell (2,2) into the cell (3,3).
54+
The black king moves from the cell (4,4) into the cell (3,5). This is the cell, where the coin fell, so the black king wins.
55+
56+
In the third example, the coin fell in the starting cell of the black king, so the black king immediately wins.
57+
*/
58+
59+
60+
61+
#include<bits/stdc++.h>
62+
using namespace std;
63+
64+
int main(){
65+
ios_base::sync_with_stdio(false);
66+
cin.tie(NULL);
67+
68+
long long n, x, y;
69+
cin >> n >> x >> y;
70+
71+
long long wd = min(abs(x - 1), abs(y - 1)) + abs(x - y);
72+
long long bd = min(abs(x - n), abs(y - n)) + abs(x - y);
73+
74+
if (bd < wd) cout << "Black";
75+
else cout << "White";
76+
77+
78+
79+
return 0;
80+
}
Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,73 @@
1+
/*
2+
A company has n employees numbered from 1 to n. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee A is said to be the superior of another employee B if at least one of the following is true:
3+
4+
Employee A is the immediate manager of employee B
5+
Employee B has an immediate manager employee C such that employee A is the superior of employee C.
6+
The company will not have a managerial cycle. That is, there will not exist an employee who is the superior of his/her own immediate manager.
7+
8+
Today the company is going to arrange a party. This involves dividing all n employees into several groups: every employee must belong to exactly one group. Furthermore, within any single group, there must not be two employees A and B such that A is the superior of B.
9+
10+
What is the minimum number of groups that must be formed?
11+
12+
Input
13+
The first line contains integer n (1?=?n?=?2000) — the number of employees.
14+
15+
The next n lines contain the integers pi (1?=?pi?=?n or pi?=?-1). Every pi denotes the immediate manager for the i-th employee. If pi is -1, that means that the i-th employee does not have an immediate manager.
16+
17+
It is guaranteed, that no employee will be the immediate manager of him/herself (pi???i). Also, there will be no managerial cycles.
18+
19+
Output
20+
Print a single integer denoting the minimum number of groups that will be formed in the party.
21+
22+
Examples
23+
inputCopy
24+
5
25+
-1
26+
1
27+
2
28+
1
29+
-1
30+
outputCopy
31+
3
32+
Note
33+
For the first example, three groups are sufficient, for example:
34+
35+
Employee 1
36+
Employees 2 and 4
37+
Employees 3 and 5
38+
*/
39+
40+
41+
42+
43+
144
#include<bits/stdc++.h>
245
using namespace std;
346

47+
448
int main(){
549
ios_base::sync_with_stdio(false);
6-
cin.tie(NULL);
7-
50+
cin.tie(NULL);
51+
52+
int n;
53+
cin >> n;
54+
55+
vector <int> v(n);
56+
57+
for (auto &x: v) cin >> x;
58+
59+
int res = 0;
60+
61+
for (int i = 0; i < n; i++) {
62+
int j = i, cnt = 0;
63+
while (v[j] != -1) {
64+
cnt++;
65+
j = v[j] - 1;
66+
}
67+
res = max(res, cnt);
68+
}
69+
70+
cout << res + 1;
871

972
return 0;
1073
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
You are planning to build housing on a street. There are n spots available on the street on which you can build a house. The spots are labeled from 1 to n from left to right. In each spot, you can build a house with an integer height between 0 and h.
3+
4+
In each spot, if a house has height a, you will gain a2 dollars from it.
5+
6+
The city has m zoning restrictions. The i-th restriction says that the tallest house from spots li to ri (inclusive) must be at most xi.
7+
8+
You would like to build houses to maximize your profit. Determine the maximum profit possible.
9+
10+
Input
11+
The first line contains three integers n, h, and m (1=n,h,m=50) — the number of spots, the maximum height, and the number of restrictions.
12+
13+
Each of the next m lines contains three integers li, ri, and xi (1=li=ri=n, 0=xi=h) — left and right limits (inclusive) of the i-th restriction and the maximum possible height in that range.
14+
15+
Output
16+
Print a single integer, the maximum profit you can make.
17+
18+
Examples
19+
inputCopy
20+
3 3 3
21+
1 1 1
22+
2 2 3
23+
3 3 2
24+
outputCopy
25+
14
26+
inputCopy
27+
4 10 2
28+
2 3 8
29+
3 4 7
30+
outputCopy
31+
262
32+
Note
33+
In the first example, there are 3 houses, the maximum height of a house is 3, and there are 3 restrictions. The first restriction says the tallest house between 1 and 1 must be at most 1. The second restriction says the tallest house between 2 and 2 must be at most 3. The third restriction says the tallest house between 3 and 3 must be at most 2.
34+
35+
In this case, it is optimal to build houses with heights [1,3,2]. This fits within all the restrictions. The total profit in this case is 12+32+22=14.
36+
37+
In the second example, there are 4 houses, the maximum height of a house is 10, and there are 2 restrictions. The first restriction says the tallest house from 2 to 3 must be at most 8. The second restriction says the tallest house from 3 to 4 must be at most 7.
38+
39+
In this case, it's optimal to build houses with heights [10,8,7,7]. We get a profit of 102+82+72+72=262. Note that there are two restrictions on house 3 and both of them must be satisfied. Also, note that even though there isn't any explicit restrictions on house 1, we must still limit its height to be at most 10 (h=10).
40+
*/
41+
42+
43+
44+
45+
46+
#include<bits/stdc++.h>
47+
using namespace std;
48+
49+
int main(){
50+
ios_base::sync_with_stdio(false);
51+
cin.tie(NULL);
52+
53+
int n, h, m;
54+
cin >> n >> h >> m;
55+
56+
vector <int> v(n, h);
57+
58+
while (m--) {
59+
int l, r, x;
60+
cin >> l >> r >> x;
61+
62+
for (int i = l - 1; i <= r - 1; i++) v[i] = min(v[i], x);
63+
64+
}
65+
66+
long long res = 0;
67+
68+
for (auto &x: v) res += x * x;
69+
70+
cout << res;
71+
72+
return 0;
73+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
There is a very secret base in Potatoland where potato mash is made according to a special recipe. The neighbours from Porridgia decided to seize this recipe and to sell it to Pilauland. For this mission they have been preparing special agent Pearlo for many years. When, finally, Pearlo learned all secrets of espionage, he penetrated into the Potatoland territory and reached the secret base.
3+
4+
Now he is standing at the entrance, but to get inside he need to pass combination lock. Minute ago one of the workers entered the password on the terminal and opened the door. The terminal is a square digital keyboard 3?×?3 with digits from 1 to 9.
5+
6+
Pearlo knows that the password consists from distinct digits and is probably symmetric with respect to the central button of the terminal. He has heat sensor which allowed him to detect the digits which the worker pressed. Now he wants to check whether the password entered by the worker is symmetric with respect to the central button of the terminal. This fact can Help Pearlo to reduce the number of different possible password combinations.
7+
8+
Input
9+
Input contains the matrix of three rows of three symbols each. Symbol «X» means that the corresponding button was pressed, and «.» means that is was not pressed. The matrix may contain no «X», also it may contain no «.».
10+
11+
Output
12+
Print YES if the password is symmetric with respect to the central button of the terminal and NO otherwise.
13+
14+
Examples
15+
inputCopy
16+
XX.
17+
...
18+
.XX
19+
outputCopy
20+
YES
21+
inputCopy
22+
X.X
23+
X..
24+
...
25+
outputCopy
26+
NO
27+
Note
28+
If you are not familiar with the term «central symmetry», you may look into http://en.wikipedia.org/wiki/Central_symmetry
29+
*/
30+
31+
32+
33+
#include<bits/stdc++.h>
34+
using namespace std;
35+
36+
int main(){
37+
ios_base::sync_with_stdio(false);
38+
cin.tie(NULL);
39+
40+
int n = 3;
41+
42+
char a[n][n];
43+
44+
for (int i = 0; i < n; i++) {
45+
for (int j = 0; j < n; j++) {
46+
cin >> a[i][j];
47+
}
48+
}
49+
50+
bool res = true;
51+
52+
for (int i = 0; i < n; i++) {
53+
for (int j = 0; j < n; j++) {
54+
if (a[i][j] != a[n - i - 1][n - j - 1]) {
55+
res = false; break;
56+
}
57+
}
58+
}
59+
60+
res ? cout << "YES" : cout << "NO";
61+
62+
return 0;
63+
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*
2+
You are given three positive integers n, a and b. You have to construct a string s of length n consisting of lowercase Latin letters such that each substring of length a has exactly b distinct letters. It is guaranteed that the answer exists.
3+
4+
You have to answer t independent test cases.
5+
6+
Recall that the substring s[l…r] is the string sl,sl+1,…,sr and its length is r-l+1. In this problem you are only interested in substrings of length a.
7+
8+
Input
9+
The first line of the input contains one integer t (1=t=2000) — the number of test cases. Then t test cases follow.
10+
11+
The only line of a test case contains three space-separated integers n, a and b (1=a=n=2000,1=b=min(26,a)), where n is the length of the required string, a is the length of a substring and b is the required number of distinct letters in each substring of length a.
12+
13+
It is guaranteed that the sum of n over all test cases does not exceed 2000 (?n=2000).
14+
15+
Output
16+
For each test case, print the answer — such a string s of length n consisting of lowercase Latin letters that each substring of length a has exactly b distinct letters. If there are multiple valid answers, print any of them. It is guaranteed that the answer exists.
17+
18+
Example
19+
inputCopy
20+
4
21+
7 5 3
22+
6 1 1
23+
6 6 1
24+
5 2 2
25+
outputCopy
26+
tleelte
27+
qwerty
28+
vvvvvv
29+
abcde
30+
Note
31+
In the first test case of the example, consider all the substrings of length 5:
32+
33+
"tleel": it contains 3 distinct (unique) letters,
34+
"leelt": it contains 3 distinct (unique) letters,
35+
"eelte": it contains 3 distinct (unique) letters.
36+
*/
37+
38+
39+
/*
40+
#include<bits/stdc++.h>
41+
using namespace std;
42+
43+
44+
int main(){
45+
ios_base::sync_with_stdio(false);
46+
cin.tie(NULL);
47+
48+
int t;
49+
cin >> t;
50+
51+
while (t--) {
52+
int n, a , b;
53+
cin >> n >> a >> b;
54+
55+
string res = "";
56+
string s = "";
57+
58+
for (int i = 0; i < b; i++) s += 'a' + i;
59+
60+
res += s;
61+
62+
for (int i = 0; i < n - b; i++) res += s[i % b];
63+
64+
cout << res << "\n";
65+
}
66+
67+
return 0;
68+
}
69+
*/
70+
71+
72+
73+
74+
#include<bits/stdc++.h>
75+
using namespace std;
76+
77+
78+
int main(){
79+
ios_base::sync_with_stdio(false);
80+
cin.tie(NULL);
81+
82+
int t;
83+
cin >> t;
84+
85+
while (t--) {
86+
int n, a , b;
87+
cin >> n >> a >> b;
88+
89+
for (int i = 0; i < n; i++) cout << char('a' + (i % b));
90+
91+
cout << "\n";
92+
}
93+
94+
return 0;
95+
}

0 commit comments

Comments
 (0)