Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct Point {
- x: int, y: int,
- function subtr(self: Point, other: Point) -> Point {
- return new Point{x: self.x - other.x, y: self.y - other.y};
- }
- function add(self: Point, other: Point) -> Point {
- return new Point{x: self.x + other.x, y: self.y + other.y};
- }
- function equally(self: Point, other: Point) {
- self.x = other.x;
- self.y = other.y;
- }
- function len2(self: Point) -> int {
- return self.x * self.x + self.y * self.y
- }
- function vecpr(self: Point, other: Point) -> int {
- return self.x * other.y - self.y * other.x;
- }
- function less(self: Point, other: Point) -> bool {
- let x: int = self.vecpr(other);
- if(x != 0) {
- return x > 0;
- }
- else {
- let indef: int = other.len2() - self.len2();
- return indef > 0;
- }
- }
- }
- function get_dist(a: Point, b: Point) -> float {
- let x: int = a.x - b.x;
- let y: int = a.y - b.y;
- return sqrt(float(x * x + y * y));
- }
- function round_f(x: float) -> string {
- x *= float(100);
- let x_t = int(x + 0.5);
- let str = string(x_t % 100);
- while(str.length() < 2) {
- str = "0" + str;
- }
- return string(x_t / 100) + "." + str;
- }
- function solve(input: string) -> string {
- let line = input.split("\n"); let curline: int = 0;
- let t: int = int(line[curline]); curline += 1;
- let ans: string[] = [];
- for(let num = 1; num <= t; num += 1) {
- let arr: Point[] = [];
- let n: int = int(line[curline]); curline += 1;
- for(let j = 0; j < n; j += 1) {
- let inp = line[curline].split(" "); curline += 1;
- let x1: int = int(inp[0]);
- let y1: int = int(inp[1]);
- arr.push(new Point{x: x1, y: y1});
- }
- let lft = new Point{x: arr[0].x, y: arr[0].y};
- let ind_left: int = 0;
- for(let j = 0; j < n; j += 1) {
- if(lft.x > arr[j].x) {
- lft.x = arr[j].x;
- lft.y = arr[j].y;
- ind_left = j;
- }
- if(lft.x == arr[j].x && lft.y > arr[j].y) {
- lft.x = arr[j].x;
- lft.y = arr[j].y;
- ind_left = j;
- }
- }
- let hull: Point[] = [];
- hull.push(lft);
- let to_swap: Point = new Point{x: arr[n - 1].x, y: arr[n - 1].y};
- arr[n - 1] = arr[ind_left];
- arr[ind_left] = to_swap;
- arr.pop();
- n -= 1;
- for(let i = 0; i < n; i += 1) {
- arr[i] = arr[i].subtr(hull[0]);
- }
- arr.sort();
- for(let i = 0; i < n; i += 1) {
- arr[i] = arr[i].add(hull[0]);
- }
- for(let i = 0; i < n; i += 1) {
- while(hull.length() >= 2) {
- let lst: int = hull.length() - 1;
- let v1: Point = hull[lst].subtr(hull[lst - 1]);
- let v2: Point = arr[i].subtr(hull[lst]);
- if(v1.vecpr(v2) > 0) {
- break;
- }
- hull.pop();
- }
- hull.push(arr[i]);
- }
- let res: float = 0.0000;
- n = hull.length();
- hull.push(hull[0]);
- for(let i = 0; i < n; i += 1) {
- res += get_dist(hull[i], hull[i + 1]);
- }
- ans.push(round_f(res));
- }
- return ans.join("\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement