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

8-suhyun113 #32

Merged
merged 6 commits into from
Jul 17, 2024
Merged

8-suhyun113 #32

merged 6 commits into from
Jul 17, 2024

Conversation

suhyun113
Copy link
Collaborator

@suhyun113 suhyun113 commented Jul 1, 2024

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

https://www.acmicpc.net/problem/1004

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

์•ฝ 1์‹œ๊ฐ„

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

๐Ÿฉต1. ์ƒํ™ฉ ์„ค๋ช…๐Ÿฉต

  • ์œ„ํ—˜์— ๋น ์ง„ ์žฅ๋ฏธ๋ฅผ ๊ตฌํ•˜๊ธฐ ์œ„ํ•ด ์€ํ•˜์ˆ˜๋ฅผ ๋”ฐ๋ผ ๊ธด ์—ฌํ–‰ ์‹œ์ž‘ํ•œ ์–ด๋ฆฐ ์™•์ž
  • ์–ด๋ฆฐ ์™•์ž์˜ ์šฐ์ฃผ์„ ์€ ํ–‰์„ฑ๊ณ„ ๊ฐ„์˜ ์ด๋™ ์ตœ๋Œ€ํ•œ ํ”ผํ•ด ์—ฌํ–‰ํ•ด์•ผ ํ•จ

๐Ÿฉต2. ํ–‰์„ฑ๊ณ„ ์˜ˆ์‹œ๐Ÿฉต
image

  • ๋นจ๊ฐ„ ์‹ค์„  : ์–ด๋ฆฐ ์™•์ž๊ฐ€ ์ถœ๋ฐœ์ ์—์„œ ๋„์ฐฉ์ ๊นŒ์ง€ ๋„๋‹ฌํ•˜๋Š”๋ฐ ์žˆ์–ด ํ•„์š”ํ•œ ํ–‰์„ฑ๊ณ„ ์ง„์ž…/์ดํƒˆ ํšŸ์ˆ˜๋ฅผ ์ตœ์†Œํ™”ํ•˜๋Š” ๊ฒฝ๋กœ
  • ์› : ํ–‰์„ฑ๊ณ„์˜ ๊ฒฝ๊ณ„
    => ์€ํ•˜์ˆ˜ ์ง€๋„, ์ถœ๋ฐœ์ , ๋„์ฐฉ์  ์ฃผ์–ด์กŒ์„ ๋•Œ, ์–ด๋ฆฐ ์™•์ž์—๊ฒŒ ํ•„์š”ํ•œ ์ตœ์†Œ์˜ ํ–‰์„ฑ๊ณ„ ์ง„์ž…/์ดํƒˆ ํšŒ์ˆ˜?

๐Ÿฉต3. ์กฐ๊ฑด๐Ÿฉต
๐Ÿง1) ํ–‰์„ฑ๊ณ„๋กœ ์ง„์ž…๊ณผ ์ดํƒˆ ๋ชจ๋‘ ํ•ด์•ผ๋งŒ ํ•จ

  • ์ถœ๋ฐœ์ , ๋„์ฐฉ์  ๋ชจ๋‘ ๊ฐ™์€ ํ–‰์„ฑ๊ณ„ -> ์ง„์ž…/์ดํƒˆํ•  ํ•„์š”x
    => ์ถœ๋ฐœ์ ๊ณผ ๋„์ฐฉ์ ์„ ํฌํ•จํ•˜๋Š” ํ–‰์„ฑ๊ณ„๋Š” ์„œ๋กœ ๋‹ฌ๋ผ์•ผ ํ•จ

๐Ÿง2) ๋„์ฐฉ์ ์„ ํฌํ•จํ•˜๋Š” ํ–‰์„ฑ๊ณ„์˜ ๊ฐœ์ˆ˜๋งŒํผ ์ง„์ž…ํ•ด์•ผ ํ•˜๊ณ , ์ถœ๋ฐœ์ ์„ ํฌํ•จํ•˜๋Š” ํ–‰์„ฑ๊ณ„์˜ ๊ฐœ์ˆ˜๋งŒํผ ์ดํƒˆํ•ด์•ผ ํ•จ

