CodeForces 71C Round Table Knights(数学+枚举)
来源:互联网 发布:广西广电网络电视 编辑:程序博客网 时间:2024/06/07 10:03
题目戳这里
题意:圆上有n个点均匀分布,其中点的状态有0或1两种情况,现在告诉你所有点的状态,问:能否由状态为1的点组成正多边形。
思路:公式推理+枚举。
当n=3时,我们需要验证是否有正三边形(三角形);
当n=6时,我们需要验证是否有正六边形与正三角形;
当n=9时,我们需要验证是否有正九边形与正三角形;
……
可以发现只要检测n的大于3的因数作为边数是否合法即可;
并不是很难的一道题。(but当时没能做出来:P
此题也包含了dp的解法,官方题解是这么说的:
This solution uses following idea. If we have a good polygon withxy vertices, we also have a good polygon with x vertices. So we can check only prime divisors of n (except 2 - here we must check 4).
也就是直接判断n的素因数作为边数时是否合法,比之前单纯的因数判法要高效些,不过都没问题。
code:
/** @author Novicer* language : C++/C*/#include<iostream>#include<sstream>#include<fstream>#include<vector>#include<list>#include<deque>#include<queue>#include<stack>#include<map>#include<set>#include<bitset>#include<algorithm>#include<cstdio>#include<cstdlib>#include<cstring>#include<cctype>#include<cmath>#include<ctime>#include<iomanip>using namespace std;const double eps(1e-8);typedef long long lint;int m[200010];int main(){int n;while(cin >> n){memset(m,0,sizeof(m));for(int i = 1 ; i <= n ; i++){scanf("%d",&m[i]);}for(int i = 1 ; i <= n / 3 ; i++){if(n%i==0){int step = i;for(int j = 1 ; j <= step ; j++){int tmp = j;while(m[tmp] && n >= tmp) tmp += step;if(tmp > n){cout << tmp << endl;cout << "YES" << endl;return 0;}}}}cout << "NO" << endl;}return 0;}
0 0
- CodeForces 71C Round Table Knights(数学+枚举)
- codeforces 71C C. Round Table Knights(枚举)
- CodeForces 71 C.Round Table Knights(数论+dp)
- CF 71C Round Table Knights 暴力
- CodeForce Round Table Knights
- Knights of the Round Table
- Knights of the Round Table
- Knights of the Round Table
- (挑战编程_13_3)The Knights Of The Round Table
- UVAlive3523 Knights of the Round Table(bcc)
- poj2942:Knights of the Round Table(Tarjan)
- Codeforces Round #246 (Div. 2)(C)数学,思维
- Educational Codeforces Round 13 C Joty and Chocolate(数学)
- codeforces Round #377 div2 A B C(数学推导)
- Codeforces Round #439 C.The Intriguing Obsession(组合数学)
- POJ 2942 Knights of the Round Table
- The Knights of the Round Table
- poj 2942 Knights of the Round Table
- MySQL存储过程
- UIRefreshControl:点击按钮实现下拉刷新
- 相似图片搜索原理二(phash—c++实现)
- Android开发——自动连接指定SSID的wifi热点(不加密/加密)
- 【VB.NET机房重构】外键冲突
- CodeForces 71C Round Table Knights(数学+枚举)
- Android RxJava使用介绍(一) Hello World
- 变革时代 国内通讯云服务厂商对比介绍
- DSP编译器优化
- 第五章10
- 深入理解ThreadLocal
- myeclipse安装findbugs
- JVM指令字符集
- __func__标识符