zoukankan      html  css  js  c++  java
  • 计算几何UVa10652

    This article is made by Jason-Cow.
    Welcome to reprint.
    But please post the article's address.

    题意见白书,P272~273

    把之前的板子拼起来就可以了

    ans=(S(木板)*100/S(凸包))%

    板子太长,先贴关键

    求面积

    db Area(D*R,int n){
        db S=0.0;
        for(int i=1;i<n;i++)S+=Cross(R[i]-R[1],R[i+1]-R[1]);
        return S/2;
    }
    int n,cnt=0;db S1=0.0;
    for(scanf("%d",&n);n--;){        
      db x,y,w,h,j,a;
      scanf("%lf%lf%lf%lf%lf",&x,&y,&w,&h,&j);
      D O(x,y);a=-Rad(j);
      R[++cnt]=O+Rotate(V(-w/2,-h/2),a);
      R[++cnt]=O+Rotate(V( w/2,-h/2),a);
      R[++cnt]=O+Rotate(V(-w/2, h/2),a);
      R[++cnt]=O+Rotate(V( w/2, h/2),a);
      S1+=w*h;
    }
    int m=Andrew(R,cnt,A); db S2=Area(A,m); printf("%.1lf %%\n",S1*100.0/S2);
      1 #include <algorithm>
      2 #include <iostream>
      3 #include <cstring>
      4 #include <cstdlib>
      5 #include <cstdio>
      6 #include <vector>
      7 #include <cmath>
      8 #include <queue>
      9 #include <map>
     10 #include <set>
     11 using namespace std;
     12 #define sqr(x) ((x)*(x))
     13 #define RG register
     14 #define op operator
     15 #define IL inline
     16 #define db double
     17 #define bl bool
     18 #define vo void
     19 IL vo read(int&x){
     20   x=0;char c=getchar(),f=0;
     21   while(c<'0'||c>'9'){if(c=='-')f=1;c=getchar();}
     22   while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();
     23   if(f)x=-x;
     24 }
     25 const db pi=acos(-1.0),eps=1e-10;
     26 struct D{
     27   db x,y;
     28   D(db x=0.0,db y=0.0):x(x),y(y){}
     29 };
     30 typedef D V;
     31 bl op<(D A,D B){return A.x<B.x||(A.x==B.x&&A.y<B.y);}
     32 V op+(V A,V B){return V(A.x+B.x,A.y+B.y);}
     33 V op-(V A,V B){return V(A.x-B.x,A.y-B.y);}
     34 V op*(V A,db N){return V(A.x*N,A.y*N);}
     35 V op/(V A,db N){return V(A.x/N,A.y/N);}
     36 
     37 
     38 db Ang(db x){return(x*180.0/pi);}
     39 db Rad(db x){return(x*pi/180.0);}
     40 V Rotate(V A,db a){return V(A.x*cos(a)-A.y*sin(a),A.x*sin(a)+A.y*cos(a));}
     41 db Dis(D A,D B){return sqrt(sqr(A.x-B.x)+sqr(A.y-B.y));}
     42 db Cross(V A,V B){return A.x*B.y-A.y*B.x;}
     43 
     44 db Area(D*R,int n){
     45     db S=0.0;
     46     for(int i=1;i<n;i++)S+=Cross(R[i]-R[1],R[i+1]-R[1]);
     47     return S/2;
     48 }
     49 db Leng(D*R,int n){
     50     db C=0.0;
     51     for(int i=2;i<=n;i++)C+=Dis(R[i],R[i-1]);
     52     return C+Dis(R[n],R[1]);
     53 }
     54 
     55 int Andrew(D*R,int n,D*A){
     56     int m=0;
     57     sort(R+1,R+n+1);
     58     for(int i=1;i<=n;i++){
     59         while(m>=2 && Cross(A[m]-A[m-1],R[i]-A[m-1])<=0)m--;
     60         A[++m]=R[i];
     61     }
     62     int k=m;
     63     for(int i=n-1;i>=1;i--){
     64         while(m>k  && Cross(A[m]-A[m-1],R[i]-A[m-1])<=0)m--;
     65         A[++m]=R[i];
     66     }
     67     return n>1?m-1:m;
     68 }
     69 
     70 D GO;
     71 bl acomp(D A,D B){
     72     db x=Cross(A-GO,B-GO);
     73     if(x>0)return 1;if(x<0)return 0;
     74     return Dis(GO,A)<Dis(GO,B);
     75 }
     76 
     77 int Graham(D*R,int n,D*A){
     78     for(int i=1;i<=n;i++){
     79         if(R[i].y<R[1].y)swap(R[i],R[1]);
     80         else if(R[i].y==R[1].y&&R[i].x<R[1].x)swap(R[i],R[1]);
     81     }
     82     GO=R[1],sort(R+2,R+n+1,acomp);
     83     int m=0;A[++m]=R[1],A[++m]=R[2];
     84     for(int i=3;i<=n;i++)
     85     {
     86         while(m>1 && Cross(A[m-1]-R[i],A[m]-R[i])<=0)m--;
     87         A[++m]=R[i];
     88     }
     89     return m;
     90 }
     91 const int maxn=(600<<2)+10;
     92 D R[maxn],A[maxn];
     93 int main(){
     94     int T;
     95     for(scanf("%d",&T);T--;){
     96         int n,cnt=0;db S1=0.0;
     97         for(scanf("%d",&n);n--;){        
     98             db x,y,w,h,j,a;
     99             scanf("%lf%lf%lf%lf%lf",&x,&y,&w,&h,&j);
    100             D O(x,y);a=-Rad(j);
    101             R[++cnt]=O+Rotate(V(-w/2,-h/2),a);
    102             R[++cnt]=O+Rotate(V( w/2,-h/2),a);
    103             R[++cnt]=O+Rotate(V(-w/2, h/2),a);
    104             R[++cnt]=O+Rotate(V( w/2, h/2),a);
    105             S1+=w*h;
    106         }
    107         int m=Andrew(R,cnt,A);
    108         db S2=Area(A,m);
    109         printf("%.1lf %%\n",S1*100.0/S2);
    110     }    
    111   return 0;
    112 }
    UVa10652
    ~~Jason_liu O(∩_∩)O
  • 相关阅读:
    流程控制之while循环
    流程控制之if...else
    基本运算符
    基本数据类型
    注释
    用户交互
    常量
    test
    查询方法
    删除代码
  • 原文地址:https://www.cnblogs.com/JasonCow/p/6592345.html
Copyright © 2011-2022 走看看