Skip to content

Commit 7e53805

Browse files
committed
local
1 parent 891e4ea commit 7e53805

File tree

5 files changed

+203
-0
lines changed

5 files changed

+203
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#include<iostream>
2+
using namespace std;
3+
4+
int main() {
5+
int arr[100][100];
6+
int n, m;
7+
8+
cin >> n >> m;
9+
for (int i = 0; i < n; ++i) {
10+
for (int j = 0; j < m; ++j) {
11+
cin >> arr[i][j];
12+
}
13+
}
14+
15+
int q;
16+
cin >> q;
17+
18+
while (q--) {
19+
int r1, r2;
20+
cin >> r1 >> r2;
21+
r1--;
22+
r2--;
23+
24+
bool is_smaller = true;
25+
for (int j = 0; j < m; ++j)
26+
is_smaller &= (arr[r1][j] < arr[r2][j]);
27+
28+
if (is_smaller)
29+
cout << "YES\n";
30+
else
31+
cout << "NO\n";
32+
}
33+
34+
return 0;
35+
}
36+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include<iostream>
2+
using namespace std;
3+
4+
int main() {
5+
int n, upper = 0, lower = 0, val;
6+
// No need to create matrix!
7+
cin >> n;
8+
for (int i = 0; i < n; ++i) {
9+
for (int j = 0; j < n; ++j) {
10+
cin >> val;
11+
12+
if (i <= j)
13+
lower += val;
14+
15+
if (i >= j)
16+
upper += val;
17+
}
18+
}
19+
cout << upper << "\n";
20+
cout << lower << "\n";
21+
22+
return 0;
23+
}
24+
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#include<iostream>
2+
using namespace std;
3+
4+
int main() {
5+
int arr[100][100];
6+
int n, m;
7+
8+
cin >> n >> m;
9+
for (int i = 0; i < n; ++i)
10+
for (int j = 0; j < m; ++j)
11+
cin >> arr[i][j];
12+
13+
//{ d, r, u, l, ul, dr, ur, dl };
14+
int di[8] = { 1, 0, -1, 0, -1, 1, -1, 1 };
15+
int dj[8] = { 0, 1, 0, -1, -1, 1, 1, -1 };
16+
17+
for (int i = 0; i < n; ++i) {
18+
for (int j = 0; j < m; ++j) {
19+
bool valid_mountain = true; // if no neighbors, will remain true!
20+
21+
// check the 8 neighbors using dir array
22+
for (int d = 0; d < 8 && valid_mountain; ++d) {
23+
int ni = i + di[d];
24+
int nj = j + dj[d];
25+
26+
if (ni < 0 || nj >= n || nj < 0 || nj >= m)
27+
continue; // outside borders
28+
29+
valid_mountain &= (arr[i][j] > arr[ni][nj]);
30+
}
31+
32+
if (valid_mountain)
33+
cout << i << " " << j << "\n";
34+
}
35+
}
36+
37+
return 0;
38+
}
39+
/**
40+
important test
41+
1 1
42+
1
43+
44+
answer
45+
0 0
46+
*/
47+
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#include<iostream>
2+
using namespace std;
3+
4+
int main() {
5+
int arr1[100][100];
6+
int arr2[100][100];
7+
int n, m;
8+
9+
cin >> n >> m;
10+
for (int i = 0; i < n; ++i)
11+
for (int j = 0; j < m; ++j)
12+
cin >> arr1[i][j];
13+
14+
for (int i = 0; i < n; ++i)
15+
for (int j = 0; j < m; ++j)
16+
arr2[j][i] = arr1[i][j];
17+
18+
for (int i = 0; i < m; ++i) {
19+
for (int j = 0; j < n; ++j)
20+
cout << arr2[i][j] << " ";
21+
cout << "\n";
22+
}
23+
24+
return 0;
25+
}
26+
/**
27+
28+
3 4
29+
8 16 9 52
30+
3 15 27 6
31+
14 25 29 10
32+
33+
output
34+
8 3 14
35+
16 15 25
36+
9 27 29
37+
52 6 10
38+
39+
40+
*/
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#include<iostream>
2+
using namespace std;
3+
4+
int main() {
5+
bool is_prime[100][100] = { 0 };
6+
int n, m, val;
7+
8+
cin >> n >> m;
9+
for (int i = 0; i < n; ++i)
10+
for (int j = 0; j < m; ++j) {
11+
cin >> val;
12+
13+
// let's compute is prime once NOT with every query. Also no need for main array
14+
if (val <= 1)
15+
continue;
16+
17+
is_prime[i][j] = 1;
18+
for (int k = 2; k < val; ++k) {
19+
if (val % k == 0) {
20+
is_prime[i][j] = 0;
21+
break;
22+
}
23+
}
24+
}
25+
26+
int q, si, sj, rs, cls;
27+
cin >> q;
28+
29+
while (q--) {
30+
cin >> si >> sj >> rs >> cls;
31+
int cnt = 0;
32+
33+
for (int i = si; i <= si + rs - 1; ++i)
34+
for (int j = sj; j <= sj + cls - 1; ++j)
35+
cnt += is_prime[i][j];
36+
37+
cout << cnt << "\n";
38+
}
39+
40+
return 0;
41+
}
42+
/**
43+
44+
3 4
45+
8 16 9 52
46+
3 15 27 6
47+
14 25 29 10
48+
49+
output
50+
8 3 14
51+
16 15 25
52+
9 27 29
53+
52 6 10
54+
55+
56+
*/

0 commit comments

Comments
 (0)