๋ฌธ์
https://www.acmicpc.net/problem/20041
20041๋ฒ: Escaping
์ฒซ ๋ฒ์งธ ์ค์๋ ๊ฒฝ์ฐฐ์ ์ N์ด ์ฃผ์ด์ง๋ค. ๋จ, 1 ≤ N ≤ 500,000์ด๋ค. ๊ทธ ๋ค์ N ๊ฐ์ ์ค์๋ ๊ฐ ๊ฒฝ์ฐฐ์ ์ด๊ธฐ ์์น์ ์ขํ (xi, yi)๊ฐ ๊ณต๋ฐฑ์ ์ฌ์ด์ ๋๊ณ ์ฃผ์ด์ง๋ค. ๋ค์ ์ค์๋ ๋๋์ ์ด๊ธฐ ์์น์ ์ข
www.acmicpc.net
icpc 2020 ์์ F๋ฒ ๋ฌธ์ ๋ก
๋๋๊ณผ ๊ฒฝ์ฐฐ์ ๋ํ ์ ๋ณด๊ฐ ์ฃผ์ด์ก์ ๋, ๋๋์ด ๊ฒฝ์ฐฐ์๊ฒ์ ํ์ถํ ์ ์๋์ง ํ๋จํ๋ ๋ฌธ์
๋ฌธ์ ํ์ด
๋๋์ด ๊ฒฝ์ฐฐ์๊ฒ์ ๊ฐ์ฅ ๋ฉ๋ฆฌ ๋ฌ์๋ ์ ์๋ ๋ฐฉ๋ฒ์ 4 ๋ฐฉํฅ ์ค ํ ๋ฐฉํฅ์ผ๋ก ์ง์ง ํ๋ ๋ฐฉ๋ฒ์ด๋ค.
๊ฐ ๊ฒฝ์ฐฐ์ ๋ํด์ ์, ์๋, ์ผ์ชฝ, ์ค๋ฅธ์ชฝ ๋ฐฉํฅ์ ํ์ํ๋ค.
ํ ๋ฒ์ด๋ผ๋ ํ์ถํ ์ ์๋ค๋ฉด ์ด๊ธฐ ์กฐ๊ฑด์์ ํ์ถ ๊ฐ๋ฅํ ๊ฒ
ex) ์๋ก ์์ง์ผ ๋.
- ๊ฒฝ์ฐฐ์ด ๋๋๋ณด๋ค ๋ฐ์ ์์ผ๋ฉด ํ์ถ ๊ฐ๋ฅ
- ๊ฒฝ์ฐฐ์ด ๋๋๋ณด๋ค ์์ ์๊ณ , ๊ทธ ๊ฑฐ๋ฆฌ๊ฐ ์ข์ฐ๋ก ๋จ์ด์ง ๊ฑฐ๋ฆฌ๋ณด๋ค ๊ธธ๋ฉด ํ์ถ ๋ถ๊ฐ๋ฅ
์ฝ๋
1.java
import java.io.*;
import java.util.StringTokenizer;
public class Main {
static int n;
static int police[][],x,y;
public static boolean find(int move) { //๋๋์ด ์์ง์ด๋ ์์น๋ฅผ ๋ฐํ์ผ๋ก
for(int i=0;i<n;i++) {
if(move==0) { //์๋ก
if(police[i][1]<=y) //ํ์ถ๊ฐ๋ฅ
continue;
int temp=police[i][0]>x?police[i][0]-x:x-police[i][0];
if((police[i][1]-y)>=temp) //์กํ
return false;
}
else if(move==1) {//์๋
if(police[i][1]>=y)
continue;
int temp=police[i][0]>x?police[i][0]-x:x-police[i][0];
if((y-police[i][1])>=temp)
return false;
}
else if(move==2) { //์ผ์ชฝ
if(police[i][0]>=x)
continue;
int temp=police[i][1]>y?police[i][1]-y:y-police[i][1];
if((x-police[i][0])>=temp)
return false;
}
else if(move==3){//์ค๋ฅธ์ชฝ
if(police[i][0]<=x)
continue;
int temp=police[i][1]>y?police[i][1]-y:y-police[i][1];
if((police[i][0]-x)>=temp)
return false;
}
}
return true;
}
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
n=Integer.parseInt(bf.readLine());
police=new int [n][2];
for(int i=0;i<n;i++) {
StringTokenizer st1=new StringTokenizer(bf.readLine());
police[i][0]=Integer.parseInt(st1.nextToken());
police[i][1]=Integer.parseInt(st1.nextToken());
}
StringTokenizer st=new StringTokenizer(bf.readLine());
x=Integer.parseInt(st.nextToken());
y=Integer.parseInt(st.nextToken());
boolean result = false;
for(int i=0;i<4;i++) {
result=find(i);
if(result==true)
break;
}
if (result==true)
System.out.println("YES");
else
System.out.println("NO");
}
}
2. ํ์ด์ฌ
n=int(input())
def find(move):
for i in range(n):
if move==0:
if police[i][1]<=y:
continue
if police[i][1]-y>=abs(police[i][0]-x):
return False
elif move==1:
if police[i][1]>=y:
continue
if y-police[i][1]>=abs(police[i][0]-x):
return False
elif move==2:
if police[i][0]>=x:
continue
if x-police[i][0]>=abs(police[i][1]-y):
return False
else:
if police[i][0]<=x:
continue
if police[i][0]-x>=abs(police[i][1]-y):
return False
return True
police=[]
for i in range(n):
police.append(list(map(int,input().split())))
x,y=map(int,input().split())
for i in range(4):
result=find(i)
if result:
break;
if result:
print("YES")
else:
print("NO")
๊ธฐํ
java ๋ก ๊ตฌํํ๊ธฐ๊ฐ ์ด๋ ค์์ ๋จผ์ ํ์ด์ฌ์ผ๋ก ๊ตฌํํด๋ณด๊ณ ๋ค์ java๋ก ํ์๋ค.
์์ด๋์ด ์์ฒด๋ ์ด๋ ต์ง ์์๋ฐ ๋ ์ฌ๋ฆฌ๊ธฐ๊ฐ ์ด๋ ค์ ๋ค.
'๐ป ์๊ณ ๋ฆฌ์ฆ > PS' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[2017 ์นด์นด์ค์ฝ๋ ์์ ] ์ปฌ๋ฌ๋ง๋ถ - ํ์ด์ฌ (0) | 2022.03.16 |
---|---|
[BOJ/๋ฐฑ์ค] 9024 ๋ ์์ ํฉ - ํ์ด์ฌ (0) | 2021.11.01 |
[BOJ/๋ฐฑ์ค] 20047 ๋์ ์ฎ๊ธฐ๊ธฐ - ์๋ฐ (0) | 2021.10.05 |
[BOJ/๋ฐฑ์ค] 19538 ๋ฃจ๋จธ - ํ์ด์ฌ (0) | 2021.09.17 |
[BOJ/๋ฐฑ์ค] 1074 Z - ํ์ด์ฌ (0) | 2021.09.17 |