일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 문자열
- object detection
- 분할 정복
- 우선 순위 큐
- 플로이드 와샬
- dropout
- 세그먼트 트리
- 자바스크립트
- DP
- 백트래킹
- 가끔은 말로
- 회고록
- NEXT
- c++
- 이분 탐색
- back propagation
- tensorflow
- 크루스칼
- lazy propagation
- pytorch
- 다익스트라
- 조합론
- dfs
- 미래는_현재와_과거로
- 가끔은_말로
- BFS
- 알고리즘
- Overfitting
- 2023
- 너비 우선 탐색
Archives
- Today
- Total
Doby's Lab
백준 1064번: 평행사변형 (C++) 본문
https://www.acmicpc.net/problem/1064
Solved By: Geometry, CCW
CCW를 통해 세 점들이 한 직선 위에 있는지 판별하여 평행사변형을 만들 수 있는지 없는지에 대해 1차적으로 구분합니다.
나머지는 세 점들로부터 두 점씩 짝지어 거리를 구하여 구할 수 있는 모든 평행사변형의 둘레를 구한 다음 최댓값과 최솟값의 차이를 구해줍니다.
#include <iostream>
#include <cmath>
#include <vector>
#define ld long double
using namespace std;
struct Point{
ld x, y;
};
ld xa, ya, xb, yb, xc, yc;
ld ccw(Point a, Point b, Point c){
return (b.x - a.x) * (c.y - a.y) - (c.x - a.x) * (b.y - a.y);
}
ld dist(Point a, Point b){
ld x = a.x - b.x;
ld y = a.y - b.y;
return sqrtl(x * x + y * y);
}
ld getRound(ld a, ld b){
return 2 * (a + b);
}
int main(){
cout.precision(14);
cout << fixed;
Point a, b, c;
cin >> a.x >> a.y >> b.x >> b.y >> c.x >> c.y;
if(ccw(a, b, c) == 0){
cout << -1;
}
else{
ld ab = dist(a, b);
ld bc = dist(b, c);
ld ac = dist(a, c);
vector<ld> v;
v.push_back(getRound(ab, ac));
v.push_back(getRound(ab, bc));
v.push_back(getRound(ac, bc));
ld maxValue = 0;
ld minValue = 40000;
for(auto i : v){
if(i > maxValue) maxValue = i;
if(i < minValue) minValue = i;
//cout << i << '\n';
}
cout << maxValue - minValue;
}
return 0;
}
728x90
'PS > BOJ' 카테고리의 다른 글
백준 14401번: 악덕 나라 (C++) (0) | 2022.11.14 |
---|---|
백준 1143번: 경찰 (C++) (2) | 2022.11.14 |
백준 10531번: Golf Bot (C++) (0) | 2022.11.12 |
백준 18134번: 치삼이의 대모험 (C++) (0) | 2022.11.06 |
백준 22990번: 사이클 (C++) (0) | 2022.11.06 |