首页 > 其他 > 详细

atan2函数的使用

时间:2021-07-21 09:31:58      阅读:28      评论:0      收藏:0      [点我收藏+]

中石油大D:Go Fishing

求点(x, y)极坐标下的角度
double x = atan2(y, x);//此时的x是一个正切值   (atan2 返回以弧度表示的 y/x 的反正切)
x * 180 / 3.14;
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstdio>
typedef long long ll;
using namespace std;
double r;
int n;
double eps = 1e-6;
const int N = 1e2 + 10;
struct pts {
    double x, y;
}p[N];
double dis(pts a, pts b){
    return sqrt((a.x - b.x)*(a.x - b.x) + (a.y - b.y)*(a.y - b.y));
}
pts center(pts a, pts b)
{
    pts mid;
    mid.x = (a.x + b.x) / 2;
    mid.y = (a.y + b.y) / 2;
    double distance = dis(mid, a);
    double h = sqrt(r * r - distance * distance);
    double th = -1 * atan2(a.x - b.x, a.y - b.y);// 使用的是相反的角, 所以需要y和x倒置, 还需要乘以-1
    //  double th = atan2(a.y - b.y, a.x - b.x);
    pts p;
    p.x = mid.x + h * cos(th);
    p.y = mid.y + h * sin(th);
    return p;
}

int main(){
    scanf("%lf",&r);
    scanf("%d",&n);
    for(int i = 0; i < n; i++){
        scanf("%lf%lf",&p[i].x,&p[i].y);
    }
    ll ans = 1;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            if(i == j) continue;
           // if(dis(p[i],p[j]) > 2*r) continue;
            pts m = center(p[i],p[j]);
            ll cnt = 0;
            for(int k = 0; k < n; k++){
                if(dis(m,p[k]) < r + eps) cnt++;
            }
            ans = max(ans,cnt);
        }
    }
    printf("%lld",ans);
    return 0;
}

atan2函数的使用

原文:https://www.cnblogs.com/jw-zhao/p/15037393.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!