zoukankan      html  css  js  c++  java
  • poj3301Texas Trip(三分)

    链接

    这题还真没看出来长得像三分。。

    三分角度,旋转点。

    最初找到所有点中最左边、右边、上边、下边的点,正方形边长为上下距离和左右距离的最大值,如图样例中的四个点(蓝色的),初始正方形为红色的正方形。

    当4个点旋转了一定角度之后,根据上下及左右的最大距离可以画出蓝色的正方形,而且现在的正方形更小,可以看出角度最大为pi/2即可。

    至于为什么是三分。。大家都说是三分。。感觉是个三分。。画起来的确是个凸性函数。。三分交上AC了!。。所以就是三分吧。

     1 #include <iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<algorithm>
     5 #include<stdlib.h>
     6 #include<vector>
     7 #include<cmath>
     8 #include<queue>
     9 #include<set>
    10 using namespace std;
    11 #define N 510
    12 #define LL long long
    13 #define INF 0xfffffff
    14 const double eps = 1e-8;
    15 const double pi = acos(-1.0);
    16 const double inf = ~0u>>2;
    17 struct point
    18 {
    19     double x,y;
    20     point(double x =0 ,double y = 0):x(x),y(y){}
    21 }p[N];
    22 int n;
    23 point rotate(point a,double rad)
    24 {
    25     return point(a.x*cos(rad)-a.y*sin(rad),a.x*sin(rad)+a.y*cos(rad));
    26 }
    27 double calc(double k)
    28 {
    29     int i;
    30     double minx = INF,miny = INF;
    31     double maxx = -INF,maxy = -INF;
    32     for(i = 1 ; i <= n; i++)
    33     {
    34         point pp;
    35         pp = rotate(p[i],k);
    36         minx = min(minx,pp.x),miny = min(miny,pp.y);
    37         maxx = max(maxx,pp.x),maxy = max(maxy,pp.y);
    38     }
    39     return max(maxx-minx,maxy-miny);
    40 }
    41 double solve()
    42 {
    43     double M,RM;
    44     double L = 0.0;
    45     double R = pi/2;
    46     while (L + eps < R)
    47     {
    48         M = (L + R) / 2;
    49         RM = (M + R) / 2;
    50         if (calc(M) < calc(RM))
    51             R = RM;
    52         else
    53             L = M;
    54     }
    55     return calc(M);
    56 }
    57 int main()
    58 {
    59     int t,i;
    60     cin>>t;
    61     while(t--)
    62     {
    63         scanf("%d",&n);
    64         for(i = 1 ;i  <= n ;i++)
    65         {
    66             scanf("%lf%lf",&p[i].x,&p[i].y);
    67         }
    68         double ans = solve();
    69         printf("%.2f
    ",ans*ans);
    70     }
    71     return 0;
    72 }
    View Code
  • 相关阅读:
    codevs 1115 开心的金明
    POJ 1125 Stockbroker Grapevine
    POJ 2421 constructing roads
    codevs 1390 回文平方数 USACO
    codevs 1131 统计单词数 2011年NOIP全国联赛普及组
    codevs 1313 质因数分解
    洛谷 绕钉子的长绳子
    洛谷 P1276 校门外的树(增强版)
    codevs 2627 村村通
    codevs 1191 数轴染色
  • 原文地址:https://www.cnblogs.com/shangyu/p/3916965.html
Copyright © 2011-2022 走看看