poj3301 Texas Trip "three-point algorithm"

Source: Internet
Author: User
Tags cos sin

Title Address: http://poj.org/problem?id=3301

Description: T group test data, each set of lines input n, representing n points, then enter the coordinates of these n points, coordinates are integers.

Requires a minimum square to cover all the points, output its area, accurate to two digits after the decimal point.

Algorithm ideas: enumeration angle, calculate area, three-point enumeration

(can refer to: Programming problem solving Strategy FAI ... 394 pages)

Code:

#include <stdio.h> #include <string.h> #include <stdlib.h> #include <ctype.h> #include < math.h> #include <stack> #include <queue> #include <iostream> #include <string> #include < Algorithm> #define EPS 1e-9using namespace std;int tg, N;int x[1000], y[1000];d ouble calc (double d) {int I, j;double dis1 , Dis2,dis;dis=0.0;for (i=1; i<n; i++) {for (j=i+1; j<=n; J + +) {dis1=fabs (cos (d) * (Y[i]-y[j])-sin (d) * (X[i]-x[j])); Dis2=fabs (sin (d) * (Y[i]-y[j]) +cos (d) * (X[i]-x[j]), if (Dis < dis1) dis = dis1;if (dis < dis2) dis = Dis2;}} return (Dis*dis);} int main () {double ll, RR, Mid, midmid;double S1, S2;cin>>tg;while (tg--) {cin>>n;for (int i=1; i<=n; i++) { Cin>>x[i]>>y[i];} ll=0.0; Rr=acos (-1.0); rr=180.0 determines the interval while (rr-ll>=eps) {mid = (LL+RR)/2; midmid= (Rr+mid)/2;s1=calc (mid); S2=calc (Midmid); if (S1&LT;S2) { Rr=midmid;} Else{ll=mid;}}    printf ("%0.2lf\n", S1&LT;S2?S1:S2);} return 0;}

poj3301 Texas Trip "three-point algorithm"

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.