https://www.acmicpc.net/problem/19532

 

19532번: 수학은 비대면강의입니다

정수 $a$, $b$, $c$, $d$, $e$, $f$가 공백으로 구분되어 차례대로 주어진다. ($-999 \leq a,b,c,d,e,f \leq 999$) 문제에서 언급한 방정식을 만족하는 $\left(x,y\right)$가 유일하게 존재하고, 이 때 $x$와 $y$가 각각 $-

www.acmicpc.net

 

코드풀이

완전탐색문제입니다.

for문을 2번 돌리면 끝납니다.

 

코드

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class Main {
public static int a,b,c,d,e,f;
public static int result = 0;
public static int x, y;
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
a = Integer.parseInt(st.nextToken());
b = Integer.parseInt(st.nextToken());
c = Integer.parseInt(st.nextToken());
d = Integer.parseInt(st.nextToken());
e = Integer.parseInt(st.nextToken());
f = Integer.parseInt(st.nextToken());
simulate();
System.out.print(x + " " + y);
}
public static void simulate() {
for(int i=-999;i<=999;i++) {
for(int j=-999;j<=999;j++) {
int first = a * i + b * j;
int second = d * i + e * j;
if(first == c && second == f) {
x = i;
y = j;
return;
}
}
}
}
}

+ Recent posts