Skip to content

Conversation

@froglike6
Copy link
Collaborator

@froglike6 froglike6 commented Apr 11, 2025

πŸ”— 문제 링크

곰곰이와 μ‹œμ†Œ

βœ”οΈ μ†Œμš”λœ μ‹œκ°„

30λΆ„

✨ μˆ˜λ„ μ½”λ“œ

ChatGPT Image 2025λ…„ 4μ›” 11일 μ˜€ν›„ 05_52_03

μˆ˜λ„μ½”λ“œ

ν•¨μˆ˜ μ‹œμž‘:

  μž…λ ₯ N, L ← 첫 번째 μ€„μ—μ„œ 읽음

  x_list ← 두 번째 μ€„μ—μ„œ 곡백으둜 κ΅¬λΆ„λœ N개의 μ •μˆ˜ μž…λ ₯ λ°›μŒ
  w_list ← μ„Έ 번째 μ€„μ—μ„œ 곡백으둜 κ΅¬λΆ„λœ N개의 μ •μˆ˜ μž…λ ₯ λ°›μŒ

  total_weight ← 0
  weighted_sum ← 0

  반볡 i = 0λΆ€ν„° N - 1κΉŒμ§€:
    total_weight ← total_weight + w_list[i]
    weighted_sum ← weighted_sum + (x_list[i] Γ— w_list[i])

  pivot ← weighted_sum Γ· total_weight

  μ†Œμˆ˜μ  μ•„λž˜ 10μžλ¦¬κΉŒμ§€ pivot 좜λ ₯

ν•¨μˆ˜ μ’…λ£Œ

μ‹œν—˜κΈ°κ°„μ΄λΌ κ°„λ‹¨ν•œ 문제λ₯Ό λ“€κ³  μ™”μŠ΅λ‹ˆλ‹€(μ›λž˜ κ³„νšμ€ λ³Όλ‘κ»μ§ˆμ΄μ—ˆμŠ΅λ‹ˆλ‹€...).

λ¬Έμ œμ—μ„œ μ‹œμ†Œμ˜ 길이와, κ·Έ μœ„μ— λ†“μ—¬μžˆλŠ” μΉ˜ν‚¨λ“€μ˜ λ¬΄κ²Œμ™€ κ·Έ μœ„μΉ˜λ“€μ„ μ€λ‹ˆλ‹€. 이 μž…λ ₯듀을 기반으둜, 받침점이 어디에 μžˆμ–΄μ•Ό μˆ˜ν‰μ΄ λ˜λŠ”μ§€ 좜λ ₯ν•˜λŠ” 물리학 λ¬Έμ œμž…λ‹ˆλ‹€.

μ €λŠ” κ°„λ‹¨νžˆ 토크 ν‰ν˜•μ„ μ΄μš©ν•΄μ„œ, 식을 λ‹€μŒκ³Ό 같이 μ„Έμ› μŠ΅λ‹ˆλ‹€.
$$\sum_{i=1}^{N} w_i \cdot (x_i - x) = 0$$

이 식을 μ •λ¦¬ν•˜λ©΄ λ‹€μŒκ³Ό 같이 $x$에 λŒ€ν•΄ 정리가 λ©λ‹ˆλ‹€.
$$x = \frac{\sum_{i=1}^{N} w_i x_i}{\sum_{i=1}^{N} w_i}$$

λ”°λΌμ„œ for문으둜 λͺ¨λ“  μΉ˜ν‚¨λ“€μ„ λŒμ•„κ°€λ©΄μ„œ μˆ˜μ‹μ„ κ³„μ‚°ν•˜μ˜€μŠ΅λ‹ˆλ‹€.

πŸ“š μƒˆλ‘­κ²Œ μ•Œκ²Œλœ λ‚΄μš©

Copy link
Contributor

@dohyeondol1 dohyeondol1 left a comment

Choose a reason for hiding this comment

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

문제만 읽고 식이 μ„Έμ›Œμ Έμ„œ λ°”λ‘œ μ œμΆœν–ˆλ‹€κ°€ λͺ‡ λ²ˆμ„ ν‹€λ ΈλŠ”μ§€..

