POJ 2187 Beauty Contest

Source: Internet
Author: User

Beauty ContestTime Limit: 3000 MS Memory Limit: 65536 KTotal Submissions: 22893 Accepted: 6994 DescriptionBessie, Farmer John's prize cow, has just won first place in a bovine beauty autcontest, earning the title 'Miss Cow world '. as a result, Bessie will make a tour of N (2 <= N <= 50,000) farms around the world order to spread goodwill between farmers and their cows. for simplicity, the world will B E represented as a two-dimen=plane, where each farm is located at a pair of integer coordinates (x, y), each having a value in the range-10,000... 10,000. no two farms share the same pair of coordinates. even though Bessie travels directly in a straight line between pairs of farms, the distance between some farms can be quite large, so she wants to bring a suitcase full of hay with her so s He has enough food to eat on each leg of her journey. since Bessie refills her suitcase at every farm she visits, she wants to determine the maximum possible distance she might need to travel so she knows the size of suitcase she must bring. help Bessie by computing the maximum distance among all pairs of farms. input * Line 1: A single integer, N * Lines 2 .. N + 1: Two space-separated integers x and y Specifying coordinate of each farm Output * Line 1: A single integer that is the squared distance between the pair of farms that are farthest apart from each other. sample Input40 00 11 11 0 Sample Output2HintFarm 1 (0, 0) and farm 3 (1, 1) have the longest distance (square root of 2) [cpp] # include <stdio. h> # include <string. h> # include <math. h> struct map {int x, y;} [50010]; struct num {int x, y;} statck [50010]; int chacheng (int x1, int y1, int x2, int y2) {int t = x1 * y2-y1 * x2; if (t> 0) {return 1;} else if (t <0) {return-1 ;} else {return 0 ;}} int cmp (const void * e, const void * f) {struct map * p1 = (struct map *) e; struct map * p2 = (struct map *) f; int x1, y1, x2, y2, t; x1 = p1-> x-a [0]. x; y1 = p1-> y-a [0]. y; x2 = p2-> x-a [0]. x; y2 = p2-> y-a [0]. y; t = chacheng (x1, y1, x2, y2); if (t = = 1) {return-1;} else if (t =-1) {return 1 ;} else {return (x1 * x1 + y1 * y1-(x2 * x2 + y2 * y2);} int main () {int I, j, n, m, s, t, pos1, top, dis; int x1, y1, x2, y2; while (scanf ("% d", & n )! = EOF) {for (I = 0; I <= n-1; I ++) {scanf ("% d", & a [I]. x, & a [I]. y); if (I = 0) {pos1 = I;} else if (a [I]. y <a [pos1]. y) | (a [I]. y = a [pos1]. y & a [I]. x <a [pos1]. x) {pos1 = I ;}t = a [0]. x; a [0]. x = a [pos1]. x; a [pos1]. x = t; t = a [0]. y; a [0]. y = a [pos1]. y; a [pos1]. y = t; qsort (a + 1, n-1, sizeof (a [0]), cmp); top = 0; statck [top]. x = a [0]. x; statck [top ++]. y = a [0]. y; statck [top]. x = a [1]. x; statck [top ++]. y = a [1]. y; for (I = 2; I <= n-1;) {if (top> = 2) {x1 = statck [top-1]. x-statck [top-2]. x; y1 = statck [top-1]. y-statck [top-2]. y; x2 = a [I]. x-statck [top-1]. x; y2 = a [I]. y-statck [top-1]. y; t = chacheng (x1, y1, x2, y2); if (t = 1 | t = 0) {statck [top]. x = a [I]. x; statck [top ++]. y = a [I]. y; I ++;} else {top -- ;}} else {statck [top]. x = a [I]. x; statck [top ++]. y = a [I]. y; I ++ ;}for (I = 0, dis = 0; I <= top-1; I ++) {for (j = I + 1; j <= top-1; j ++) {x1 = statck [j]. x-statck [I]. x; y1 = statck [j]. y-statck [I]. y; if (x1 * x1 + y1 * y1)> dis) {dis = x1 * x1 + y1 * y1 ;}} printf ("% d \ n ", dis);} return 0 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.