[백준 19532] https://www.acmicpc.net/problem/19532
이 문제는 a,b,c,d,e,f 입력을 받아서 두개의 방정식의 해를 구하는 문제이다.
선형대수에서 배운 사람은 Cramer 공식을 활용하면 정말 쉽게 풀 수있고, 나 역시 Cramer 공식을 사용해서 문제를 풀었다.
<Cramer's rule에 대한 설명>
https://ko.wikipedia.org/wiki/%ED%81%AC%EB%9D%BC%EB%A9%94%EB%A5%B4_%EB%B2%95%EC%B9%99
- Cramer 공식을 사용하기 위해서는 분모에 오는 행렬과 분자에 있는 행렬 2개의 행렬식이 필요하다.
- 분모에 오는 행렬은 두 개의 방정식에서 좌항에 오는 미지수를 포함한 식의 계수행렬을 구하면 된다.
- 분자에 오는 행렬은 분모를 구할 때 사용했던 계수행렬에서 위치에 대응하는 계수 값을 우항의 몫으로 대체하면 된다.
by Cramer's Rule
= ,
=
#include <iostream>
using namespace std;
int main(void){
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int a,b,c,d,e,f;
cin>>a>>b>>c>>d>>e>>f;
int denominator=a*e-b*d; // 분모에 오는 행렬식
int son_x=c*e-b*f; // x 값을 구할 때 분자에 오는 행렬식
int son_y=a*f-c*d; // y 값을 구할 때 분자에 오는 행렬식
cout<<son_x/denominator<<" "<<son_y/denominator<<'\n';
return 0;
}
Cramer 공식을 활용하면 정말 쉽게 풀 수 있다.