*์œ„์˜ ๊ทธ๋ฆผ์„ ์ฐธ๊ณ ๋กœ ํ•˜๋ฉด,

  • ์ถœ๋ฐœ์ ์ด ์› ๋‚ด๋ถ€์— ์žˆ๊ณ , ๋„์ฐฉ์ ์ด ์› ์™ธ๋ถ€์— ์žˆ๋‹ค๋ฉด, ๊ทธ ํ–‰์„ฑ์€ ์ถœ๋ฐœ์ ์„ ํฌํ•จํ•˜๋Š” ํ–‰์„ฑ์ด๋ฏ€๋กœ ์ดํƒˆํ•ด์•ผ ํ•จ.
  • ์ถœ
    -> ์ถœ๋ฐœ์ ์„ ํฌํ•จํ•˜๋Š” ํ–‰์„ฑ ๊ฐœ์ˆ˜ : 1๊ฐœ์ด๋ฏ€๋กœ ์ง„์ž… ํšŸ์ˆ˜ = 1ํšŒ
    -> ๋„์ฐฉ์ ์„ ํฌํ•จํ•˜๋Š” ํ–‰์„ฑ ๊ฐœ์ˆ˜ : 2๊ฐœ์ด๋ฏ€๋กœ ์ดํƒˆ ํšŸ์ˆ˜ = 2ํšŒ
    => ์ตœ์ข… ์ง„์ž…/์ดํƒˆ ํšŸ์ˆ˜ = ์ง„์ž… ํšŸ์ˆ˜ + ์ดํƒˆ ํšŸ์ˆ˜ = 3ํšŒ
๐Ÿฉต4. ์ตœ์ข… ์ฝ”๋“œ๐Ÿฉต
#include <iostream>
#include <cmath>
using namespace std;

int main() {
    int T; // ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค์˜ ๊ฐœ์ˆ˜
    int x1, y1, x2, y2; // ์ถœ๋ฐœ์ , ๋„์ฐฉ์ 
    int n; // ํ–‰์„ฑ์˜ ๊ฐœ์ˆ˜
    int cx, cy, r; // ํ–‰์„ฑ๊ณ„์˜ ์ค‘์ ๊ณผ ๋ฐ˜์ง€๋ฆ„
    
    cin >> T;
    while(T--) {
        cin >> x1 >> y1 >> x2 >> y2;
        cin >> n;

        int enter = 0; // ์ง„์ž… ํšŸ์ˆ˜
        int departure = 0; // ์ดํƒˆ ํšŸ์ˆ˜
        int count = 0; // ์ตœ์ข… ์ง„์ž…/์ดํƒˆ ํšŸ์ˆ˜

        while(n--) {
            cin >> cx >> cy >> r;
            float startDistance = sqrt(pow(cx - x1, 2) + pow(cy - y1, 2)); // ์ถœ๋ฐœ์ ๊ณผ ์› ์‚ฌ์ด์˜ ๊ฑฐ๋ฆฌ
            float endDistance = sqrt(pow(cx - x2, 2) + pow(cy - y2, 2)); // ๋„์ฐฉ์ ๊ณผ ์› ์‚ฌ์ด์˜ ๊ฑฐ๋ฆฌ

            if (startDistance < r){  // ์ถœ๋ฐœ์ ์ด ์› ๋‚ด๋ถ€์— ์žˆ๊ณ , 
                if (endDistance > r) { // ๋„์ฐฉ์ ์ด ์› ์™ธ๋ถ€์— ์žˆ์Œ
                    departure++; // ์ถœ๋ฐœ์  ํฌํ•จํ•˜๋Š” ํ–‰์„ฑ -> ์ดํƒˆ ํšŸ์ˆ˜ ์ฆ๊ฐ€
                }
            }
            if (startDistance > r) { // ์ถœ๋ฐœ์ ์ด ์› ์™ธ๋ถ€์— ์žˆ๊ณ , 
                if (endDistance < r) { // ๋„์ฐฉ์ ์ด ์› ๋‚ด๋ถ€์— ์žˆ์Œ
                    enter++; // ๋„์ฐฉ์  ํฌํ•จํ•˜๋Š” ํ–‰์„ฑ -> ์ง„์ž… ํšŒ์ˆ˜ ์ฆ๊ฐ€
                }
            }
        }
        count = enter + departure; // ์ตœ์ข… ์ง„์ž…/์ดํƒˆ ํšŸ์ˆ˜
        cout << count << endl; 
    }
    return 0;
}

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

์•ฝ๊ฐ„ ๋น„์Šทํ•œ ๋ฌธ์ œ๋ฅผ ๊ฐ์ง€ํ”„ ์ˆ˜์—…์„ ๋“ค์œผ๋ฉด์„œ ํ’€์–ด๋ณธ ๊ธฐ์–ต์ด ๋‚˜๋Š”๋ฐ,,,
์›๊ณผ ์  ์‚ฌ์ด์˜ ๊ฑฐ๋ฆฌ๋ฅผ ๊ตฌํ•˜๋Š” ๊ณต์‹์„ ์ด์šฉํ•˜์—ฌ ๊ทธ ๊ฑฐ๋ฆฌ๊ฐ€ ๋ฐ˜์ง€๋ฆ„๋ณด๋‹ค ํฌ๋ƒ ์ž‘๋ƒ์— ๋”ฐ๋ผ ๊ทธ ์ ์ด ์›์˜ ๋‚ด๋ถ€์— ์žˆ๋Š”์ง€ ์™ธ๋ถ€์— ์žˆ๋Š”์ง€ ๊ตฌํ•  ์ˆ˜ ์žˆ๋‹ค๋Š” ๊ฒƒ์„ ๋‹ค์‹œ ํ•œ ๋ฒˆ ๋ณต์Šตํ•ด๋ณผ ์ˆ˜ ์žˆ์—ˆ๋‹ค.

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.

