⨠ꡬν
μ½λνΈλ¦¬ | μ½λ©ν μ€νΈ μ€λΉλ₯Ό μν μκ³ λ¦¬μ¦ μ μ
κ΅κ°λνκ° λ§λ μ½λ© 곡λΆμ κ°μ΄λλΆ μ½λ© μμ΄λ³΄λΆν° κΏμ μ§μ₯ μ½ν ν©κ²©κΉμ§, κ΅κ°λνκ° μμ ν 컀리νλΌμΌλ‘ μ€λΉν΄λ³΄μΈμ.
www.codetree.ai
π κ³ λ €ν΄μΌν μ
- ν΄λΉνλ μΉΈμ μλ μ΄λ€μ λΉκ΅νκ³ κ°μ₯ 곡격λ ₯μ΄ λμ μ΄μ μ νν΄μΌνλ€.
- μ§ μ¬λμ κ²½μ° μ΄μ ν΄λΉνλ μΉΈμ λκ³ , 쑰건μ λ°λΌ μ΄λνλ€.
πΉοΈ μκ³ λ¦¬μ¦ κ³Όμ
μ§ μ¬λμ΄ μ΄μ λ²λ¦¬κ³ μ΄λν΄μΌνλλ°, λ²λ¦¬λ μ½λλ₯Ό μμ±νμ§ μμ λλ²κΉ νλλ° μκ°μ μκ°λ³΄λ€ λ§μ΄ μμ κ² μΈμλ λ±ν λ§νλ λΆλΆμ΄ μμλ€.
κ·Έλ₯ λ¬Έμ μ½κ³ μ λΉν μλ£κ΅¬μ‘°λ₯Ό μ νν΄μ λ¬Έμ μμ μꡬνλλ‘ μ νλ©΄ λλ€.
π©π»μ 체 μ½λ
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.StringTokenizer;
public class final_2022_1_μΈμλ
{
static int n, m, k;
static int[] dx = {-1, 0, 1, 0};
static int[] dy = {0, 1, 0, -1};
static int[][] gunPower;
static int[][] playerLoc;
static Info[] players;
static int[] point;
static int winner, loser;
static ArrayList<Integer>[][] guns;
static class Info{
int x, y, d, s, gp, n;
public Info(int x, int y, int d, int s, int gp, int n) {
this.x=x;
this.y=y;
this.d=d;
this.s=s; // μ΄κΈ° λ₯λ ₯μΉ
this.gp=gp; // νμ¬ κ°μ§κ³ μλ μ΄μ 곡격λ ₯
this.n=n; // νλ μ΄μ΄ λ²νΈ
}
}
static void simulate() {
move();
}
static void move() {
for(int i=1; i<=m; i++) {
Info now = players[i];
int nx = now.x+dx[now.d];
int ny = now.y+dy[now.d];
// 격μλ₯Ό λ²μ΄λλ κ²½μ°μλ μ λ°λ λ°©ν₯μΌλ‘ λ°©ν₯ λ°κΎΈκ³ 1μΉΈ μ΄λ
if(nx<0 || nx>=n || ny<0 || ny>=n) {
if(now.d==0 || now.d==1) now.d+=2;
else now.d-=2;
nx = now.x+dx[now.d];
ny = now.y+dy[now.d];
}
// μ΄λ μλ£
now.x=nx;
now.y=ny;
// λ§μ½ μ΄λν λ°©ν₯μ νλ μ΄μ΄κ° μλ€λ©΄ μ΄ μλμ§ νμΈ
if(playerLoc[now.x][now.y]==0) {
// μ΄μ΄ μλ€λ©΄
if(guns[now.x][now.y].size()>=1) {
compareGun(now);
}
// μ΄λν κ² playerLocμ λ°μμν€κΈ°
copyLoc();
}
// λ§μ½ νλ μ΄μ΄κ° μλ€λ©΄ μΈμ
else {
int idx = playerLoc[nx][ny];
Info p = players[idx];
fight(p, now);
// μ΄κΈ΄ μ¬λ & μ§ μ¬λ μ΄λ
Info w = players[winner];
Info l = players[loser];
w.x= nx;
w.y= ny;
l.x=nx;
l.y=ny;
copyLoc();
// μ§ μ¬λ --> λ³ΈμΈμ΄ κ°μ§κ³ μλ μ΄μ ν΄λΉ 격μμ λ΄λ €λκ³ μ‘°κ±΄μ λ§κ² μ΄λ
lose(l);
// μ΄κΈ΄ μ¬λ --> 곡격λ ₯ λμ μ΄ μ ν
compareGun(w);
copyLoc();
}
}
}
static void compareGun(Info p) {
int playerGp= p.gp;
for(int i=0; i<guns[p.x][p.y].size(); i++) {
if(playerGp<=guns[p.x][p.y].get(i)) {
playerGp = guns[p.x][p.y].get(i);
}
}
if(p.gp!=0) guns[p.x][p.y].add(p.gp);
guns[p.x][p.y].remove(Integer.valueOf(playerGp));
p.gp = playerGp;
}
static void fight(Info other, Info now) {
if(other.gp+other.s == now.gp+now.s) {
if(other.s<now.s) {
winner = now.n;
loser = other.n;
}
else if(other.s> now.s) {
winner = other.n;
loser = now.n;
}
}else if(other.gp+other.s > now.gp+now.s) {
winner=other.n;
loser = now.n;
point[winner]+= ((other.gp+other.s) - (now.gp+now.s));
}
else {
winner = now.n;
loser = other.n;
point[winner]+= ((now.gp+now.s) - (other.gp+other.s));
}
}
static void lose(Info l) {
// λ³ΈμΈμ΄ κ°μ§κ³ μλ μ΄μ ν΄λΉ 격μμ λ΄λ €λμ
if(l.gp!=0) {
guns[l.x][l.y].add(l.gp);
l.gp=0;
}
while(true) {
// νλ μ΄μ΄κ° μλ κ°μ§κ³ μλ λ°©ν₯λλ‘ ν μΉΈ μ΄λ
int nx = l.x+dx[l.d];
int ny = l.y+dy[l.d];
if(nx<0 || nx>=n || ny<0 || ny>=n || playerLoc[nx][ny]!=0) {
l.d = (l.d+1)%4;
}else {
l.x=nx;
l.y=ny;
break;
}
}
compareGun(l);
}
static void copyLoc() {
playerLoc = new int[n][n];
for(int i=1; i<=m; i++) {
Info p = players[i];
playerLoc[p.x][p.y]= i;
}
}
public static void main(String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
StringTokenizer st = new StringTokenizer(br.readLine());
n = Integer.parseInt(st.nextToken());
m = Integer.parseInt(st.nextToken());
k = Integer.parseInt(st.nextToken());
gunPower = new int[n][n];
playerLoc = new int[n][n];
players = new Info[m+1];
point = new int[m+1];
guns = new ArrayList[n][n];
for(int i=0; i<n; i++) {
for(int j=0; j<n; j++) {
guns[i][j] = new ArrayList<>();
}
}
for(int i=0; i<n; i++) {
st = new StringTokenizer(br.readLine());
for(int j=0; j<n; j++) {
int n =Integer.parseInt(st.nextToken());
if(n==0) continue;
guns[i][j].add(n); // μ΄ κ³΅κ²©λ ₯
}
}
for(int i=1; i<=m; i++) {
st = new StringTokenizer(br.readLine());
int x = Integer.parseInt(st.nextToken())-1;
int y = Integer.parseInt(st.nextToken())-1;
int d = Integer.parseInt(st.nextToken()); // λ°©ν₯
int s = Integer.parseInt(st.nextToken()); // μ΄κΈ° λ₯λ ₯μΉ
playerLoc[x][y]=i;
players[i] = new Info(x, y, d, s, 0, i);
}
while(k-->0) {
simulate();
}
for(int i=1; i<=m; i++) {
bw.write(String.valueOf(point[i]) + " ");
}
bw.flush();
bw.close();
}
}
'μκ³ λ¦¬μ¦ > CodeTree' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
[CodeTree] λ©μ΄μ¦ λ¬λ - Java (1) | 2024.04.12 |
---|---|
[CodeTree] 루λνμ λ°λ - Java (2) | 2024.04.06 |