Untitled

 avatar
unknown
plain_text
2 years ago
2.5 kB
4
Indexable
package Point_of_Balance;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class Solution {
	public static void main(String[] args) throws FileNotFoundException {
		System.setIn(new FileInputStream("input.txt"));
		Scanner sc = new Scanner(System.in);
		for (int tc = 1; tc <= 10; tc++){
			int n = sc.nextInt();
			int [] mas = new int [n];
			int [] loc = new int [n];
			double [] ans = new double [n];
			double x = 0;
			double left = 0;
			double right = 0;
			double mid = 0;
			double f1 = 0;
			double f2 = 0;
			for (int i = 0; i < n; i++) {
				loc[i] = sc.nextInt();
			}
			for (int i = 0; i < n; i++) {
				mas[i] = sc.nextInt();
			}
			for (int i = 0; i < n-1; i++) {
				left = loc[i];
				right = loc[i+1];
				x = 1.0;
				while(x>=0.0000000001){
					f1 = 0.0;
					f2 = 0.0;
					mid = (right + left)/2;
					ans[i] = mid;
					for (int k = 0; k <= i ; k++) {
						f1 = f1 + mas[k]/((ans[i]-loc[k])*(ans[i]-loc[k]));
					}
					for (int k = n-1; k > i ; k--) {
						f2 = f2 + mas[k]/((ans[i]-loc[k])*(ans[i]-loc[k]));
					}
					if(f1==f2){
						break;
					}else if(f1 > f2){
						x = right - left;
						left = mid;
					}else{
						x = right - left;
						right = mid;
					}
				}
			}
			System.out.print("#"+tc+" ");
			for (int i = 0; i < n-1; i++) {
				System.out.printf("%.10f",ans[i]);
				System.out.print(" ");
			}
			System.out.println();
		}
	}
}


////


2
1 2 1 1
2
1 2 1 1000
2
457 468 333 321
3
1 2 3 1 2 1
4
2 3 5 7 3 2 7 5
5
3 11 12 19 29 542 661 450 521 366	
6
42 75 88 94 113 144 669 551 355 344 294 155
7
62 86 279 323 363 516 579 810 749 736 297 136 107 52
8
10 34 64 73 93 97 101 122 466 463 441 373 315 292 225 83
10
9 14 38 39 48 73 179 190 207 302 560 497 640 722 437 259 449 470 709 520 
////


#1 1.5000000000 
#2 1.0306534300 
#3 462.5504629633 
#4 1.4060952085 2.5939047915 
#5 2.5328594461 3.7271944335 6.0999536409 
#6 6.3428568767 11.5477377494 15.9641592997 24.9267991616 
#7 57.8805685416 81.8651598883 91.0573691382 105.0835650491 133.2934094882 
#8 74.2211477711 190.6837563313 305.8269181686 348.3304429927 470.2694219293 555.4943093854 
#9 21.5171374463 47.9890597763 68.6536668433 82.9131954024 95.0052272762 99.1999097771 116.4978330952 
#10 11.5573600056 24.0238341337 38.4847676134 44.6137453708 64.7500445424 126.9908128981 184.3221650927 197.9760596291 266.0574653676 
Editor is loading...