Skip to content

Commit 1c95852

Browse files
committed
Add problems from URI
1 parent 57bb1f5 commit 1c95852

File tree

3 files changed

+136
-0
lines changed

3 files changed

+136
-0
lines changed

URI/1533.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
4+
int main() {
5+
int n;
6+
while (cin >> n) {
7+
if (!n) break;
8+
vector< pair<int, int> > v(n);
9+
for (int i = 0; i < n; ++i) {
10+
int t;
11+
cin >> t;
12+
v[i] = {t, i + 1};
13+
}
14+
15+
sort(v.begin(), v.end());
16+
reverse(v.begin(), v.end());
17+
cout << v[1].second << endl;
18+
}
19+
20+
return 0;
21+
}

URI/1591.cpp

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
4+
int count (string s, string r) {
5+
int pos = 0;
6+
int tot = 0;
7+
while (s.find(r, pos) != string::npos) {
8+
int ind = s.find(r, pos);
9+
pos = ind + 1;
10+
tot ++;
11+
}
12+
13+
return tot;
14+
}
15+
16+
int main() {
17+
int t;
18+
cin >> t;
19+
20+
for (int i = 0; i < t; ++i) {
21+
int n, m;
22+
cin >> n >> m;
23+
24+
map<char, int> mapa;
25+
char mat[n][m];
26+
vector<string> rows;
27+
vector<string> cols(m);
28+
for (int j = 0; j < n; ++j) {
29+
string s;
30+
for (int k = 0; k < m; ++k) {
31+
cin >> mat[j][k];
32+
s.push_back(mat[j][k]);
33+
cols[k].push_back(mat[j][k]);
34+
mapa[mat[j][k]] ++;
35+
}
36+
rows.push_back(s);
37+
}
38+
39+
int q;
40+
cin >> q;
41+
for (int j = 0; j < q; ++j) {
42+
string s;
43+
cin >> s;
44+
45+
int ans = 0;
46+
if (s.size() > 1) {
47+
for (int k = 0; k < rows.size(); ++k) {
48+
ans += count(rows[k], s);
49+
}
50+
51+
for (int k = 0; k < cols.size(); ++k) {
52+
ans += count(cols[k], s);
53+
}
54+
}
55+
else {
56+
ans += mapa[s[0]];
57+
}
58+
59+
cout << ans << endl;
60+
}
61+
62+
}
63+
64+
return 0;
65+
}

URI/1905.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
4+
int ans;
5+
int n;
6+
char mat[11][11];
7+
int visited[11][11];
8+
9+
bool check(int x, int y) {
10+
return x < 0 || x >= n || y < 0 || y >= n;
11+
}
12+
13+
void dfs(int x, int y) {
14+
if (!visited[x][y]) {
15+
visited[x][y] = true;
16+
17+
if (x == n - 1 && y == n - 1) ans = true;
18+
19+
int dx[] = {-1, 0, 1, 0};
20+
int dy[] = {0, 1, 0, -1};
21+
for (int i = 0; i < 4; ++i) {
22+
int xx = x + dx[i];
23+
int yy = y + dy[i];
24+
if (!check(xx, yy) && mat[xx][yy] == '0')
25+
dfs(xx, yy);
26+
}
27+
}
28+
}
29+
30+
int main() {
31+
int t;
32+
cin >> t;
33+
34+
n = 5;
35+
for (int i = 0; i < t; ++i) {
36+
for (int j = 0; j < n; ++j) {
37+
for (int k = 0; k < n; ++k) {
38+
cin >> mat[j][k];
39+
}
40+
}
41+
42+
memset(visited, 0, sizeof visited);
43+
ans = false;
44+
dfs(0, 0);
45+
if (ans) cout << "COPS" << endl;
46+
else cout << "ROBBERS" << endl;
47+
}
48+
49+
return 0;
50+
}

0 commit comments

Comments
 (0)