-
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
16-mjj111 #229
base: main
Are you sure you want to change the base?
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.
2μκ° λ°κ³ GG μ³€μ΅λλ€..
λͺ
μ€λ μ½λ λ³΄κ³ κ°μμμλλ°λ μλλ€μ γ
λμ€μ μ¬λμ νκ² μ΅λλ€...
νλ¦° μ 체 μ½λ
#include <iostream>
#include <vector>
#include <set>
#include <unordered_map>
#include <algorithm>
using namespace std;
constexpr int MAX_DISTANCE = 2500;
const vector<pair<int, int>> SantaOffset{{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
const vector<pair<int, int>> RudolphOffset{{-1, 0}, {-1, 1}, {0, 1}, {1, 1}, {1, 0}, {1, -1}, {0, -1}, {-1, -1}};
inline int GetDistanceBetween(int r1, int c1, int r2, int c2)
{
return (r1 - r2) * (r1 - r2) + (c1 - c2) * (c1 - c2);
}
struct FSanta
{
int Power;
int Number;
int R, C;
bool bOut;
int Score;
int StunnedTurn;
FSanta(int InPower, int InNumber, int InR, int InC)
: Power(InPower)
, Number(InNumber)
, R(InR)
, C(InC)
, bOut(false)
, Score(0)
, StunnedTurn(0)
{}
};
struct FRudolph
{
int Power;
int R, C;
FRudolph(int InPower, int InR, int InC)
: Power(InPower)
, R(InR)
, C(InC)
{}
};
int N, M, P, C, D;
vector<vector<int>> Board;
FRudolph* Rudolph;
vector<FSanta*> SantaList;
unordered_map<int, FSanta*> SantaMap;
inline bool OutOfBound(int r, int c)
{
return !(1 <= r && r <= N && 1 <= c && c <= N);
}
inline bool bAllSantasOut()
{
for(const FSanta* Santa : SantaList)
{
if(false == Santa->bOut)
{
return false;
}
}
return true;
}
void Interaction(FSanta* InSanta, const int dr, const int dc)
{
if(Board[InSanta->R][InSanta->C] == 0)
{
Board[InSanta->R][InSanta->C] = InSanta->Number;
return;
}
FSanta* Santa = SantaMap[Board[InSanta->R][InSanta->C]];
Board[InSanta->R][InSanta->C] = InSanta->Number;
Santa->R += dr;
Santa->C += dc;
if(OutOfBound(Santa->R, Santa->C))
{
Santa->bOut = true;
return;
}
Interaction(Santa, dr, dc);
}
FSanta* GetNearestSanta()
{
vector<FSanta*> Candidates;
int NearestDistance = MAX_DISTANCE;
for(FSanta* Santa : SantaList)
{
if(Santa->bOut)
{
continue;
}
int Distance = GetDistanceBetween(Rudolph->R, Rudolph->C, Santa->R, Santa->C);
if(Distance < NearestDistance)
{
Candidates.clear();
NearestDistance = Distance;
Candidates.emplace_back(Santa);
}
else if(Distance == NearestDistance)
{
Candidates.emplace_back(Santa);
}
}
sort(Candidates.begin(), Candidates.end(),
[&](const FSanta* Lhs, const FSanta* Rhs)
{
if(Lhs->R == Rhs->R) return Lhs->C > Rhs->C;
return Lhs->R > Rhs->R;
});
return Candidates.front();
}
void MoveRudolph(int InTurn)
{
FSanta* NearestSanta = GetNearestSanta();
int NearestDistance = MAX_DISTANCE;
int NearestDirection = -1;
for(int Dir = 0; Dir < RudolphOffset.size(); ++Dir)
{
int nr = Rudolph->R + RudolphOffset[Dir].first;
int nc = Rudolph->C + RudolphOffset[Dir].second;
if(OutOfBound(nr, nc))
{
continue;
}
int Distance = GetDistanceBetween(nr, nc, NearestSanta->R, NearestSanta->C);
if(Distance < NearestDistance)
{
NearestDirection = Dir;
NearestDistance = Distance;
}
}
int nr = Rudolph->R + RudolphOffset[NearestDirection].first;
int nc = Rudolph->C + RudolphOffset[NearestDirection].second;
Board[Rudolph->R][Rudolph->C] = 0;
Rudolph->R = nr, Rudolph->C = nc;
Board[Rudolph->R][Rudolph->C] = -1;
if(nr == NearestSanta->R && nc == NearestSanta->C)
{
NearestSanta->Score += Rudolph->Power;
NearestSanta->StunnedTurn = InTurn;
NearestSanta->R += RudolphOffset[NearestDirection].first * Rudolph->Power;
NearestSanta->C += RudolphOffset[NearestDirection].second * Rudolph->Power;
if(OutOfBound(NearestSanta->R, NearestSanta->C))
{
NearestSanta->bOut = true;
}
else
{
Interaction(NearestSanta, RudolphOffset[NearestDirection].first, RudolphOffset[NearestDirection].second);
}
}
}
void MoveSanta(int InTurn)
{
for(FSanta* Santa : SantaList)
{
if(Santa->bOut || InTurn < Santa->StunnedTurn + 2)
{
continue;
}
int NearestDistance = GetDistanceBetween(Rudolph->R, Rudolph->C, Santa->R, Santa->C);
int NearestDirection = -1;
for(int Dir = 0; Dir < SantaOffset.size(); ++Dir)
{
int nr = Santa->R + SantaOffset[Dir].first;
int nc = Santa->C + SantaOffset[Dir].second;
if(OutOfBound(nr, nc) || Board[nr][nc] >= 1)
{
continue;
}
int Distance = GetDistanceBetween(Rudolph->R, Rudolph->C, nr, nc);
if(Distance < NearestDistance)
{
NearestDistance = Distance;
NearestDirection = Dir;
}
}
if(NearestDirection == -1)
{
continue;
}
int nr = Santa->R + SantaOffset[NearestDirection].first;
int nc = Santa->C + SantaOffset[NearestDirection].second;
Board[nr][nc] = 0;
Santa->R = nr, Santa->C = nc;
if(Board[nr][nc] == 0)
{
Board[nr][nc] = Santa->Number;
}
else if(Board[nr][nc] == -1)
{
Santa->Score += Santa->Power;
Santa->StunnedTurn = InTurn;
int Reverse = (NearestDirection + 2) % 4;
int dr = SantaOffset[Reverse].first;
int dc = SantaOffset[Reverse].second;
nr = Santa->R + dr * Santa->Power;
nc = Santa->C + dc * Santa->Power;
if(OutOfBound(nr, nc))
{
Santa->bOut = true;
}
else
{
Santa->R = nr;
Santa->C = nc;
Interaction(Santa, dr, dc);
}
}
}
}
int main()
{
cin.tie(nullptr)->sync_with_stdio(false);
cin >> N >> M >> P >> C >> D;
int Rr, Rc; cin >> Rr >> Rc;
Rudolph = new FRudolph(C, Rr, Rc);
Board.assign(N + 1, vector<int>(N + 1, 0));
Board[Rr][Rc] = -1;
for(int i = 0; i < P; ++i)
{
int Pn, Sr, Sc; cin >> Pn >> Sr >> Sc;
Board[Sr][Sc] = Pn;
FSanta* Santa = new FSanta(D, Pn, Sr, Sc);
SantaList.push_back(Santa);
SantaMap[Pn] = Santa;
}
sort(SantaList.begin(), SantaList.end(),
[&](const FSanta* Lhs, const FSanta* Rhs)
{
return Lhs->Number < Rhs->Number;
});
for(int Turn = 1; false == bAllSantasOut() && Turn <= M; ++Turn)
{
MoveRudolph(Turn);
MoveSanta(Turn);
for(FSanta* Santa : SantaList)
{
if(false == Santa->bOut)
{
Santa->Score++;
}
}
}
for(const FSanta* Santa : SantaList)
{
cout << Santa->Score << " ";
}
return 0;
}
μ½λ 보λκΉ λ§€ μ°¨ μμ§μ΄λκ±° print ν΄μ λλ²κΉ νλ©΄, μΆκ° 1μκ°μμ νΈμ€κ±° κ°μλ°μ..? |
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.
루λν 머리 κΉ¨μ§ κ² κ°μμ.... κ·Έλ§ν λμ...γ γ γ
μΆ©λμ΄λ μνΈμμ©νλλ°μ, 루λνκ° λͺ©νλ₯Ό μ νν λ‘ λλ Έλμ§ μ£½μ κ² κ°μμ, ν¬κΈ°νμ΄λλ€.π₯²
ν¬κΈ°...
input = open("input.txt").readline
size, turn, santa_alive, r_force, s_force = map(int,input().split())
r_x, r_y = map(int,input().split())
limit = float('inf')
s_offset = [(-1,0), (0, 1), (1, 0), (0, -1)]
santa_poses = [0]*santa_alive
# 0 : alive / 1: stun / 2 : dead
santa_status = [0]*santa_alive
santa_score = [0]*santa_alive
for _ in range(santa_alive):
s_num, s_x, s_y = map(int,input().split())
santa_poses[s_num-1] = [s_x, s_y]
def rudolph_move(r_x, r_y):
nearest_idx = 0
n_x, n_y = 0, 0
min_dist = limit
for idx, pos in enumerate(santa_poses):
sx, sy = pos
dist = pow((r_x-sx), 2) + pow((r_y-sy), 2)
if dist > min_dist:
continue
elif dist == min_dist:
if sx < n_x:
continue
if sx == n_x and sy < n_y:
continue
min_dist = dist
n_x, n_y = sx, sy
nearest_idx = idx
force = [0, 0]
if r_x > santa_poses[nearest_idx][0]:
r_x -= 1
force[0] -= 1
elif r_x < santa_poses[nearest_idx][0]:
r_x += 1
force[0] += 1
if r_y > santa_poses[nearest_idx][1]:
r_y -= 1
force[1] -= 1
elif r_y < santa_poses[nearest_idx][1]:
r_y += 1
force[1] += 1
return r_x, r_y, force, nearest_idx
def santa_move(idx):
sx, sy = santa_poses[idx]
min_dist = pow((r_x-sx), 2) + pow((r_y-sy), 2)
m_x, m_y = 0, 0
for dx, dy in s_offset:
px, py = sx + dx, sy + dy
dist = pow((r_x-px), 2) + pow((r_y-py), 2)
if dist < min_dist:
min_dist = dist
m_x, m_y = dx, dy
return sx+m_x, sy+m_y, [m_x, m_y]
def santa_interaction(idx2, move):
sx, sy = santa_poses[idx2]
sx += move[0]
sy += move[1]
if not 0 <= sx < size or not 0 <= sy < size:
santa_status[idx2] = 2
else:
santa_poses[idx2] = [sx, sy]
if [sx, sy] in santa_poses:
santa_interaction(santa_poses.index([sx, sy]), move)
return
r_x, r_y, move, idx = rudolph_move(r_x, r_y)
# 루λνκ° μ°ννν
μΆ©λν λ
if [r_x, r_y] == santa_poses[idx]:
sx, sy = santa_poses[idx]
sx += r_force * move[0]
sy += r_force * move[1]
if not 0 <= sx < size or not 0 <= sy < size:
santa_status[idx] = 2
else:
santa_status[idx] = 1
santa_poses[idx] = [sx, sy]
if [sx, sy] in santa_poses:
santa_interaction(santa_poses.index([sx, sy]), move)
print(santa_poses)
# μ°νμ μμ§μ
for idx in range(santa_alive):
if santa_status[idx] == 2:
continue
elif santa_status[idx] == 1:
santa_status[idx] = 0
sx, sy, move = santa_move(idx)
if [r_x, r_y] == santa_poses[idx]:
sx -= s_force * move[0]
sy -= s_force * move[1]
if not 0 <= sx < size or not 0 <= sy < size:
santa_status[idx] = 2
else:
santa_poses[idx] = [sx, sy]
santa_status[idx] = 1
if [sx, sy] in santa_poses:
santa_interaction(santa_poses.index([sx, sy]), move)
print(santa_poses)
print(santa_status)
print(r_x, r_y)
π λ¬Έμ λ§ν¬
루λνμ λ°λ
βοΈ μμλ μκ°
3μκ°...
β¨ μλ μ½λ
ν΄λΉ λ¬Έμ λ μ£Όμ΄μ§ λ°©μμ λ§μΆ° 루λνλ₯Ό μμ§μ΄κ³ ,
μ°νλ₯Ό μμ§μΈ λ€,
μ΄μμλ μ°νμκ² μ μ μμΉμ μμΌ
κ²°κ³Όμ μΌλ‘ κ° μ°νκ° μ μκ° μΌλ§μλμ§ μΆλ ₯νλ©΄ λ©λλ€.
루λνκ° μμ§μΌ λλ 루λνμ μ°νκ°μ κ±°λ¦¬κ° κ°κΉκ³ , xμ’νκ° ν¬κ³ yμ’νκ° ν° μμΌλ‘
μ΅μ μ μ°νλ₯Ό κ°μ Έμ΅λλ€.
루λνκ° μ°νλ₯Ό ν₯ν΄ λμ§νλλ° λ§μ½ λΆλͺνλ€λ©΄ μ°μμ μΌλ‘ μ°νλ ν μΉΈμ© λ°λ €λμΌν©λλ€.
λ°λ €λ μ°νλ μμ μ΄ λ¨μ΄μ§ μμΉμ μ‘΄μ¬ν μ°νλ₯Ό ν μΉΈμ© μ¬κ·λ₯Ό ν΅ν΄ λ°μ΄μ€λλ€.
μ°νμ μμ§μμ μ‘°κΈ λ³΅μ‘ν©λλ€.
μ°νμ μλ²λλ‘ μ κ·Όνμ¬ μμ§μ΄λ, λ§μ½ κΈ°μ ν μνκ±°λ μ₯μΈμΌ κ²½μ° μμ§μ΄μ§ λͺ»ν©λλ€.
νμ¬ μ°νλ₯Ό κΈ°μ€μΌλ‘ 루λνλ₯Ό ν₯ν΄ κ° μ μλ μ΅μ μ λ°©ν₯μΌλ‘ μμ§μ λλ€.
λ§μ½ μ°νκ° μμ§μ΄λ€κ° 루λνλ₯Ό λ§λ κ²¨μ° μ°νμ νλ§νΌ λ€μ λ€λ‘ λ¬Όλ¬λ μ§λ©°,
λ¬Όλ¬λμ§λ, λ€λ₯Έ μ°νκ° μμΌλ©΄ λλ―Έλ Έμ²λΌ ν μΉΈμ© λ°λ¦½λλ€.
κ° ν΄μ΄ λλ λλ§λ€, μ₯λ΄μ μλ μ°νλ μ μλ₯Ό νλν©λλ€.
μ΄ν κ° μ°νμ μ μλ₯Ό μΆλ ₯ν©λλ€..
π μλ‘κ² μκ²λ λ΄μ©
μ΄ μ λμ 빑ꡬνμ, μΌλ¨ μ€κ³νκ³ κ΅¬ννλ€μ
νλμ© κ²°κ³Όλ₯Ό μΆλ ₯ν΄μ λλ²κΉ νλ λ°©ν₯μΌλ‘ μ§νν΄μΌν κ²κ°μ΅λλ€.
ꡬν ν κ²°κ³Όκ°μ λΉκ΅νλλ° ν리면,
빑ꡬν λ¬Έμ λ ꡬνμ΄ λ³΅μ‘ν΄μ λλ²κΉ μ΄ μ΄λ €μ°λ―λ‘
μ€κ°λ§λ€ νμΈν μ μκ² κ΅¬νμ λΆλ¦¬νλ©΄ μ’μ κ² κ°μμ π€