Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

6-oesnuj #22

Merged
merged 3 commits into from
Jul 6, 2024
Merged

6-oesnuj #22

merged 3 commits into from
Jul 6, 2024

Conversation

oesnuj
Copy link
Member

@oesnuj oesnuj commented May 5, 2024

๐Ÿ”— ๋ฌธ์ œ ๋งํฌ

๋ฐฑ์ค€ | ์ •์‚ฌ๊ฐํ˜•

โœ”๏ธ ์†Œ์š”๋œ ์‹œ๊ฐ„

30๋ถ„

โœจ ์ˆ˜๋„ ์ฝ”๋“œ

์š”์ฆ˜ ๊ถŒ์˜คํ  ๊ต์ˆ˜๋‹˜์ด ๊ณผ์ œ๋กœ ๊ธฐํ•˜๋ฌธ์ œ๋ฅผ ์ž์ฃผ ๋‚ด์ฃผ์…”์„œ ๊ธฐํ•˜๋ฌธ์ œ ํ•œ๋ฒˆ ํ’€์–ด๋ดค์Šต๋‹ˆ๋‹ค.

์ž…๋ ฅ์œผ๋กœ ์  ์ขŒํ‘œ 4๊ฐœ๊ฐ€ ์ฃผ์–ด์ง€๊ณ  ์ด ์  4๊ฐœ๋กœ ์ •์‚ฌ๊ฐํ˜•์„ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋Š”์ง€ ์—†๋Š”์ง€๋ฅผ ํŒ๋‹จํ•œ๋‹ค.

Note

์ •์‚ฌ๊ฐํ˜• ์กฐ๊ฑด

  1. ๋„ค ๋ณ€์˜ ๊ธธ์ด๊ฐ€ ๋ชจ๋‘ ๊ฐ™๋‹ค
  2. ๋‘ ๋Œ€๊ฐ์„ ์˜ ๊ธธ์ด๊ฐ€ ๊ฐ™๋‹ค.

image

์ถ”๊ฐ€๋กœ ์  ์ขŒํ‘œ 4๊ฐœ๊ฐ€ ๋žœ๋ค์ด๋ฏ€๋กœ ์ •๋ ฌ์‹œ์ผœ ์•„๋ž˜์™€ ๊ฐ™์€ ์ˆœ์„œ๋กœ ๋ฐฐ์—ด์„ ๊ตฌ์„ฑํ•œ๋‹ค.
1 3
0 2

์œ„ ์ˆœ์„œ๋กœ ์ •๋ ฌ์‹œํ‚จ ๋‹ค์Œ ๊ฐ ์„ ๋ถ„์˜ ๊ธธ์ด์™€ ๋‘ ๋Œ€๊ฐ์„ ์˜ ๊ธธ์ด๋ฅผ ๊ตฌํ•ด์ค๋‹ˆ๋‹ค.
์ ๊ณผ ์ ์‚ฌ์ด์˜ ๊ฑฐ๋ฆฌ ๊ณต์‹์„ ํ™œ์šฉํ•ด์„œ ๊ธธ์ด๋ฅผ ๊ตฌํ•ด์ค๋‹ˆ๋‹ค.
๊ธธ์ด ๋น„๊ต๋งŒ ์ง„ํ–‰ ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๋ฃจํŠธ๋Š” ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

pow(a.x - b.x, 2) + pow(a.y - b.y, 2);

x์ถ•์˜ ์ขŒํ‘œ ์ฐจ์˜ ์ œ๊ณฑ, y์ถ•์˜ ์ขŒํ‘œ ์ฐจ์˜ ์ œ๊ณฑ์˜ ํ•ฉ์„ ๊ฑฐ๋ฆฌ ๋น„๊ต์— ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค

๊ตฌํ•œ ๊ธธ์ด๋“ค์„ ์ •์‚ฌ๊ฐํ˜• ์กฐ๊ฑด์— ๋งž๋Š”์ง€ ๊ฒ€์‚ฌํ•˜๋ฉด ๋งž๋‹ค๋ฉด ์ •์‚ฌ๊ฐํ˜•์ด๋ฏ€๋กœ 1์„ ์ถœ๋ ฅ ์•„๋‹ˆ๋ผ๋ฉด 0์„ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค.

๐Ÿ“‚ ์ „์ฒด ์ฝ”๋“œ

#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);
        //1 3
        //0 2
        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;
}

๐Ÿ“š ์ƒˆ๋กญ๊ฒŒ ์•Œ๊ฒŒ๋œ ๋‚ด์šฉ

Copy link
Contributor

@Ghdrn1399 Ghdrn1399 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๊ธฐํ•˜ ๊ด€๋ จ๋ฌธ์ œ ํ’€์–ด์ฃผ์‹ ๊ฑฐ ์ž˜ ๋ดค์Šต๋‹ˆ๋‹ค!!

Copy link
Collaborator

