zoukankan      html  css  js  c++  java
  • Codeforces Round #421 (Div. 2)

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

    题意:给定一个正n边形,然后让你选择3个不同的顶点,使得这3个顶点形成的角度尽可能的接近a。

    思路:首先模拟一下画个图发现因为是正n边形所以可以固定2个相邻的顶点然后找第3个顶点既可,这里先固定顶点1和2并且以顶点2为中点,然后枚举其他n-2个顶点计算夹角度数取最优即可。  我们知道正n边形的内角为(n-2)/n*180°,由于固定了2个相邻的顶点所以一个内角可以被划分成(n-2)份,所以每份的度数det为((n-2)/n*180)/(n-2)°。

    #define _CRT_SECURE_NO_DEPRECATE
    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<string>
    #include<map>
    #include<vector>
    #include<time.h>
    #include<stack>
    #include<cmath>
    using namespace std;
    typedef long long int LL;
    typedef unsigned long long int ULL;
    const int MAXN = 500 + 24;
    int main(){
    //#ifdef kirito
    //    freopen("in.txt", "r", stdin);
    //    freopen("out.txt", "w", stdout);
    //#endif
    //    int start = clock();
        int n, a;
        while (~scanf("%d%d", &n,&a)){
            int v3=n;
            double cur = 1000,det=(1.0*(n-2)/n*180.0)/(1.0*n-2);
            for (int i = n; i >= 3; i--){
                if (fabs(cur - a) > fabs(det*(n - i + 1) - a)){
                    cur = det*(n - i + 1);
                    v3 = i;
                }
            }
            printf("%d %d %d
    ",1, 2, v3);
        }
    //#ifdef LOCAL_TIME
    //    cout << "[Finished in " << clock() - start << " ms]" << endl;
    //#endif
        return 0;
    }
  • 相关阅读:
    ovs tag
    从数据库分析OpenStack创建虚机流程
    Neutron中的二层网络服务架构
    Failed to bind port
    OpenStack网络参数segment
    OpenStack与SDN控制器的集成
    HDU 3709 Balanced Number
    HDU 5787 K-wolf Number
    HDU 5803 Zhu’s Math Problem
    CodeForces 258B Little Elephant and Elections
  • 原文地址:https://www.cnblogs.com/kirito520/p/7100099.html
Copyright © 2011-2022 走看看