Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- XR Interaction Toolkit
- ue5
- 스택
- 트리
- DFS
- VR
- 유니온 파인드
- Unreal Engine 5
- 그래프
- 문자열
- 백트래킹
- 다이나믹 프로그래밍
- c++
- 그리디 알고리즘
- 구현
- 우선순위 큐
- 알고리즘
- Team Fortress 2
- 시뮬레이션
- BFS
- 다익스트라
- 재귀
- 백준
- 유니티
- 브루트포스
- 투 포인터
- 수학
- 자료구조
- 정렬
- 누적 합
Archives
- Today
- Total
1일1알
백준 1485번 정사각형 C++ 본문
https://www.acmicpc.net/problem/1485
1485번: 정사각형
첫째 줄에 테스트 케이스의 개수 T가 주어진다. 각 테스트 케이스는 네 줄로 이루어져 있으며, 점의 좌표가 한 줄에 하나씩 주어진다. 점의 좌표는 -100,000보다 크거나 같고, 100,000보다 작거나 같
www.acmicpc.net
네 변의 길이가 같고 두 대각선의 길이가 같으면 정사각형이다. 정렬한 뒤 구하면 된다.
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <set>
#include <map>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <limits.h>
using namespace std;
using int64 = long long;
double GetDist(pair<int64, int64>& loc1, pair<int64, int64>& loc2) {
return sqrt(pow(loc2.first - loc1.first, 2) + pow(loc2.second - loc1.second, 2));
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t;
cin >> t;
while (t--) {
vector<pair<int64, int64>> v;
for (int i = 0; i < 4; i++) {
int x, y;
cin >> x >> y;
v.push_back({ x,y });
}
sort(v.begin(), v.end());
double height1 = GetDist(v[0], v[1]);
double height2 = GetDist(v[2], v[3]);
double width1 = GetDist(v[0], v[2]);
double width2 = GetDist(v[1], v[3]);
double diagonal1 = GetDist(v[0], v[3]);
double diagonal2 = GetDist(v[1], v[2]);
set<double> s1;
set<double> s2;
s1.insert(height1);
s1.insert(height2);
s1.insert(width1);
s1.insert(width2);
s2.insert(diagonal1);
s2.insert(diagonal2);
int ans = 0;
if (s1.size() == 1 && s2.size() == 1) ans = 1;
cout << ans << "\n";
}
}
'알고리즘' 카테고리의 다른 글
백준 12789번 도키도키 간식드리미 C++ (0) | 2022.12.14 |
---|---|
백준 5545번 최고의 피자 C++ (0) | 2022.12.13 |
백준 13904번 과제 C++ (0) | 2022.12.11 |
백준 1774번 우주신과의 교감 C++ (0) | 2022.12.10 |
백준 1613번 역사 C++ (0) | 2022.12.09 |