• ural 1333 化平面为点计算覆盖率


    题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1333

    #include<cstdio>
    #include<cstring>
    #include<cmath>
    #include<iostream>
    #include<algorithm>
    #include<queue>
    using namespace std;
    
    const double eps = 1e-8;
    const double PI = acos(-1.0);
    const double INF = 1000000000000000.000;
    
    struct Point{
        double x,y;
        Point(double x=0, double y=0) : x(x),y(y){ }    //构造函数
    };
    typedef Point Vector;
    
    struct Circle{
         Point c;
         double r;
         Circle() {}
         Circle(Point c,double r): c(c),r(r) {}
    };
    Vector operator + (Vector A , Vector B){return Vector(A.x+B.x,A.y+B.y);}
    Vector operator - (Vector A , Vector B){return Vector(A.x-B.x,A.y-B.y);}
    Vector operator * (double p,Vector A){return Vector(A.x*p,A.y*p);}
    Vector operator / (Vector A , double p){return Vector(A.x/p,A.y/p);}
    
    bool operator < (const Point& a,const Point& b){
        return a.x < b.x ||( a.x == b.x && a.y < b.y);
    }
    
    int dcmp(double x){
        if(fabs(x) < eps) return 0;
        else              return x < 0 ? -1 : 1;
    }
    bool operator == (const Point& a, const Point& b){
        return dcmp(a.x - b.x) == 0 && dcmp(a.y - b.y) == 0;
    }
    
    ///向量(x,y)的极角用atan2(y,x);
    inline double Dot(Vector A, Vector B){ return A.x*B.x + A.y*B.y; }
    inline double Length(Vector A)    { return sqrt(Dot(A,A)); }
    inline double Angle(Vector A, Vector B)  { return acos(Dot(A,B) / Length(A) / Length(B)); }
    double Cross(Vector A, Vector B)  { return A.x*B.y - A.y * B.x; }
    
    Point read_point(){
        Point A;
        scanf("%lf %lf",&A.x,&A.y);
        return A;
    }
    
    /*************************************分 割 线*****************************************/
    const int maxn = 15;
    Circle C[maxn];
    
    int main()
    {
        //freopen("E:\acm\input.txt","r",stdin);
    
        int N;
        cin>>N;
        for(int i=1;i<=N;i++){
            scanf("%lf %lf %lf",&C[i].c.x,&C[i].c.y,&C[i].r);
        }
    
        double cnt = 0;
        for(double x = 0.000;x<=1.000;x+=0.001)
            for(double y = 0.000;y<=1.000;y+=0.001){
                Point A = Point(x,y);
                for(int i=1;i<=N;i++){
                    if(dcmp(Length(A-C[i].c)-C[i].r) < 0){
                        cnt ++;
                        break;
                    }
                }
        }
        double prec = cnt/1e6;
    
        cout<<prec*100<<endl;
    }
    View Code
  • 相关阅读:
    java mybatis
    java influx DB工具类
    java redisUtils工具类很全
    java 任务定时调度(定时器)
    java 线程并发(生产者、消费者模式)
    java 线程同步、死锁
    Redis 集群版
    Redis 单机版
    linux下配置zookeeper注册中心及运行dubbo服务
    vue搭建前端相关命令
  • 原文地址:https://www.cnblogs.com/acmdeweilai/p/3318550.html
Copyright © 2020-2023  润新知