Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.io.*;
- import java.math.*;
- class Solution {
- public static void main(String args[])
- {
- Scanner in = new Scanner(System.in);
- Map<Integer, Double> map = new HashMap<>();
- int N = in.nextInt();
- int M = in.nextInt();
- for (int i = 0; i < N; i++) {
- int[] tab = new int[M];
- for (int j = 0; j < M; j++) {
- tab[j] = in.nextInt();
- }
- map.put(i+1,variance(tab));
- }
- double min = -1;
- int indiceMin = 1;
- for(int x : map.keySet())
- {
- double y = map.get(x);
- if(min == -1)
- min = y;
- else
- {
- if(y < min)
- {
- min = y;
- indiceMin = x;
- }
- }
- }
- System.out.println(indiceMin);
- }
- public static double variance(int[] tab)
- {
- double moy = 0.0;
- for(int x : tab)
- moy += x;
- moy /= tab.length;
- double variance = 0.0;
- for(int x : tab)
- {
- double y = Math.pow(x-moy,2);
- variance += y;
- }
- return variance;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement