Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7df3bcd

Browse files
accepted
1 parent e6ede9a commit 7df3bcd

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#include <vector>
2+
#include <iostream>
3+
4+
using namespace std;
5+
6+
int main() {
7+
int n, d, l, r, c;
8+
9+
/*
10+
d = 0 = horizontally
11+
d = 1 = vertically
12+
13+
L = size of the ship
14+
15+
r, c = row, and col position
16+
17+
if vertical = r + l - 1, c;
18+
if horizontal = r, c + l -1;
19+
20+
*/
21+
22+
vector<vector<int> > v (10, vector<int>(10, 0));
23+
24+
cin >> n;
25+
26+
int ok = true;
27+
while(n--) {
28+
cin >> d >> l >> r >> c;
29+
if (d == 0) {
30+
// out of the ship
31+
if (l - 1 + c > 10) {
32+
ok = false;
33+
} else {
34+
for (int i = (c - 1); i < (c + (l - 1)); i++) {
35+
if(!v[r - 1][i]) {
36+
v[r - 1][i] = 1;
37+
} else {
38+
ok = false;
39+
}
40+
}
41+
}
42+
} else {
43+
if (l - 1 + r > 10) {
44+
ok = false;
45+
} else {
46+
for (int i = (r - 1); i < (r + (l - 1)); i++) {
47+
if(!v[i][c - 1]) {
48+
v[i][c - 1] = 1;
49+
} else {
50+
ok = false;
51+
}
52+
}
53+
54+
}
55+
}
56+
57+
}
58+
59+
60+
if (ok) {
61+
cout << "Y\n";
62+
} else {
63+
cout << "N\n";
64+
}
65+
return 0;
66+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /