-
Notifications
You must be signed in to change notification settings - Fork 1
8-froglike6 #31
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-froglike6 #31
Conversation
dohyeondol1
left a comment
There was a problem hiding this 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
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μμ μ΄ λ€μ xμ λνμ¬ μ 리νλ λ°©μμ΄ μνμ ν λλ λΉμ°νκ² νλλ° λ°±μ€ λ¬Έμ λ₯Ό ν λλ μ΄μνλ€μ. μ²μμ μ΄λ»κ² ν΄μΌ νλ κ³ λ―Όνμ΅λλ€...
μ€λλ§μ 물리 λ¬Έμ μ¬λ°μμ΅λλ€.
hadongun
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μ€λλ§μ μμ μΈμ°λ € νλ μκΎΈ λμ μ§κ° μ€λ€μ..γ
γ
μ 체μ μΈ μ½λλ λΉμ·νλ° νμ€ν λνλμ νμ΄μ¬ μ½λκ° κΉλνμ κ² κ°μμ!
zipν¨μλ ν¬λ§€ν
λ¬Έλ²λ λ°°μ κ°μ.!
π λ¬Έμ λ§ν¬
κ³°κ³°μ΄μ μμ
βοΈ μμλ μκ°
30λΆ
β¨ μλ μ½λ
μλμ½λ
μνκΈ°κ°μ΄λΌ κ°λ¨ν λ¬Έμ λ₯Ό λ€κ³ μμ΅λλ€(μλ κ³νμ λ³Όλ‘κ»μ§μ΄μμ΅λλ€...).
λ¬Έμ μμ μμμ κΈΈμ΄μ, κ·Έ μμ λμ¬μλ μΉν¨λ€μ 무κ²μ κ·Έ μμΉλ€μ μ€λλ€. μ΄ μ λ ₯λ€μ κΈ°λ°μΌλ‘, λ°μΉ¨μ μ΄ μ΄λμ μμ΄μΌ μνμ΄ λλμ§ μΆλ ₯νλ 물리ν λ¬Έμ μ λλ€.
μ λ κ°λ¨ν ν ν¬ ννμ μ΄μ©ν΄μ, μμ λ€μκ³Ό κ°μ΄ μΈμ μ΅λλ€.
$$\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λ¬ΈμΌλ‘ λͺ¨λ μΉν¨λ€μ λμκ°λ©΄μ μμμ κ³μ°νμμ΅λλ€.π μλ‘κ² μκ²λ λ΄μ©