Skip to content

Commit

Permalink
2024-05-06 정사각형
Browse files Browse the repository at this point in the history
  • Loading branch information
oesnuj committed May 5, 2024
1 parent e764051 commit 41430fe
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
1 change: 1 addition & 0 deletions oesnuj/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
| 3차시 | 2024.04.02 || [카드 놓기](https://www.acmicpc.net/problem/18115) | [#11](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/11) |
| 4차시 | 2024.04.06 | 스택 | [옥상 정원 꾸미기](https://www.acmicpc.net/problem/6198) | [#14](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/14) |
| 5차시 | 2024.04.13 | 이분탐색 | [듣보잡](https://www.acmicpc.net/problem/1764) | [#20](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/20) |
| 6차시 | 2024.05.06 | 기하학 | [정사각형](https://www.acmicpc.net/problem/1485) | [#22](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/22) |
---
53 changes: 53 additions & 0 deletions oesnuj/기하/1485.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;

struct Point
{
int x, y;
};

int calcDistance(Point a, Point b)
{
return pow(a.x - b.x, 2) + pow(a.y - b.y, 2);
}

bool compareInfo(Point &a, Point &b)
{
if(a.x == b.x)
return a.y < b.y;
return a.x < b.x;
}

int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);

int n;
cin >> n;

while (n--)
{
vector <Point> v(4);
for (int i = 0; i < 4; i++) {
cin >> v[i].x >> v[i].y;
}
sort(v.begin(), v.end(),compareInfo);
//2 3
//0 1
int s1 = calcDistance(v[0], v[1]); //선분
int s2 = calcDistance(v[0], v[2]);
int s3 = calcDistance(v[1], v[3]);
int s4 = calcDistance(v[2], v[3]);

int dia1 = calcDistance(v[0], v[3]); //대각선
int dia2 = calcDistance(v[1], v[2]);
if (s1 == s2 && s2 == s3 && s3 == s4 && dia1 == dia2) //네변의 길이가 같고 대각선의 길이가 같다.
cout << 1 << '\n';
else
cout << 0 << '\n';
}
return 0;
}

0 comments on commit 41430fe

Please sign in to comment.