Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.*;
- public class CF {
- class Thing implements Comparable<Thing> {
- int id;
- double d;
- Thing(int id, double d) {
- this.id = id;
- this.d = d;
- }
- @Override
- public int compareTo(Thing o) {
- return Double.compare(o.d, d);
- }
- }
- void solve() {
- int n = in.nextInt();
- int[] x = new int[n];
- int[] y = new int[n];
- for (int i = 0; i < n; i++) {
- x[i] = in.nextInt();
- y[i] = in.nextInt();
- }
- long[] ans = new long[n + 1];
- Random rnd = new Random(123);
- Thing[] a = new Thing[n];
- for (int i = 0; i < n; i++)
- a[i] = new Thing(i, 0);
- for (int ITER = 0; ITER < 5000; ITER++) {
- double angle = rnd.nextDouble() * Math.PI * 2;
- double x1 = Math.cos(angle);
- double y1 = Math.sin(angle);
- for (int i = 0; i < n; i++) {
- a[i].id = i;
- a[i].d = x1 * x[i] + y1 * y[i];
- }
- Arrays.sort(a);
- long nowX = 0, nowY = 0;
- for (int i = 0; i < n; i++) {
- nowX += x[a[i].id];
- nowY += y[a[i].id];
- long dist = nowX * nowX + nowY * nowY;
- ans[i + 1] = Math.max(ans[i + 1], dist);
- }
- }
- for (int i = 1; i <= n; i++) {
- out.println(Math.sqrt(ans[i]));
- }
- }
- FastScaner in;
- PrintWriter out;
- void run() {
- in = new FastScaner(System.in);
- out = new PrintWriter(System.out);
- solve();
- out.close();
- }
- void runWithFiles() {
- in = new FastScaner(new File("input.txt"));
- try {
- out = new PrintWriter(new File("output.txt"));
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- }
- solve();
- out.close();
- }
- public static void main(String[] args) {
- Locale.setDefault(Locale.US);
- new CF().run();
- }
- class FastScaner {
- BufferedReader br;
- StringTokenizer st;
- FastScaner(InputStream is) {
- br = new BufferedReader(new InputStreamReader(is));
- }
- FastScaner(File f) {
- try {
- br = new BufferedReader(new FileReader(f));
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- }
- }
- String next() {
- while (st == null || !st.hasMoreElements()) {
- String s = null;
- try {
- s = br.readLine();
- } catch (IOException e) {
- e.printStackTrace();
- }
- if (s == null)
- return null;
- st = new StringTokenizer(s);
- }
- return st.nextToken();
- }
- int nextInt() {
- return Integer.parseInt(next());
- }
- long nextLong() {
- return Long.parseLong(next());
- }
- double nextDouble() {
- return Double.parseDouble(next());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment