【Codeforces Round #421 (Div. 2) B】Mister B and Angle in Polygon

本文解析了CodeForces竞赛中一道关于几何问题的B级题目。通过利用正多边形的特性,寻找与给定角度最接近的角度值。文章提供了完整的C++代码实现。

【题目链接】:http://codeforces.com/contest/820/problem/B

【题意】

给你一个正n边形;
然后让你在这正n边行中选3个点,组成一个角;
找出角的大小和所给的角最接近的角;

【题解】

同弧所对应的圆周角都是相同的;
而且每个正多边行都能作出一个外接圆;
所以随便选两个相邻的点;然后再选其他
n-2个点中的一个点组成角;
就能覆盖到所有的情况了;
顺序增加角的大小就好(一份一份地加);

【Number Of WA

0

【反思】

想说是B题;
就没往复杂的地方想了.

【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x)
#define Open() freopen("F:\\rush.txt","r",stdin)
#define Close() ios::sync_with_stdio(0)

typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 110;

int n,c;
double a,d;

int main(){
    //Open();
    Close();
    cin >> n >> a;
    double t = (n-2)*180/(1.0*n);
    t=t/(1.0*(n-2));
    double now = t;
    int temp = n;
    rep1(i,1,n-2){
        if (i==1){
            c = temp;
            d = fabs(now-a);
        }else{
            double temp1 = fabs(now-a);
            if (temp1 < d){
                d = temp1;
                c = temp;
            }
        }
        temp--;
        now+=t;
    }
    cout << 1 <<' '<<2<<' '<<c<<endl;
    return 0;
}

转载于:https://www.cnblogs.com/AWCXV/p/7626231.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值