【数学】【CF1096C】 Polygon for the Angle
Description
给定一个角度 \(\theta\),请你寻找一个正 \(n\) 边型,满足在这个正 \(n\) 边型上找三个顶点 \(A,B,C\) (可以不相邻),使得 \(\angle ABC~=~\theta\) 。请输出最小的 \(n\)。保证 \(n\) 不超过 \(998244353\)。多组数据。
注意给出的 \(\theta\) 是使用角度制表示的。
Input
第一行是数据组数 \(T\)
下面 \(T\) 行,每行一个整数 \(\theta\),代表给出的角度
Output
对于每组数据输出一行代表答案
Hint
\(1~\leq~T~\leq~180~,~1~\leq~\theta~<~180\)。
Solution
多边形内角和定理:
对于一个有 \(n\) 个顶点的凸多边形 \(n~\geq~3\),其内角和为 \((n~-~2)~\times~180^\circ\)。
证明略。这大概是初中定理吧……大概方法是显然一个 \(n\) 边型可以分成 \((n~-~2)\) 个三角形,每个三角形的内角和是 \(180^\circ\)。至于证明可以分成 \((n~-~2)\) 个三角形,对 \(n\) 做数学归纳即可。
由于这是一个正 \(n\) 边型,所以一个角的度数为 \(\frac{n-2}{n}~\times~180^\circ\)
同时它连向其他每个顶点的线段平分这个角,所以它连向相邻两个顶点的线段组成的角的度数为 \(\frac{n-2}{(n-2)n}~\times~180^\circ~=~\frac{1}{n}~\times~180^\circ\)
我们设选择的点 \(A\) 和点 \(C\) 中间相隔了 \((k-1)\) 个顶点 \((k~\leq~n~-~2)\),于是这些一共组成了 \(k\) 个角度如上的角。列得方程如下(角度略去):
\]
移项得
\]
我们设 \(s~=~\gcd(\theta~,~180)\),然后等式两侧同除 \(s\),得
\(\frac{180}{s}~\times~k~=~\frac{\theta}{s}~\times~n\)
由于\(\frac{180}{s}~\perp~\frac{\theta}{s}\),所以 \(k~=~\frac{\theta}{s}~,~n~=~\frac{180}{s}\)
考虑这种情况下我们要求 \(k~\leq~n~-~2\),但是如果算出来不是这样怎么办:如果答案为 \(n\) 时满足上式,则答案为 \(xn(x~\in~Z^+)\) 时一定也满足上式。于是我们不断加 \(n\) 直到合法即可。
Code
#include <cstdio>
#ifdef ONLINE_JUDGE
#define freopen(a, b, c)
#endif
#define rg register
#define ci const int
#define cl const long long
typedef long long int ll;
namespace IPT {
const int L = 1000000;
char buf[L], *front=buf, *end=buf;
char GetChar() {
if (front == end) {
end = buf + fread(front = buf, 1, L, stdin);
if (front == end) return -1;
}
return *(front++);
}
}
template <typename T>
inline void qr(T &x) {
rg char ch = IPT::GetChar(), lst = ' ';
while ((ch > '9') || (ch < '0')) lst = ch, ch=IPT::GetChar();
while ((ch >= '0') && (ch <= '9')) x = (x << 1) + (x << 3) + (ch ^ 48), ch = IPT::GetChar();
if (lst == '-') x = -x;
}
template <typename T>
inline void ReadDb(T &x) {
rg char ch = IPT::GetChar(), lst = ' ';
while ((ch > '9') || (ch < '0')) lst = ch, ch = IPT::GetChar();
while ((ch >= '0') && (ch <= '9')) x = x * 10 + (ch ^ 48), ch = IPT::GetChar();
if (ch == '.') {
ch = IPT::GetChar();
double base = 1;
while ((ch >= '0') && (ch <= '9')) x += (ch ^ 48) * ((base *= 0.1)), ch = IPT::GetChar();
}
if (lst == '-') x = -x;
}
namespace OPT {
char buf[120];
}
template <typename T>
inline void qw(T x, const char aft, const bool pt) {
if (x < 0) {x = -x, putchar('-');}
rg int top=0;
do {OPT::buf[++top] = x % 10 + '0';} while (x /= 10);
while (top) putchar(OPT::buf[top--]);
if (pt) putchar(aft);
}
const int maxn = 200010;
const int MOD = 998244353;
int n;
ll ans;
char MU[maxn];
int main() {
freopen("1.in", "r", stdin);
qr(n);
for (rg int i = 1; i <= n; ++i) do {MU[i] = IPT::GetChar();} while ((MU[i] > 'z') || (MU[i] < 'a'));
MU[0] = MU[1]; MU[n + 1] = MU[n];;
int pos = n; while (MU[pos] == MU[0]) --pos;
int k = n - pos;
for (rg int i = 1; i <= n; ++i) if (MU[i] == MU[i - 1]) {
++ans;
} else break;
ans = (ans * k) % MOD;
++ans;
for (rg int i = 1; i <= n; ++i) if (MU[i] == MU[i - 1]) ++ans; else break;
for (rg int i = n; i; --i) if (MU[i] == MU[i + 1]) ++ans; else break;
qw(ans % MOD, '\n', true);
return 0;
}
【数学】【CF1096C】 Polygon for the Angle的更多相关文章
- CF-1096C Polygon for the Angle
CF-1096C Polygon for the Angle https://codeforces.com/contest/1096/problem/C 题意:给一个角度ang(1<=ang&l ...
- CF1096C Polygon for the Angle
思路: 要想到正n边形中所有可能的ang为180 * k / n (1 <= k <= n - 2). 根据n = 180 * k / ang, n是大于等于3的整数,并且n >= ...
- C. Polygon for the Angle 几何数学
C. Polygon for the Angle 几何数学 题意 给出一个度数 ,问可以实现的最小的n的n边形是多少 思路 由n边形的外角和是180度直接就可以算出最小的角是多少 如果给出的度数是其最 ...
- C. Polygon for the Angle(几何)
题目链接:http://codeforces.com/contest/1096/problem/C 题目大意:T是测试样例,然后每一次输入一个角度,然后问你在一个n边形里面,能不能构成这个角度,如果能 ...
- Educational Codeforces Round 57 (Rated for Div. 2) 前三个题补题
感慨 最终就做出来一个题,第二题差一点公式想错了,又是一波掉分,不过我相信我一定能爬上去的 A Find Divisible(思维) 上来就T了,后来直接想到了题解的O(1)解法,直接输出左边界和左边 ...
- WPF学习05:2D绘图 使用Transform进行控件变形
在WPF学习04:2D绘图 使用Shape绘基本图形中,我们了解了如何绘制基本的图形. 这一次,我们进一步,研究如何将图形变形. 例子 一个三角形,经Transform形成组合图形: XAML代码: ...
- SVG的Transform使用
SVG的Transform使用: <%@ page language="java" contentType="text/html; charset=UTF-8&qu ...
- Educational Codeforces Round 57 (Rated for Div. 2)
我好菜啊. A - Find Divisible 好像没什么可说的. #include<cstdio> #include<cstring> #include<algori ...
- Educational Codeforces Round 57题解
A.Find Divisible 沙比题 显然l和2*l可以直接满足条件. 代码 #include<iostream> #include<cctype> #include< ...
随机推荐
- 【视频编解码·学习笔记】12. 图像参数集(PPS)介绍
一.PPS相关概念: 除了序列参数集SPS之外,H.264中另一重要的参数集合为图像参数集Picture Paramater Set(PPS). 通常情况下,PPS类似于SPS,在H.264的裸码流中 ...
- [Github] Github使用教程
前言 Github是一个面向开源及私有软件项目的托管平台.它可以免费使用,并且速度快速,拥有超多的用户.是目前管理软件开发和发现已有代码的首选平台.下面将向Github新手介绍相关操作. 正文 注册 ...
- 第十四次ScrumMeeting博客
第十四次ScrumMeeting博客 本次会议于12月3日(日)22时整在3公寓725房间召开,持续30分钟. 与会人员:刘畅.辛德泰.张安澜.方科栋. 1. 每个人的工作(有Issue的内容和链接) ...
- Django_事务
介绍 函数说明 from django.db import transaction transaction.atomic # 原子性操作,把一系列操作当做一个整体,错了则集体回退 transactio ...
- 配置树莓派/Linux默认声卡设备
1.设置默认声卡为USB声卡 在$HOME下新建.asoundrc $cd $HOME $nano .asoundrc 输入以下内容 defaults.ctl.card 1 defaults.pcm. ...
- 凡事预则立|项目Beta冲刺准备
1.讨论组长是否重选的议题和结论. 组员一致认为组长不需要重选,我们都很认可组长的表现,组长的付出我们都看在眼里,我们找不出更适合担任组长的人选. 2.下一阶段需要改进完善的功能. 财富值的布局优化以 ...
- 浏览器播放rtmp流
我是利用flash插件实现的,需要以下几个文件: flowplayer-3.2.8.min.js flowplayer-3.2.18.swf flowplayer.rtmp-3.2.8.swf flo ...
- Robot Framework 教程 (4) - 自定义Library
RobotFrame Work为我们提供了包括OS.Android.XML.FTP.HTTP.DataBase.Appium.AutoIt.Selenium.Watir等大量的库.在使用过程中,除这些 ...
- CentOS7 修改 启动级别
1. centos7 之前应该使用init 的启动脚本 不支持并行 速度比较慢, centos7 开始使用systemd 的模式 提高了开机的性能 所以之前的init 脚本修改 启动级别应该就无效了 ...
- Android UI测量、布局、绘制过程探究
在上一篇博客<Android中Activity启动过程探究>中,已经从ActivityThread.main()开始,一路摸索到ViewRootImpl.performTraversals ...