Untitled
unknown
plain_text
2 years ago
2.3 kB
8
Indexable
Point of balance // In Practice, You should use the statndard input/output // in order to receive a score properly. // Do not use file input and output. Please be very careful. #include<iostream> using namespace std; double arr[10]; int loca[10]; int wei[10]; int main(int argc, char** argv) { int test_case; int T; int Answer; int N; ios::sync_with_stdio(false); /* The freopen function below opens input.txt in read only mode and sets your standard input to work with the opened file. When you test your code with the sample data, you can use the function below to read in from the sample data file instead of the standard input. So. you can uncomment the following line for your local test. But you have to comment the following line when you submit for your scores. */ freopen("input.txt", "r", stdin); //cin >> T; cout.setf(ios::fixed); cout.setf(ios::showpoint); cout.precision(10); /* Read each test case from standard input. */ for(test_case = 1; test_case <= 10; ++test_case) { Answer = 0; ///////////////////////////////////////////////////////////////////////////////////////////// /* Please, implement your algorithm from this section. */ ///////////////////////////////////////////////////////////////////////////////////////////// cin >> N; for (int i=0;i<N;i++) { cin >> loca[i]; } for (int i=0;i<N;i++) { cin >> wei[i]; } for (int i=0;i<N-1;i++) { double left = loca[i]; double right = loca[i+1]; double x=1; while(x>=0.0000000001) { double f1=0; double f2=0; double mid = (left+right)/2; arr[i]=mid; for (int k=0;k<=i;k++) { f1=f1+wei[k]/((arr[i]-loca[k])*(arr[i]-loca[k])); } for (int k=N-1;k>i;k--) { f2=f2+wei[k]/((arr[i]-loca[k])*(arr[i]-loca[k])); } if (f1==f2) break; else if(f1>f2) { x=right-left; left=mid; } else { x=right-left; right=mid; } } } cout << "#" << test_case << " "; for (int j=0; j<N-1;j++) { //printf("%0.10lf", arr[j]); cout << arr[j] << " "; } cout << endl; // Print the answer to standard output(screen). //cout << "#" << test_case << " " << Answer << endl; } return 0;//Your program should return 0 on normal termination. }
Editor is loading...