@pu2rile pu2rile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์˜ค... ์ €๋Š” ์•ฝ๊ฐ„ ํŽธ์‹์Ÿ์ด๋ผ ์ˆ˜ํ•™ ๋ฌธ์ œ๋ฅผ ์ž˜ ํ’€์ง€ ์•Š๋Š”๋ฐ ์ค€์„œ ๋‹˜์ด ํ’€์–ด์ฃผ์‹  ๊ฒƒ ๋ณด๋‹ˆ ์ œ๋ฒ• ํฅ๋ฏธ๋กœ์šธ์ง€๋„...? ์ €๋„ ๋‹ค์Œ์— ํ•œ๋ฒˆ ๋„์ „ํ•ด ๋ด์•ผ๊ฒ ์–ด์š”!! ์ˆ˜๊ณ ํ•˜์…จ์Šต๋‹ˆ๋‹ค!

Copy link
Collaborator

@suhyun113 suhyun113 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ €๋„ ๊ถŒ์˜คํ  ๊ต์ˆ˜๋‹˜ ์ˆ˜์—…์„ ๋“ค์—ˆ๋Š”๋ฐ... ๊ธฐํ•˜ ๋ฌธ์ œ๊ฐ€ ์ž์ฃผ ๋‚˜์™€์„œ ํž˜๋“ค์—ˆ์—ˆ์ฃ ..ใ…œใ…œ
์ด ๋ฌธ์ œ์—์„œ ์ •์‚ฌ๊ฐํ˜•์ธ์ง€ ํŒ๋ณ„ํ•˜๋Š” ๊ฒƒ์ด ๊ฐ€์žฅ ์ค‘์š”ํ•œ ๊ฒƒ ๊ฐ™์€๋ฐ, ์ ์„ ์ •๋ ฌํ•œ ํ›„ ๊ฐ ๋ณ€๊ณผ ๋Œ€๊ฐ์„ ์˜ ๊ธธ์ด๋ฅผ ๊ณ„์‚ฐํ•˜๋Š” ๊ฒƒ์œผ๋กœ ๋กœ์ง์„ ์ž˜ ๊ตฌํ˜„ํ•˜์‹  ๊ฒƒ ๊ฐ™์•„์š”!
calcDistance ํ•จ์ˆ˜๋กœ ๋‘ ์  ์‚ฌ์ด์˜ ๊ฑฐ๋ฆฌ๋ฅผ ๊ณ„์‚ฐํ•˜๋Š” ๊ฒƒ์„ ํšจ์œจ์ ์œผ๋กœ ๊ตฌํ˜„ํ•˜์‹  ๊ฒƒ๊ณผ
compareInfo๋ผ๋Š” ํ•จ์ˆ˜๋ฅผ ์ด์šฉํ•˜์—ฌ x์ขŒํ‘œ๋ฅผ ๊ธฐ์ค€์œผ๋กœ x๊ฐ€ ๊ฐ™์„ ๊ฒฝ์šฐ y์ขŒํ‘œ๋ฅผ ๊ธฐ์ค€์œผ๋กœ ์ •๋ ฌํ•˜๋Š” ๊ฒƒ์„ ์ž˜ ๊ตฌ์„ฑํ•œ ๊ฒƒ์ด ๋ณด๊ธฐ ์ข‹์•˜์Šต๋‹ˆ๋‹ค. ์ €๋Š” ํ•จ์ˆ˜๋กœ ๋‚˜๋ˆ„์–ด ์ฝ”๋“œ๋ฅผ ๋ถ„๋ฆฌํ•˜๋Š” ๊ฒƒ์ด ์•„์ง ์ข€ ์–ด์ƒ‰ํ•œ๋ฐ, ์ค€์„œ๋‹˜ ์ฝ”๋“œ๋ฅผ ๋ณด๋ฉด ํ•ญ์ƒ ๊น”๋”ํ•˜๊ณ  ๋ณด๊ธฐ ์ข‹๊ฒŒ ๋‚˜๋ˆ„์–ด์ ธ ์žˆ์–ด ๋ณด๊ณ  ๋ฐฐ์šฐ๊ณ  ์‹ถ์–ด์š”!

์ฝ”๋“œ๋ฅผ ํ•จ์ˆ˜๋กœ ๋ถ„๋ฆฌํ•˜๋Š” ๊น€์—, ๋ฐ˜๋ณต๋ฌธ ๋ถ€๋ถ„์˜ ์ •์‚ฌ๊ฐํ˜•์ธ์ง€ ํŒ๋ณ„ํ•˜๋Š” ๋ถ€๋ถ„๋„ ๋ถ„๋ฆฌํ•ด ๋ดค์–ด์š”! ์ด๋ ‡๊ฒŒ ํ•˜๋ฉด ์ข€ ๋” ๊ฐ€๋…์„ฑ์„ ๋†’์ผ ์ˆ˜ ์žˆ์–ด์š”~

bool isSquare(const vector<Point>& v) {
        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]);

    return (s1 == s2 && s2 == s3 && s3 == s4 && dia1 == dia2);
}
if (isSquare(v)) {
            cout << 1 << '\n';
        } else {
            cout << 0 << '\n';
        }

์ด๋ ‡๊ฒŒ ๋ฐ”๊ฟ”์คฌ์Šต๋‹ˆ๋‹น~

์ฝ”๋“œ๊ฐ€ ์ดํ•ดํ•˜๊ธฐ ์ข‹์•˜์Šต๋‹ˆ๋‹คใ… ์ˆ˜๊ณ ํ•˜์…จ์–ด์š”!๐Ÿ‘ป

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants