Title Link: http://poj.org/problem?id=3301
Texas Trip
Time Limit: 1000MS |
|
Memory Limit: 65536K |
Total Submissions: 4935 |
|
Accepted: 1543 |
Description
After a day trips with his friend Dick, Harry noticed a strange pattern of tiny holes in the door of his SUV. The local American Tire store sells fiberglass patching material only in square sheets. What's the smallest patch that Harry needs to fix his door?
Assume that the holes is points on the integer lattice in the plane. Your job is to find the area of the smallest square that would cover all the holes.
Input
The first line of input contains a single integerT expressed in decimal with no leading zeroes, denoting the numb Er of test cases to follow. The subsequent lines of input describe the test cases.
Each test case is begins with a single line, containing a single integern expressed in decimal with no leading Zeroe s, the number of points to follow; Each of the followingn lines contains-integers x and y, both expressed in decimal with no l Eading zeroes, giving the coordinates of one of your points.
You are guaranteed this T ≤30 and that no data set contains more than points. All points with each data set would be is no more than to units away from (0,0).
Output
Print, on a places of precision, and the area of the smallest square containing all of your point S.
Sample Input
24-1-11-11 1-1 1410 110-1-10 1-10-1
Sample Output
4.00242.00
SourceWaterloo Local Contest, 2007.7.14
Idea: Single-peak function to find the extremum problem. The optimal solution is obtained by the three-point angle [0,90].
Directly attach the AC code:
#include <cstdio> #include <cmath> #include <algorithm>//#pragma comment (linker, "/stack:102400000, 102400000 ") using namespace Std;const int maxn = 35;const double eps = 1e-8;const double pi = ACOs ( -1.0); const int inf = 0x 3f3f3f3f;struct node{double x, y;} p[maxn];int n;double filter (double x) {double maxx=-inf, minx=inf, Maxy=-inf, Miny=inf; for (int i=0; i<n; ++i) {maxx = Max (Maxx, P[i].x*cos (x)-p[i].y*sin (x)); Maxy = max (Maxy, P[i].x*sin (x) +p[i].y*cos (x)); miny = min (miny, P[i].x*sin (x) +p[i].y*cos (x)), minx = min (Minx, P[i].x*cos (x)-p[i].y*sin (x));} Return Max (Maxx-minx, maxy-miny);} int main () {#ifdef localfreopen ("Input.txt", "R", stdin), Freopen ("Output.txt", "w", stdout), #endifint t;scanf ("%d", &t), while (t--) {scanf ("%d", &n), for (int i=0; i<n; ++i) scanf ("%lf%lf", &p[i].x, &p[i].y);d ouble l= 0.0, r=pi/2.0, Mid, Tri;while (R-l > EPs) {mid = (r+l)/2.0;tri = (r+mid)/2.0;if (Filter (mid) > filter (tri)) L = Mid;el Ser = tri;} Double ans = filter (l);p rintf ("%.2f\n", Ans*ans);} return 0;}
POJ 3301 Texas Trip