fragment-header
fragment-markdown
홈
로그인
로그아웃
내 블로그
설정
로그인
백준 25996 (C++) Equalising Audio
최초 업로드: 2025-09-21 06:27:50
최근 수정 시간: 2025-09-21 06:27:50
게시자: rlatjwls3333
카테고리: 백준
조회수: 3
# [Silver III] Equalising Audio [문제 링크](https://www.acmicpc.net/problem/25996) ## 문제 설명 <p>As a radio engineer at the Balanced Audio Podcast \copyright{} your job is to deliver an equal listening experience at all times. You did a poll among the listeners and they are especially concerned about fluctuations in loudness. To resolve this you bought a transformer to equalise the audio, but alas, its software got corrupted during transport.</p> <p>Your job is to rewrite the equalising software. As input the transformer gets $n$ amplitudes $a_1, \ldots, a_n$, with an average perceived loudness of $\frac{1}{n}\sum_{i=1}^n a_i^2$. The output should contain the same amplitudes, but renormalised by some constant positive factor, such that the average perceived loudness is $x$. There is one exception: total silence should always be preserved.</p> ## 입력 <p>The input consists of:</p> <ul> <li>One line with a two integers $n$ and $x$ ($1\leq n\leq 10^5$, $0 \leq x \leq 10^6)$, the number of amplitudes and the average perceived loudness to achieve.</li> <li>One line with $n$ integers $a_1, \ldots, a_n$ ($\left| a_i \right| \leq 10^6$), the amplitudes.</li> </ul> ## 출력 <p>Output one line containing $n$ numbers, the renormalised amplitudes with an average perceived loudness of $x$.</p> <p>Your answers should have an absolute or relative error of at most $10^{-6}$.</p> ## 풀이 평균이 0인 경우 전부 0으로 출력하는 케이스를 고려해야 한다. 나머지 경우는 x를 평균으로 나누고 제곱근 씌워서 모든 수에 곱해주면 된다. ``` c++ #include<bits/stdc++.h> using namespace std; typedef long double ld; int main() { ios::sync_with_stdio(0); cin.tie(0); ld n, x; cin >> n >> x; ld average=0; vector<ld> a(n); for(int i=0;i<n;i++) { cin >> a[i]; average += a[i]*a[i]; } average /= n; if(average==0) { for(int i=0;i<n;i++) cout << "0 "; return 0; } ld w = sqrtl(x/average); for(int i=0;i<n;i++) cout << fixed << setprecision(6) << a[i]*w << ' '; } ```