zoukankan      html  css  js  c++  java
  • poj 1266 Cover an Arc.

    http://poj.org/problem?id=1266

    Cover an Arc.
    Time Limit: 1000MS   Memory Limit: 10000K
    Total Submissions: 823   Accepted: 308

    Description

    A huge dancing-hall was constructed for the Ural State University's 80-th anniversary celebration. The size of the hall is 2000 * 2000 metres! The floor was made of square mirror plates with side equal to 1 metre. Then the walls were painted with an indelible paint. Unfortunately, in the end the painter flapped the brush and the beautiful mirror floor was stained with the paint. But not everything is lost yet! The stains can be covered with a carpet. 
    Nobody knows why, but the paint on the floor formed an arc of a circle (a centre of the circle lies inside the hall). The dean of the Department of Mathematics and Mechanics measured the coordinates of the arc's ends and of some other point of the arc (he is sure that this information is quite enough for any student of the Ural State University). The dean wants to cover the arc with a rectangular carpet. The sides of a carpet must go along the sides of the mirror plates (so, the corners of the carpet must have integer coordinates). 
    You should find the minimal square of such a carpet. 

    Input

    The input consists of six integers. At first the coordinates of the arc's ends are given. The co-ordinates of an inner point of the arc follow them. Absolute value of coordinates doesn't exceed 1000. The points don't belong the same straight line. The arc lies inside the square [-1000,1000] * [-1000,1000].

    Output

    You should write to the standard output the minimal square of the carpet covering this arc.

    Sample Input

    476 612
    487 615
    478 616

    Sample Output

    66

    Source

     
     
     
    分析:
    几何题, 求正方形覆盖圆弧的面积。
     
     
     
    AC代码:
     1 #include<iostream>
     2 #include<algorithm>
     3 #include<stdio.h>
     4 #define max(a,b) a>b?a:b
     5 #define min(a,b) a>b?b:a
     6 #include<math.h>
     7 using namespace std;
     8 #define eps 1e-8
     9 struct point{double x,y;};
    10 struct line {point a,b;};
    11 point a,b,c;
    12 double xmult(point p1,point p2,point p0){
    13  return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);
    14 }
    15 bool pp(point p)
    16 {
    17     double t1,t2;
    18     t1=(xmult(a,c,b));
    19     t2=(xmult(a,p,b));
    20     if ((t1<0&&t2<0)||(t1>0&&t2>0)) return true;
    21     return false;
    22 }
    23 double distan (point p1,point p2)
    24 {
    25     return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));
    26 }
    27 point inter(line u,line v)
    28 {
    29     point ret = u.a;
    30     double t = ((u.a.x-v.a.x)*(v.a.y-v.b.y)-(u.a.y-v.a.y)*(v.a.x-v.b.x))/((u.a.x-u.b.x)*(v.a.y-v.b.y)-(u.a.y-u.b.y)*(v.a.x-v.b.x));
    31     ret.x +=(u.b.x-u.a.x)*t;
    32     ret.y +=(u.b.y-u.a.y)*t;
    33     return ret;
    34 }
    35 point circle(point a,point b,point c )
    36 {
    37     line u,v;
    38     u.a.x =(a.x+b.x)/2;
    39     u.a.y = (a.y+b.y)/2;
    40     u.b.x = u.a.x - a.y+b.y;
    41     u.b.y = u.a.y + a.x-b.x;
    42     v.a.x = (a.x+c.x)/2;
    43     v.a.y = (a.y+c.y)/2;
    44     v.b.x = v.a.x - a.y+c.y;
    45     v.b.y = v.a.y+a.x-c.x;
    46     return inter(u,v);
    47 }
    48 int main()
    49 {
    50     point d,e,p;
    51     int cas =1;
    52     while(~scanf("%lf %lf %lf %lf %lf %lf",&a.x,&a.y,&b.x,&b.y,&c.x,&c.y))
    53     {
    54         d = circle(a,b,c);
    55         double bj = distan(d,a);
    56         double maxx,maxy,minx,miny;
    57         double dd=d.x,yy=d.y;
    58         int ax,bx,cx,ay,by,cy;
    59         maxx=max(a.x,b.x);
    60         maxx=max(maxx,c.x);
    61         minx=min(a.x,b.x);
    62         minx=min(minx,c.x);
    63         maxy=max(a.y,b.y);
    64         maxy=max(maxy,c.y);
    65         miny=min(a.y,b.y);
    66         miny=min(miny,c.y);
    67         p.x=d.x-bj;
    68         p.y=d.y;
    69         if(pp(p))
    70             minx=p.x;
    71         p.x=d.x+bj;
    72         if(pp(p))
    73             maxx=p.x;
    74         p.x=d.x;
    75         p.y=d.y-bj;
    76         if(pp(p))
    77             miny=p.y;
    78         p.y=d.y+bj;
    79         if(pp(p))
    80             maxy=p.y;
    81         cx=(long)ceil(maxx-eps)-(long)floor(minx+eps);
    82         cy=(long)ceil(maxy-eps)-(long)floor(miny+eps);
    83         printf("%d
    ",cx*cy);
    84     }
    85     return 0;
    86 }
  • 相关阅读:
    用友U8存货分类通过DataTable生成EasyUI Tree JSON
    脚本加密与解密
    CKFinker 2.5.0.1 去demo标示
    C#压缩图片时保留原始的Exif信息
    Newtonsoft.Json转换强类型DataTable错误:Self referencing loop detected with type ......
    Access无法启动应用程序,工作组信息文件丢失,或是已被其他用户已独占方式打开
    C#获取邮件客户端保存的邮箱密码
    网站ASHX不执行故障
    水晶报表打印时出现:出现通信错误 将停止打印
    UILabel居上对齐居下对齐类别扩展
  • 原文地址:https://www.cnblogs.com/jeff-wgc/p/4483824.html
Copyright © 2011-2022 走看看