문제
https://www.acmicpc.net/problem/19572
걸린 시간
-
풀이
C
#include <stdio.h>
int main(){
float d1, d2, d3;
float a, b, c;
scanf("%f %f %f", &d1, &d2, &d3);
float mat[3][4] = {{1, 1, 0, d1}, {1, 0, 1, d2}, {0, 1, 1, d3}};
for(int col = 0; col < 4; col++){
mat[0][col] -= mat[1][col];
mat[0][col] -= mat[2][col];
}
c = mat[0][3]/mat[0][2];
a = mat[1][3]-c;
b = mat[2][3]-c;
if(a <= 0 or b <= 0 or c <= 0){
printf("%d\n", -1);
}
else{
printf("%d\n%.1f %.1f %.1f\n", 1, a, b, c);
}
return 0;
}
미지수 3개에 계수가 모두 1인 연립방정식의 해를 구하는 문제이다.
SUAPC 2020 에서 맞추라고 준 문제인데 수학 쪽으로 배경지식과 구현능력이 부족했던 탓인지 풀지 못했었다..
'Baekjoon' 카테고리의 다른 글
Baekjoon 2096번 내려가기 (0) | 2020.08.22 |
---|---|
Baekjoon 11003 최솟값 찾기 (0) | 2020.08.21 |
Baekjoon 1389번 케빈 베이컨의 6단계 법칙 (0) | 2020.08.17 |
Baekjoon 7569번 토마토 (0) | 2020.08.17 |
Baekjoon 9461번 파도반 수열 (0) | 2020.08.17 |
댓글