μ €λŠ” accumulateν•¨μˆ˜λ₯Ό μ΄μš©ν•΄ w의 λˆ„μ  합을 κ΅¬ν•˜κ³ ,
λ„ν˜„λ‹˜μ˜ 식과 같은 μ‹μœΌλ‘œ ν•΄κ²°ν•˜μ˜€μŠ΅λ‹ˆλ‹€.

쀑간에 μžλ£Œν˜•μ„ μ œλŒ€λ‘œ λͺ» λ§žμΆ”λŠ” λ°”λžŒμ— λͺ‡λ²ˆ ν‹€λ Έλ„€μš”...
accumulateν•¨μˆ˜μ—μ„œλ„,
μ„Έ 번째 인자λ₯Ό 0으둜 μ„€μ •ν•΄ λ†“μœΌλ©΄ λ§μ…ˆμ΄ μ •μˆ˜ 연산이 λœλ‹€λŠ” 사싀을 μ΄μ œμ•Ό μ•Œκ²Œ λ˜μ—ˆμŠ΅λ‹ˆλ‹€..

C++ μ½”λ“œ
#include <iostream>
#include <vector>
#include <numeric>
#include <iomanip>
using namespace std;

int main() {
    cin.tie(0)->sync_with_stdio(0);
    
    int N, L;
    cin >> N >> L;
    
    vector<int> x(N);
    for(int &position : x)
        cin >> position;
    
    vector<int> w(N);
    for(int &weight : w)
        cin >> weight;
    
    double totalW = accumulate(w.begin(), w.end(), 0.0);
    double totalXTimesW = 0.0;
    for(int i = 0; i < N; i++)
        totalXTimesW += static_cast<double>(x[i]) * w[i];
    
    double result = totalXTimesW / totalW;
    
    cout << fixed << setprecision(10) << result << '\n';
    
    return 0;
}

μ˜€λ²„ν”Œλ‘œμš°λ₯Ό 쑰심, 또 쑰심해야 ν•œλ‹€λŠ” κ±Έ λŠκΌˆμŠ΅λ‹ˆλ‹€..

caucsejunseo
caucsejunseo approved these changes Apr 29, 2025
Copy link
Collaborator

@caucsejunseo caucsejunseo left a comment

Choose a reason for hiding this comment

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

식을 μ“΄ λ‹€μŒ x에 λŒ€ν•˜μ—¬ μ •λ¦¬ν•˜λŠ” 방식이 μˆ˜ν•™μ„ ν’€ λ•ŒλŠ” λ‹Ήμ—°ν•˜κ²Œ ν•˜λŠ”λ° λ°±μ€€ 문제λ₯Ό ν’€ λ•ŒλŠ” μ–΄μƒ‰ν•˜λ„€μš”. μ²˜μŒμ— μ–΄λ–»κ²Œ ν•΄μ•Ό ν•˜λ‚˜ κ³ λ―Όν–ˆμŠ΅λ‹ˆλ‹€...
μ˜€λžœλ§Œμ— 물리 문제 μž¬λ°Œμ—ˆμŠ΅λ‹ˆλ‹€.

@froglike6 froglike6 changed the base branch from 7-froglike6 to main May 1, 2025 23:25
Copy link
Collaborator

@hadongun hadongun left a comment

Choose a reason for hiding this comment

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

μ˜€λžœλ§Œμ— 식을 μ„Έμš°λ € ν•˜λ‹ˆ 자꾸 λ‡Œμ •μ§€κ°€ μ˜€λ„€μš”..γ…Žγ…Ž
전체적인 μ½”λ“œλŠ” λΉ„μŠ·ν•œλ° ν™•μ‹€νžˆ λ„ν˜„λ‹˜μ˜ 파이썬 μ½”λ“œκ°€ κΉ”λ”ν•˜μ‹  것 κ°™μ•„μš”!
zipν•¨μˆ˜λž‘ ν¬λ§€νŒ… 문법도 λ°°μ›Œ κ°€μš”.!

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.

5 participants