Skip to content

Commit 2d2495d

Browse files
committed
🚀 13-May-2021
1 parent 1f48393 commit 2d2495d

13 files changed

+898
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
Arkady's morning seemed to be straight of his nightmare. He overslept through the whole morning and, still half-asleep, got into the tram that arrived the first. Some time after, leaving the tram, he realized that he was not sure about the line number of the tram he was in.
3+
4+
During his ride, Arkady woke up several times and each time he saw the tram stopping at some stop. For each stop he knows which lines of tram stop there. Given this information, can you help Arkady determine what are the possible lines of the tram he was in?
5+
6+
Input
7+
The first line contains a single integer n (2=n=100) — the number of stops Arkady saw.
8+
9+
The next n lines describe the stops. Each of them starts with a single integer r (1=r=100) — the number of tram lines that stop there. r distinct integers follow, each one between 1 and 100, inclusive, — the line numbers. They can be in arbitrary order.
10+
11+
It is guaranteed that Arkady's information is consistent, i.e. there is at least one tram line that Arkady could take.
12+
13+
Output
14+
Print all tram lines that Arkady could be in, in arbitrary order.
15+
16+
Examples
17+
inputCopy
18+
3
19+
3 1 4 6
20+
2 1 4
21+
5 10 5 6 4 1
22+
outputCopy
23+
1 4
24+
inputCopy
25+
5
26+
1 1
27+
10 10 9 8 7 100 5 4 3 99 1
28+
5 1 2 3 4 5
29+
5 4 1 3 2 5
30+
4 10 1 5 3
31+
outputCopy
32+
1
33+
Note
34+
Consider the first example. Arkady woke up three times. The first time he saw a stop with lines 1, 4, 6. The second time he saw a stop with lines 1, 4. The third time he saw a stop with lines 10, 5, 6, 4 and 1. He can be in a tram of one of two lines: 1 or 4.
35+
*/
36+
37+
38+
39+
40+
#include<bits/stdc++.h>
41+
using namespace std;
42+
43+
int main(){
44+
ios_base::sync_with_stdio(false);
45+
cin.tie(NULL);
46+
47+
int n;
48+
cin >> n;
49+
50+
unordered_map <int, int> mp;
51+
52+
for (int i = 0; i < n; i++) {
53+
int t;
54+
cin >> t;
55+
56+
while (t--) {
57+
int a;
58+
cin >> a;
59+
mp[a]++;
60+
}
61+
}
62+
63+
for (auto &it: mp) {
64+
if (it.second == n) cout << it.first << " ";
65+
}
66+
67+
return 0;
68+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/*
2+
You are developing a project to build a new data center. The data center will be a rectangle with an area of exactly n square meters. Each side of the data center must be an integer.
3+
4+
Your goal is to minimize the impact of the external environment on the data center. For this reason, you want to minimize the length of the perimeter of the data center (that is, the sum of the lengths of its four sides).
5+
6+
What is the minimum perimeter of a rectangular data center with an area of exactly n square meters, if the lengths of all its sides must be integers?
7+
8+
Input
9+
The first and only line of the input contains an integer n (1=n=105), where n is the area of the data center in square meters.
10+
11+
Output
12+
Print the required minimum perimeter in meters.
13+
14+
Examples
15+
inputCopy
16+
36
17+
outputCopy
18+
24
19+
inputCopy
20+
13
21+
outputCopy
22+
28
23+
inputCopy
24+
1
25+
outputCopy
26+
4
27+
Note
28+
In the first example, the required shape of the data center is 6×6 square. Its area is 36 and the perimeter is 6+6+6+6=24.
29+
30+
In the second example, the required shape of the data center is 1×13 rectangle. Its area is 13 and the perimeter is 1+13+1+13=28.
31+
32+
In the third example, the required shape of the data center is 1×1 square. Its area is 1 and the perimeter is 1+1+1+1=4.
33+
*/
34+
35+
36+
37+
/*
38+
#include<bits/stdc++.h>
39+
using namespace std;
40+
41+
int main(){
42+
ios_base::sync_with_stdio(false);
43+
cin.tie(NULL);
44+
45+
int n;
46+
cin >> n;
47+
48+
vector <int> factor;
49+
50+
for (int i = 1; i * i <= n; i++) {
51+
if (n % i == 0) {
52+
factor.push_back(i);
53+
factor.push_back(n / i);
54+
}
55+
}
56+
57+
int res = INT_MAX;
58+
59+
for (auto &x: factor) {
60+
int l = x;
61+
int b = n / x;
62+
if (l * b == n) res = min(res, 2 * (l + b));
63+
}
64+
65+
cout << res;
66+
67+
return 0;
68+
}
69+
70+
*/
71+
72+
73+
74+
75+
76+
77+
#include<bits/stdc++.h>
78+
using namespace std;
79+
80+
int main(){
81+
ios_base::sync_with_stdio(false);
82+
cin.tie(NULL);
83+
84+
int n;
85+
cin >> n;
86+
87+
int res = INT_MAX;
88+
89+
for (int i = 1; i * i <= n; i++) {
90+
if (n % i == 0) {
91+
int l = i;
92+
int b = n / i;
93+
res = min(res, 2 * (l + b));
94+
}
95+
}
96+
97+
cout << res;
98+
99+
return 0;
100+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
Sherlock Holmes and Dr. Watson played some game on a checkered board n?×?n in size. During the game they put numbers on the board's squares by some tricky rules we don't know. However, the game is now over and each square of the board contains exactly one number. To understand who has won, they need to count the number of winning squares. To determine if the particular square is winning you should do the following. Calculate the sum of all numbers on the squares that share this column (including the given square) and separately calculate the sum of all numbers on the squares that share this row (including the given square). A square is considered winning if the sum of the column numbers is strictly greater than the sum of the row numbers.
3+
4+
5+
For instance, lets game was ended like is shown in the picture. Then the purple cell is winning, because the sum of its column numbers equals 8?+?3?+?6?+?7?=?24, sum of its row numbers equals 9?+?5?+?3?+?2?=?19, and 24?>?19.
6+
7+
Input
8+
The first line contains an integer n (1?=?n?=?30). Each of the following n lines contain n space-separated integers. The j-th number on the i-th line represents the number on the square that belongs to the j-th column and the i-th row on the board. All number on the board are integers from 1 to 100.
9+
10+
Output
11+
Print the single number — the number of the winning squares.
12+
13+
Examples
14+
inputCopy
15+
1
16+
1
17+
outputCopy
18+
0
19+
inputCopy
20+
2
21+
1 2
22+
3 4
23+
outputCopy
24+
2
25+
inputCopy
26+
4
27+
5 7 8 4
28+
9 5 3 2
29+
1 6 6 4
30+
9 5 7 3
31+
outputCopy
32+
6
33+
Note
34+
In the first example two upper squares are winning.
35+
36+
In the third example three left squares in the both middle rows are winning:
37+
38+
5 7 8 4
39+
9 5 3 2
40+
1 6 6 4
41+
9 5 7 3
42+
*/
43+
44+
45+
46+
47+
#include<bits/stdc++.h>
48+
using namespace std;
49+
50+
int main(){
51+
ios_base::sync_with_stdio(false);
52+
cin.tie(NULL);
53+
54+
int n;
55+
cin >> n;
56+
57+
int a[n][n];
58+
59+
for (int i = 0; i <n; i++) {
60+
for (int j = 0; j < n; j++){
61+
cin >> a[i][j];
62+
}
63+
}
64+
65+
int row[n] = {0};
66+
int col[n] = {0};
67+
68+
for (int i = 0; i <n; i++) {
69+
for (int j = 0; j < n; j++){
70+
row[i] += a[i][j];
71+
col[j] += a[i][j];
72+
}
73+
}
74+
75+
int res = 0;
76+
77+
for (int i = 0; i <n; i++) {
78+
for (int j = 0; j < n; j++){
79+
if (col[j] > row[i]) res++;
80+
}
81+
}
82+
83+
cout << res;
84+
85+
return 0;
86+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an n?×?n size matrix, where n is odd. The Smart Beaver considers the following matrix elements good:
3+
4+
Elements of the main diagonal.
5+
Elements of the secondary diagonal.
6+
Elements of the "middle" row — the row which has exactly rows above it and the same number of rows below it.
7+
Elements of the "middle" column — the column that has exactly columns to the left of it and the same number of columns to the right of it.
8+
The figure shows a 5?×?5 matrix. The good elements are marked with green.
9+
Help the Smart Beaver count the sum of good elements of the given matrix.
10+
11+
Input
12+
The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0?=?aij?=?100) separated by single spaces — the elements of the given matrix.
13+
14+
The input limitations for getting 30 points are:
15+
16+
1?=?n?=?5
17+
The input limitations for getting 100 points are:
18+
19+
1?=?n?=?101
20+
Output
21+
Print a single integer — the sum of good matrix elements.
22+
23+
Examples
24+
inputCopy
25+
3
26+
1 2 3
27+
4 5 6
28+
7 8 9
29+
outputCopy
30+
45
31+
inputCopy
32+
5
33+
1 1 1 1 1
34+
1 1 1 1 1
35+
1 1 1 1 1
36+
1 1 1 1 1
37+
1 1 1 1 1
38+
outputCopy
39+
17
40+
Note
41+
In the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure.
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;
54+
cin >> n;
55+
56+
int a[n][n];
57+
58+
for (int i = 0; i < n; i++) {
59+
for (int j = 0; j < n; j++) {
60+
cin >> a[i][j];
61+
}
62+
}
63+
64+
long long sum = 0;
65+
66+
for (int i = 0; i < n; i++) {
67+
for (int j = 0; j < n; j++) {
68+
if (i == j)
69+
sum = sum + a[i][j] + a[i][n - j - 1];
70+
}
71+
}
72+
73+
for (int i = 0; i < n; i++) {
74+
sum = sum + a[i][n / 2] + a[n / 2][i];
75+
}
76+
77+
cout << sum - 3 * a[n / 2][n / 2];
78+
79+
return 0;
80+
}

0 commit comments

Comments
 (0)