0% found this document useful (0 votes)
41 views2 pages

TCS Code Vita Question 1

Uploaded by

skygennetsis14
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views2 pages

TCS Code Vita Question 1

Uploaded by

skygennetsis14
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

import [Link].

*;

import [Link].*;

class Main {

static class Point implements Comparable<Point> {

int x, y;

Point(int x, int y) { this.x = x; this.y = y; }

public int compareTo(Point p) {

if (this.x != p.x) return this.x - p.x;

return this.y - p.y;

// Cross product to check turn direction

static long cross(Point o, Point a, Point b) {

return (long)(a.x - o.x) * (b.y - o.y) - (long)(a.y - o.y) * (b.x - o.x);

// Distance between two points

static double dist(Point a, Point b) {

return [Link]((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));

public static void main(String[] args) {

Scanner sc = new Scanner([Link]);

int N = [Link]();

Point[] points = new Point[N];


for (int i = 0; i < N; i++) {

points[i] = new Point([Link](), [Link]());

[Link](points);

// Build lower hull

List<Point> lower = new ArrayList<>();

for (Point p : points) {

while ([Link]() >= 2 && cross([Link]([Link]()-2),


[Link]([Link]()-1), p) <= 0) {

[Link]([Link]()-1);

[Link](p);

// Perimeter calculation for lower hull

double perimeter = 0;

for (int i = 0; i < [Link]() - 1; i++) {

perimeter += dist([Link](i), [Link](i+1));

[Link]([Link](perimeter));

You might also like