Skip to content

Instantly share code, notes, and snippets.

@MasterAlish
Created October 30, 2013 02:06
Show Gist options
  • Save MasterAlish/7226122 to your computer and use it in GitHub Desktop.
Save MasterAlish/7226122 to your computer and use it in GitHub Desktop.
olymp.krsu.248
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Solution {
private final double y2;
private final double y1;
private final double x2;
private final double x1;
public static void main(String[] args){
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
try {
String[] nums = in.readLine().split(" ");
int x1 = Integer.parseInt(nums[0].trim());
int y1 = Integer.parseInt(nums[1].trim());
int x2 = Integer.parseInt(nums[2].trim());
int y2 = Integer.parseInt(nums[3].trim());
Solution try1 = new Solution(x1,y1,x2,y2);
int result = try1.solve();
System.out.println(result);
} catch (IOException e) {
e.printStackTrace();
}
}
public Solution(int x1, int y1, int x2, int y2) {
this.x1 = x1;
this.x2 = x2;
this.y1 = y1;
this.y2 = y2;
}
private int solve() {
int left = (int) (sqr(x1+x2)+sqr(abs(y1-y2)));
int up = (int) (sqr(y1+y2)+sqr(abs(x1-x2)));
int right = (int) (sqr(100-x1+100-x2)+sqr(abs(y1-y2)));
int down = (int) (sqr(100-y1+100-y2)+sqr(abs(x1-x2)));
return min(min(left, right), min(up,down));
}
private int min(int a, int b){
return a>b?b:a;
}
private double sqr(double d){
return d*d;
}
private double abs(double d){
return Math.abs(d);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment