Created
February 11, 2020 04:56
-
-
Save roharon/c02c57cb0a618e90544dad2462a6a9c6 to your computer and use it in GitHub Desktop.
g++ array[2] windows, linux
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <cmath> | |
| using namespace std; | |
| typedef long double ld; | |
| ld get_m(int K, int idx, int array[]){ | |
| ld m = 0; | |
| for(int i =idx; i<idx+K; i++){ | |
| printf("get_m arr[i] : %d\n", array[i]); | |
| m+=array[i]; | |
| } | |
| cout<<"m : "<<m/K<<endl; | |
| return ld(m/K); | |
| } | |
| ld get_b(int K, int idx, int arr[], ld m){ | |
| ld b=0; | |
| for(int i = idx; i < idx+K; i++){ | |
| printf("get_b idx : %d , arr[i] : %d\n", i, arr[i]); | |
| b += ((arr[i]-m)*(arr[i]-m)); | |
| } | |
| b = b/K; | |
| cout<<"v : "<<b<<endl; | |
| return sqrt(b); | |
| } | |
| int main(){ | |
| int N,K; | |
| ld minimum = 9999999; | |
| ld M, B; | |
| cin >> N >> K; | |
| int* dolls_like = new int(N); | |
| for(int i = 0; i<N; i++){ | |
| cin >> dolls_like[i]; | |
| } | |
| for(int _k = K; _k <= N; _k++){ | |
| for(int idx = 0; idx<=N-_k; idx++){ | |
| M = get_m(_k, idx, dolls_like); | |
| cout<<"main m "<<M<<endl; | |
| printf("main [2] : %d\n",dolls_like[2]); | |
| B = get_b(_k, idx, dolls_like, M); | |
| cout<<"main b "<<B<<endl; | |
| if(B<minimum){ | |
| minimum=B; | |
| } | |
| } | |
| } | |
| printf("%.10lf", minimum); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment