-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
13-mj111 #222
13-mj111 #222
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ํ....
์ฒ์์๋ ๊ฒฉ์ ์นธ ํฌ๊ธฐ๊ฐ ์ต๋ 100 x 100 ์ธ ๊ฑฐ ๋ณด๊ณ ๋งค ๋ฐ๋ณต๋ง๋ค ๊ฒฉ์ ์ซ ํ์ด์ ์์ด ์ฎ๊ธฐ๊ณ ์ก์๋จน๋ ์ฒ๋ฆฌ๋ฅผ ํ๋๋ก ์์ฑํ๋๋ฐ, ์ต๋ 14%์ฏค์ธ๊ฐ์์ ์๊ฐ์ด๊ณผ๋๋ค์...
์ด๋ก ์ ๋์์ ์ฎ๊ธฐ๋ ๊ฑฐ 100๋ฒ x ๋งค ์ด๋๋ง๋ค ์์ด ์ก๊ธฐ ์ต๋ 100์นธ x ์์ด ์ด๋์ ์ํ ๊ทธ๋ฆฌ๋ ํ๊ธฐ 100 x 100... ๋ฐ์ ธ๋ณด๋ ์ฐ์ฐ 1์ต๋ฒ ๋๊ธธ ์๋ ์๊ฒ ๋ค ์ถ๋๋ผ๊ตฌ์...
๊ทธ๋์ ์์ด ์ ๋ณด๋ฅผ ๋ด๋ ๋ฐฐ์ด์ ์์ฑํด์ ๊ฑ๋ค๋ค๋ง ํ๋๋ก ์์ ํ๋ ์๊ฐ ์์ ํต๊ณผํ๋ค์ ํ...
๋นก๊ตฌํ์ ์ ๋ง ์ซ์ต๋๋ค...
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const vector<pair<int, int>> Offset{ {0, 0}, { -1, 0 }, {1, 0}, {0, 1}, {0, -1} };
int R, C, M;
inline bool OutOfBound(int r, int c)
{
return !(1 <= r && r <= R && 1 <= c && c <= C);
}
struct FShark
{
int R, C;
int Speed;
int Direction;
int Size;
bool IsDead;
FShark(int InR, int InC, int InS, int InD, int InZ)
: R(InR)
, C(InC)
, Speed(InS)
, Direction(InD)
, Size(InZ)
, IsDead(false)
{
}
};
vector<FShark*> Sharks;
vector<vector<int>> Grid;
void Move()
{
for (FShark* Shark : Sharks)
{
if (Shark->IsDead) continue;
int Speed = Shark->Speed, Direction = Shark->Direction, Size = Shark->Size;
int r = Shark->R, c = Shark->C;
Grid[r][c] = -1;
int nr, nc;
while (true)
{
nr = r + Speed * Offset[Direction].first;
nc = c + Speed * Offset[Direction].second;
if (!OutOfBound(nr, nc))
{
break;
}
switch (Direction)
{
case 1:
Speed -= (r - 1);
r = 1;
Direction = 2;
break;
case 2:
Speed -= R - r;
r = R;
Direction = 1;
break;
case 3:
Speed -= C - c;
c = C;
Direction = 4;
break;
case 4:
Speed -= (c - 1);
c = 1;
Direction = 3;
break;
}
}
Shark->R = nr;
Shark->C = nc;
Shark->Direction = Direction;
}
}
void Update()
{
for (int Index = 0; Index < M; ++Index)
{
FShark* Shark = Sharks[Index];
if (Shark->IsDead) continue;
int R = Shark->R, C = Shark->C;
if (Grid[R][C] == -1)
{
Grid[R][C] = Index;
}
else
{
int OtherIndex = Grid[R][C];
FShark* Other = Sharks[OtherIndex];
if (Shark->Size > Other->Size)
{
Other->IsDead = true;
Grid[R][C] = Index;
}
else
{
Shark->IsDead = true;
}
}
}
}
int main()
{
cin.tie(nullptr)->sync_with_stdio(false);
cin >> R >> C >> M;
Sharks.resize(M);
Grid.assign(R + 1, vector<int>(C + 1, -1));
for (int i = 0; i < M; ++i)
{
int r, c, s, d, z; cin >> r >> c >> s >> d >> z;
Grid[r][c] = i;
Sharks[i] = new FShark(r, c, s, d, z);
}
int Answer = 0;
for (int c = 1; c <= C; ++c)
{
for (int r = 1; r <= R; ++r)
{
const int Index = Grid[r][c];
if (Index > -1)
{
Answer += Sharks[Index]->Size;
Sharks[Index]->IsDead = true;
Grid[r][c] = -1;
break;
}
}
Move();
Update();
}
cout << Answer;
return 0;
}
while(speed-- > 0) { | ||
int nextX = s.x + dx[s.direction]; | ||
int nextY = s.y + dy[s.direction]; | ||
|
||
if(isOutRange(nextX, nextY)) { | ||
s.changeDirection(); | ||
speed++; | ||
continue; | ||
} | ||
|
||
s.x = nextX; | ||
s.y = nextY; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
๋งค ์์ด๋ง๋ค ํ ์นธ์ฉ ์ด๋ ํ์ ์ ์ฃผ๋ ๊ฒ๋ ์๊ฐ๋ณด๋ค ์๊ฐ์ ์ข ์ก์๋จน๋ ๊ฒ ๊ฐ์ต๋๋ค.
์ฒ์์ ์๊ฐ ์์ ํต๊ณผํ ์ฝ๋๊ฐ ๋๋ฆฐ ๊ฒ ์ฝ๊ฐ ์ด ๋ฌธ์ ๋ ์๋ ๊ฒ ๊ฐ์ต๋๋ค.
speed๋ ๋ฐฉํฅ์ ์ด์ฉํด ๋ค์ ์ขํ๋ฅผ ํ ๋ฒ์ ์ป๊ณ , bound๋ฅผ ๋์ด๊ฐ๋ ๊ฒ์ ๋ํ ๋ณด์ ์ ์ฃผ๋ ํ์์ผ๋ก ๋ฐ๋ณต ํ์๋ฅผ ์ค์ด๋ ๊ฒ๋ ์ข์ ๊ฒ ๊ฐ์ต๋๋ค.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์ ๋น์์ ์คํผ๋์ ๋ง์ถฐ์ ํ ํ๊ธฐ๋ ์ธ๋ฑ์ค ๊ณ์ฐํ๊ธฐ ๋ณด๋ค ๊ทธ๋ฅ speed ์์ ๋์ํ๋๋ก ํ๋๊ฒ ๊ณ์ฐํด๋ณด๋ ์๊ฐ ์ด๊ณผ๊ฐ ์๋จ๋ ํฌ๊ธฐ๋ผ์ ๊ทธ๋ฌ๋๊ฑฐ๊ฐ์์!
๋นก๊ตฌํ ๋นจ๋ฆฌ ํธ๋๋ฐ ์ง์คํด์ ์ ์ ์ด ์์์ด์ ใ ใ ใ ใ ใ ใ
if(copyMap[s.x][s.y] != 0) { | ||
Shark op = sharks.get(copyMap[s.x][s.y] - 1); | ||
if(s.size < op.size) { | ||
s.alive = false; | ||
continue; | ||
} else { | ||
op.alive = false; | ||
} | ||
} | ||
|
||
copyMap[s.x][s.y] = s.number; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
๊ฐ ์์ด๊ฐ ์ขํ ์ ๋ณด์ ์ด์๋๊ฐ/์ฃฝ์๋๊ฐ ์ ๋ณด๋ ๋ค๊ณ ์์ผ๋,
Move ํจ์ ๋ด์์๋ ์์ด๋ฅผ ์ฎ๊ธฐ๋ ๊ธฐ๋ฅ๋ง ํ๊ณ ์์ด ์ก์๋จน๋ ์ฒ๋ฆฌ๋ ๋ณ๋์ ํจ์์์ ์ฒ๋ฆฌํ๊ฒ ํ๋ ๊ฒ๋ ์ข์ ๊ฒ ๊ฐ์ต๋๋ค.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
๋ฐฐ์ด์ ์์ด ์ ๋ณด๋ฅผ ๋ฃ๊ณ ,
๋์์์ด ์๋ ์ด์์ ๊ฐ์ฅ ๋
์ ๊ฐ๊น์ด ์์ด๋ฅผ ์ก์ต๋๋ค
๊ทธ ํ ์ด์์๋ ์์ด ์๋งํผ popํด์ค์
์์ด์ ์์น์ ์์ด์ ํฌ๊ธฐ๊ฐ ๊ทธ๋๋ก ์ธ์ง ํ์ธํ๋ ๊ณผ์ ์ผ๋ก ์์ฌ์ฌ๋ถ๋ฅผ ํ์ธํ๊ณ
์์ด๋ฅผ ์ด๋์ํค๋ ๊ฒ์ ๋ฐ๋ณตํด์ ํด๊ฒฐํ์ต๋๋ค!
์ ์ฒด ์ฝ๋
from collections import deque
input = open("input.txt").readline
R, C, M = map(int,input().split())
shark_cnt = M
dq = deque([])
table = [[0]*C for _ in range(R)]
for _ in range(M):
r, c, s, d, z = map(int, input().split())
if not s:
s = s % (2*R-2) if d <= 2 else s % (2*C-2)
table[r-1][c-1] = max(table[r-1][c-1], z)
dq.append((r-1, c-1, s, d, z))
result = 0
for i in range(C):
# fishing
for j in range(R):
if not table[j][i]:
continue
result += table[j][i]
table[j][i] = 0
break
# shark_check
for _ in range(shark_cnt):
r, c, s, d, z = dq.popleft()
if not table[r][c] == z:
shark_cnt -= 1
continue
else:
table[r][c] = 0
dq.append(( r, c, s, d, z ))
# shark_move
for _ in range(shark_cnt):
r, c, s, d, z = dq.popleft()
# 1 : ์ / 2 : ์๋ / 3 : ์ค๋ฅธ์ชฝ / 4 : ์ผ์ชฝ
if d <= 2:
r += -s if d==1 else s
while not 0 <= r < R:
r = abs(r) if r < 0 else 2*R-2-r
d = 1 if d==2 else 2
else:
c += s if d == 3 else -s
while not 0 <= c < C:
c = abs(c) if c <0 else 2*C-2-c
d = 3 if d == 4 else 4
table[r][c] = max(table[r][c], z)
dq.append((r, c, s, d, z))
print(result)
๋๋ฆ ์ค๋ฌด์คํ๊ฒ ํ์ด์ ๊ธฐ๋ถ์ด ์ข๋ค์ :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์กฐ๊ธ ๊ตฌํํ๋ค๊ฐ ๋๋ฌด ๋ณต์กํด์ ํฌ๊ธฐํ๋ค์.. ์๊ณ ๋ง์ผ์
จ์ต๋๋ค!!
์์ด๊ฐ ๋์ ๋ค๋ค๋์ ๋ ๋ฐฉํฅ ๋ฐ๊ฟ์ฃผ๋ ๊ฒ๋ ์ผ์ผ์ด ํด์ฃผ์ด์ผ ํ๊ณ , ๊ทธ๋ฆฌ๊ณ ๋ฐ๋ ์์น๋ ๊ณ์ ๊ฐฑ์ ํด์ฃผ์ด์ผ ํ๋๊ฒ ์๊ฐ๋ณด๋ค ์ด๋ ต๋ค์.
์ด๋ฟ๋ง ์๋๋ผ ๊ฐ์ ์์น์ ์ฌ๋ฌ ์์ด๊ฐ ์์ผ๋ฉด ํฌ๊ธฐ ๋น๊ตํด์ฃผ๋ ๊ฑฐ๋ ๊ฐ์ฅ ์์ ์์ด๊ฐ ๋์๋์ด ์์ด์ง๋ ๊ฒ๋ ์๊ฐํด์ผํ๊ณ ์ฌ๋ฌ๋ชจ๋ก ๋ณต์กํ ๋ฌธ์ ๋ค์..๐ญ
๐ ๋ฌธ์ ๋งํฌ
๋ฐฑ์ค - ๋์์
https://www.acmicpc.net/problem/17143
โ๏ธ ์์๋ ์๊ฐ
1์๊ฐ 30๋ถ
โจ ์๋ ์ฝ๋
ํด๋น ๋ฌธ์ ๋ ์์ด๊ฐ ๋ฐฉํฅ๊ณผ ํฌ๊ธฐ์ ๋ฐ๋ผ ์ด๋ํ๋ ์์ค์ ์ผ์ชฝ ์ด์์ ์ค๋ฅธ์ชฝ ์ด๋ก ์์ด๋ฅผ ์ก๋ ๋ฌธ์ ์ ๋๋ค!
์ดํ, ์ก์ ์์ด ํฌ๊ธฐ์ ํฉ์ ์ถ๋ ฅํ๋ฉด ๋ฉ๋๋ค.
๋จผ์ ์ฃผ์ด์ง ์ ๋ ฅ์ ๋ฐ์์ฃผ๊ณ
ํ ์ด์ฉ ์ก์ผ๋ฉฐ, ์์ด๋ฅผ ์ด๋์ํค๋ฉด ๋ฉ๋๋ค.
์์ด๋ฅผ ์ก์ ๋๋ ์ฃผ์ด์ง ์ด๊ฐ์ ์ํด ์์ด๋ฅผ ์์งํฉ๋๋ค.
์ฌ๊ธฐ์ ์ค์ํ ์ ์, ํด๋น ์์ด๋ฅผ ๋ฌดํจํ ํด์ผํ๋ค๋ ์ ์ ๋๋ค!
๊ทธ๋ ๊ธฐ ๋๋ฌธ์ ์์ด๋ฅผ ์ฃฝ์๋ค ํ์ํ๊ณ
์ฃผ์ด์ง map์์ ์ง์์ค๋๋ค.
์์ด๋ฅผ ์ด๋์ํค๋ ๋ฐฉ๋ฒ์ ์ฃผ์ด์ง ๋ฐฉํฅ์ผ๋ก ์๋๋งํผ ์์ง์ด๋๋ก ํฉ๋๋ค.
์ฌ๊ธฐ์ ์ฃผ์ํ ์ ์ ์์ด์ ์ด๋๋ฐฉํฅ์ ๋ฐ๋ผ ์์ง์ด๋ค ๋ฒฝ์ ๋ถ๋ชํ ๊ฒฝ์ฐ ๋ฐฉํฅ์ ๋ฐ๋๋ก ํ๊ณ ์ด๋์์ผ์ผํ๋ค๋ ์ ์ ๋๋ค!
๐ ์๋กญ๊ฒ ์๊ฒ๋ ๋ด์ฉ
๋ฌธ์ ๋ฅผ ์ฝ์ผ๋ฉด์ ์๊ตฌ์ฌํญ์ ์ป์ด๋ด๋๋ฐ ์กฐ๊ธ ํ๋ค์์ต๋๋ค..
๋๋ถ์ด Java๋ก ๊ตฌํํ๋ ์กฐ๊ธ ๋ ์ด๋ ค์ด๊ฒ๋ ๋๊ปด์ก๋ค์ ใ (์ด์ ๋ ํ์ด์ฌ์ผ๋ก ๊ฐ๊ฒ ์ต๋๋ค)
๋นก๊ตฌํ์ ๊ตฌํ๋ณด๋ค, ์๊ตฌ์ฌํญ์ ์ ์ดํดํ๋๊ฒ ๊ด๊ฑด์์ ์ฒด๊ฐํ์ต๋๋ค.