zoukankan      html  css  js  c++  java
  • 【2011 Greater New York Regional 】Problem G: Rancher's Gift

    计算几何的题目,很简单;

    自己随手敲了个,纪念下!

     1 #include<cstdio>
     2 #include<cmath>
     3 using namespace std;
     4 
     5 struct point
     6 {
     7     double x,y;
     8     point(double x=0,double y=0):x(x),y(y) { }
     9 } a,b,c,d;
    10 
    11 point midd(point a,point b)
    12 {
    13     return point((a.x+b.x)/2.0,(a.y+b.y)/2.0);
    14 }
    15 point operator + (point a,point b)
    16 {
    17     return point(a.x+b.x,a.y+b.y);
    18 }
    19 point operator - (point a,point b)
    20 {
    21     return point(a.x-b.x,a.y-b.y);
    22 }
    23 point operator * (point a,double p)
    24 {
    25     return point(a.x*p,a.y*p);
    26 }
    27 point operator / (point b,double p)
    28 {
    29     return point(a.x/p,a.y/p);
    30 }
    31 double cross(point a,point b)
    32 {
    33     return a.x*b.y-b.x*a.y;
    34 }
    35 point getlineintersection(point p,point v,point q,point w)
    36 {
    37     point u=p-q;
    38     double t=cross(w,u)/cross(v,w);
    39     return p+v*t;
    40 }
    41 double area(point a,point b,point c)
    42 {
    43     return cross(b-a,c-a)/2.0;
    44 }
    45 double dis(point a,point b)
    46 {
    47     return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
    48 }
    49 double line(point a,point b,point c,point d)
    50 {
    51     return dis(a,b)+dis(b,c)+dis(c,d)+dis(d,a);
    52 }
    53 
    54 
    55 int main()
    56 {
    57     int t,ca;
    58     scanf("%d",&t);
    59     while(t--)
    60     {
    61         scanf("%d",&ca);
    62         printf("%d ",ca);
    63         a.x=0.0,a.y=0.0,b.y=0.0;
    64         scanf("%lf%lf%lf%lf%lf",&b.x,&c.x,&c.y,&d.x,&d.y);
    65         point dd=midd(a,b);
    66         point aa=midd(b,c);
    67         point cc=midd(a,d);
    68         point bb=midd(c,d);
    69         point aaa=getlineintersection(d,d-dd,a,a-aa);
    70         point bbb=getlineintersection(a,aa-a,b,bb-b);
    71         point ccc=getlineintersection(c,cc-c,b,bb-b);
    72         point ddd=getlineintersection(c,cc-c,d,dd-d);
    73         printf("%.3lf ",area(a,b,bbb)/160.0);
    74         printf("%.3lf ",area(b,c,ccc)/160.0);
    75         printf("%.3lf ",area(c,d,ddd)/160.0);
    76         printf("%.3lf ",area(d,a,aaa)/160.0);
    77         printf("%.3lf ",((area(ddd,aaa,bbb)+area(bbb,ccc,ddd))/160.0));
    78         printf("%.0lf
    ",ceil(line(aaa,bbb,ccc,ddd)*16.5));
    79     }
    80     return 0;
    81 }
    View Code
  • 相关阅读:
    Python基础—字符串
    Python基础—函数
    2019918练手爬虫日记
    python基础—列表
    Python urllib详解
    安装TesseractOCR显示无效的路径
    Sql server 关于ID突然自增问题解决方案
    Sql server 登陆后无法找不到数据库怎么解决
    Python常用语句及流程控制
    jquery cookie操作
  • 原文地址:https://www.cnblogs.com/yours1103/p/3348661.html
Copyright © 2011-2022 走看看