惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Engineering at Meta
Engineering at Meta
G
Google Developers Blog
WordPress大学
WordPress大学
M
MIT News - Artificial intelligence
D
DataBreaches.Net
云风的 BLOG
云风的 BLOG
爱范儿
爱范儿
Microsoft Security Blog
Microsoft Security Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Blog — PlanetScale
Blog — PlanetScale
T
Tailwind CSS Blog
S
SegmentFault 最新的问题
阮一峰的网络日志
阮一峰的网络日志
博客园 - 三生石上(FineUI控件)
酷 壳 – CoolShell
酷 壳 – CoolShell
Recent Announcements
Recent Announcements
T
The Blog of Author Tim Ferriss
I
InfoQ
MyScale Blog
MyScale Blog
V
V2EX
B
Blog
罗磊的独立博客
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

OhYee 博客

小鹏辅助驾驶测评|OhYee 博客 小鹏非支持手机开启自动解锁|OhYee 博客 使用函数计算实现 301 重定向|OhYee 博客 针对 HTML 内容使用 Ant Design 图片弹框|OhYee 博客 博客进程泄露及僵尸进程解决|OhYee 博客 蓝易云服务器体验|OhYee 博客 SSH 调起本地 VSCode|OhYee 博客 【2022 秋招内推】阿里云后端研发工程师|OhYee 博客 使用函数计算获取 IP 地址信息|OhYee 博客 正确获取客户端 IP/HTTP Header 也可能重复|OhYee 博客 评测 Oculus Quest2 及 BigScreen|OhYee 博客 NextJS 热重载保留状态|OhYee 博客 如何优雅地贴 gist 代码|OhYee 博客 Linux 精细化文件权限|OhYee 博客 VSCode 容器开发环境|OhYee 博客 Clash 的不兼容更新排查|OhYee 博客 Zeek 导出 PCAP|OhYee 博客 记一次 ssh 配置问题|OhYee 博客 Git Commit 规范化工具|OhYee 博客 谈谈《星之卡比-探索发现》|OhYee 博客 VSCode 快捷键绑定 Shell 命令|OhYee 博客 ASN.1 语法及 X.509 证书格式解析解析|OhYee 博客 腾讯企业邮箱忽略 MX 记录发信|OhYee 博客 Chrome/Edge 标签组插件|OhYee 博客 【应届内推】阿里云后端研发工程师|OhYee 博客 损坏的 Typecho 备份处理为 JSON|OhYee 博客 VS Code VIM 插件高效使用|OhYee 博客 SSH 正反向代理|OhYee 博客 Let's Encrypt 根证书过期引发的问题|OhYee 博客 OpenWRT 忽略内核依赖|OhYee 博客
Codeforces 820B.Mister B and Angle in Polygon|OhYee 博客
2017-06-28 · via OhYee 博客

这是一篇最后编辑于 8 年前 的文章,其内容可能与目前实际情况差异较大,请注意甄别

题目

{% fold 点击显/隐题目 %}

On one quiet day all of sudden Mister B decided to draw angle a on his field. Aliens have already visited his field and left many different geometric figures on it. One of the figures is **regular convex n-gon** (regular convex polygon with $n$ sides).

That's why Mister B decided to use this polygon. Now Mister B must find three distinct vertices v1, v2, v3 such that the angle ∠v1v2v3\angle v_1 v_2 v_3(where v2v_2 is the vertex of the angle, and v1v_1 and v3v_3 lie on its sides) is as close as possible to aa. In other words, the value $\left| \angle v_1 v_2 v_3 - a \right| $ should be minimum possible.

If there are many optimal solutions, Mister B should be satisfied with any of them.

First and only line contains two space-separated integers $n$ and $a$ ($3 \leq n \leq 10^5$, $1 \leq a \leq 180$) — the number of vertices in the polygon and the needed angle, in degrees.

Print three space-separated integers: the vertices v1, v2, v3, which form . If there are multiple optimal solutions, print any of them. The vertices are numbered from 1 to n in clockwise order.

3 15 4 67 4 68

1 2 3 2 1 3 4 1 2

{% endfold %}

题解

题意
n 边形选3个顶点,使拼合成的角使所有角中最接近 a

需要的数学知识:
正n边形内角和: (n−2)×180∘(n-2) \times 180^{\circ}

对于如图所示的角,其角度为 ((4−2)×180−2×(6−2)∗180÷6)÷2=60((4-2) \times 180 - 2 \times (6-2)*180 \div 6) \div 2 = 60

同样,可以证明(数学归纳法)得到 ∠v2v1vk(3≤k≤n)\angle v_2 v_1 v_k ( 3 \leq k \leq n ) 正好可以覆盖所有的可以取到的角度

所以,只要枚举 (i×180−i×(n−2)∗180÷n)÷2   (1≤i≤n−2)(i \times 180 - i \times (n-2)*180 \div n) \div 2 \:\:\: ( 1 \leq i \leq n-2 ) 即可

代码

{% fold 点击显/隐代码 %}```cpp Mister B and Angle in Polygon https://github.com/OhYee/sourcecode/tree/master/ACM 代码备份
//
#define debug
#include
//
/
#include
#include
#include
#include
using namespace std;

const double eps = 1e-5;

int main() {
#ifdef debug
freopen("in.txt", "r", stdin);
int START = clock();
#endif
cin.tie(0);
cin.sync_with_stdio(false);

double n, a;
while (cin >> n >> a) {
    double tot = 180 * (n - 2);
    double t = tot / n;
    double Min = 9e9;
    double pos = 0;
    for (int i = 1; i <= n - 2; i++) {
        double temp = (180 * i - t * i) / 2;
        //cout << "2 1 " << i + 2 << " " << temp << " " << fabs(temp - a)
             //<< " "<<Min<<endl;
        if (fabs(temp - a) < Min) {
            Min = fabs(temp - a);
            pos = i;
        }
    }
    cout << "2 1 " << pos + 2 << endl;
}

#ifdef debug
printf("Time:%.3fs.\n", double(clock() - START) / CLOCKS_PER_SEC);
#endif
return 0;
}

{% endfold %}