์ €๋Š” ํŒŒ์ด์ฌ์œผ๋กœ ํ•œ๋ฒˆ ํ’€์–ด ๋ดค๋Š”๋ฐ์š”!

๋จผ์ € ์ด ์ง„์ž…/์ดํƒˆ ํšŸ์ˆ˜๋Š” ์•„๋ž˜ ๊ทธ๋ฆผ์ฒ˜๋Ÿผ 3ํšŒ

แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2024-07-05 แ„‹แ…ฉแ„’แ…ฎ 11 53 40

์ฆ‰, ์ถœ๋ฐœ์ ๊ณผ ๋„์ฐฉ์ ์ด ๋ชจ๋‘ ํ–‰์„ฑ ๋‚ด๋ถ€์— ์žˆ์–ด ์ง„์ž…/์ดํƒˆ์ด ํ•„์š” ์—†๋Š” ๊ฒฝ์šฐ๊ฐ€ ์ด ์ง„์ž…/์ดํƒˆ 0ํšŒ

dis1 = (x1 - cx)**2 + (y1 - cy)**2
        dis2 = (x2 - cx)**2 + (y2 - cy)**2
        pow_cr = cr**2

์ˆ˜ํ˜„๋‹˜์ฒ˜๋Ÿผ ์ ๊ณผ ์  ์‚ฌ์ด์˜ ๊ฑฐ๋ฆฌ๋ฅผ ๊ตฌํ•˜๋Š” ๊ณต์‹์„ ์‚ฌ์šฉํ•˜๋ฉด ํ’€ ์ˆ˜ ์žˆ๋”๋ผ๊ตฌ์š”!

์ˆ˜ํ•™ ๋ฌธ์ œ๋Š” ๋ญ”๊ฐ€ ์–ด๋ ค์›Œ ๋ณด์—ฌ์„œ ์†์„ ์ž˜ ์•ˆ ๋Œ”๋Š”๋ฐ ์ด ๋ฌธ์ œ๋Š” ์žฌ๋ฏธ์žˆ๊ฒŒ ํ’€์—ˆ๋˜ ๊ฒƒ ๊ฐ™์•„์š” ใ…Žใ…Ž pr ์ˆ˜๊ณ ํ•˜์…จ์Šต๋‹ˆ๋‹ค!

Copy link
Member

@oesnuj oesnuj left a comment

Choose a reason for hiding this comment

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

์ €๋„ ๊ฐ์ง€ํ”„ ์ƒ๊ฐ๋‚˜๋ฉด์„œ ์žฌ๋ฐŒ๊ฒŒ ํ’€์—ˆ๋Š”๋ฐ์š”.
"์‹œ์ž‘์ ๊ณผ ๋„์ฐฉ์ ์ค‘ ํ•˜๋‚˜๋งŒ์„ ํฌํ•จํ•˜๊ณ  ์žˆ๋Š” ์›"์ธ ๊ฒฝ์šฐ์—๋งŒ cnt๋ฅผ ์ฆ๊ฐ€์‹œํ‚ค๋Š” ๋กœ์ง์œผ๋กœ ํ•ด๊ฒฐํ•ด๋ดค์Šต๋‹ˆ๋‹ค.
๋‹ค๋ฅธ c++ํ’€์ด๋„ ๋ณด๋‹ˆ๊นŒ ์ข‹๋„ค์š”!! PR ์ˆ˜๊ณ ํ•˜์…จ์Šต๋‹ˆ๋‹ค๐Ÿ‘

#include <iostream>
#include <cmath>
using namespace std;


double calcDistance(int& x1, int& y1, int& x2, int& y2) {
    return sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2));
}

int main() {
    int T, x1, y1, x2, y2, cx, cy, r, n;
    float distance = 0;
    cin >> T;
    while (T--) {
        int cnt = 0;
        cin >> x1 >> y1 >> x2 >> y2;
        cin >> n;
        while (n--) {
            cin >> cx >> cy >> r;
            bool start_in_circle = calcDistance(x1, y1, cx, cy) <= r;
            bool end_in_circle = calcDistance(x2, y2, cx, cy) <= r;
            if (start_in_circle != end_in_circle) cnt++;
        }
        cout << cnt << '\n';
    }
    return 0;
}

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.

3 participants