Codeforces 71C Round Table Knights

题意:有n个点均匀的分布在圆周上,每个点有0,1两种状态,问你所有 1的点能否主城正多边形。

解题思路:数论 + dp  ,假设可以组成正 t 边形 ,那么 t 一定要是 n的因子 ,又因为如果能组成 正t边形 ,一定能组成 正 2*t 边形,3*t边行等等,所以只需要质因子。

然后用 0 去排除这些质因子是否可行就行了。

解题代码:

 1 // File Name: 71c.cpp
 2 // Author: darkdream
 3 // Created Time: 2015年03月20日 星期五 21时45分50秒
 4
 5 #include<vector>
 6 #include<list>
 7 #include<map>
 8 #include<set>
 9 #include<deque>
10 #include<stack>
11 #include<bitset>
12 #include<algorithm>
13 #include<functional>
14 #include<numeric>
15 #include<utility>
16 #include<sstream>
17 #include<iostream>
18 #include<iomanip>
19 #include<cstdio>
20 #include<cmath>
21 #include<cstdlib>
22 #include<cstring>
23 #include<ctime>
24 #define LL long long
25 #define maxn 100001
26 using namespace std;
27 int a[100005];
28 int hs[100005];
29 int n;
30 int tt;
31 int zyz[10];
32 int dp[10][100050];
33 void sai()
34 {
35    int li = sqrt(n)+1;
36    for(int i = 2;i <= li ;i ++)
37    {
38       if(hs[i] == 0)
39       {
40         int k = i*i ;
41         while(k <= n)
42         {
43            hs[k] = 1;
44            k += i ;
45         }
46       }
47    }
48    hs[4] = 0 ;
49    hs[2] = 1;
50    tt = 0 ;
51    for(int  i = 2;i <= n ;i ++)
52    {
53      if(hs[i] == 0 && n % i == 0 )
54      {
55        tt ++ ;
56        zyz[tt] = n/i ;
57      }
58    }
59 }
60 int main(){
61     scanf("%d",&n);
62     sai();
63     /*for(int i = 1;i <= tt; i ++)
64         printf("%d ",zyz[i]);
65     printf("\n");*/
66     int tmp ;
67     for(int i = 1;i <= n;i ++)
68     {
69        scanf("%d",&tmp);
70        if(tmp == 0 )
71        {
72        for(int j = 1; j <= tt; j++)
73        {
74            dp[j][i%zyz[j]] = 1;
75        }
76        }
77     }
78     for(int i = 1;i <= tt;i ++)
79     {
80       for(int j =0 ;j < zyz[i];j ++)
81           if(dp[i][j] == 0)
82           {
83             printf("YES\n");
84             return 0 ;
85           }
86     }
87     printf("NO\n");
88 return 0;
89 }

时间: 2024-10-20 05:35:17

Codeforces 71C Round Table Knights的相关文章

poj2924--F - Knights of the Round Table(圆桌骑士,经典连通分量)

F - Knights of the Round Table Time Limit:7000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Description Being a knight is a very attractive career: searching for the Holy Grail, saving damsels in distress, and drinking w

POJ 2942 Knights of the Round Table 黑白着色+点双连通分量

题目来源:POJ 2942 Knights of the Round Table 题意:统计多个个骑士不能參加随意一场会议 每场会议必须至少三个人 排成一个圈 而且相邻的人不能有矛盾 题目给出若干个条件表示2个人直接有矛盾 思路:求补图  能够坐在一起 就是能够相邻的人建一条边 然后假设在一个奇圈上的都是满足的 那些不再不论什么一个奇圈的就是不满足 求出全部奇圈上的点 总数减去它就是答案 首先有2个定理 1.一个点双连通分量是二分图 你就没有奇圈 假设有奇圈  那就不是二分图  充分必要条件 所

暴力/DP Codeforces Beta Round #22 (Div. 2 Only) B. Bargaining Table

题目传送门 1 /* 2 题意:求最大矩形(全0)的面积 3 暴力/dp:每对一个0查看它左下的最大矩形面积,更新ans 4 注意:是字符串,没用空格,好事多磨,WA了多少次才发现:( 5 详细解释:http://www.cnblogs.com/cszlg/p/3217478.html 6 */ 7 #include <cstdio> 8 #include <algorithm> 9 #include <cstring> 10 #include <cmath>

poj 2942 Knights of the Round Table - Tarjan

Being a knight is a very attractive career: searching for the Holy Grail, saving damsels in distress, and drinking with the other knights are fun things to do. Therefore, it is not very surprising that in recent years the kingdom of King Arthur has e

【POJ】2942 Knights of the Round Table(双连通分量)

http://poj.org/problem?id=2942 各种逗.... 翻译白书上有:看了白书和网上的标程,学习了..orz. 强连通分量就是先找出割点,然后用个栈在找出割点前维护子树,最后如果这个是割点那么子树就都是强连通分量,然后本题求的是奇圈,那么就进行黑白染色,判断是否为奇圈即可.将不是奇圈的所有强连通分量的点累计起来即可. #include <cstdio> #include <cstring> #include <cmath> #include <

【POJ 2942】Knights of the Round Table(双联通分量+染色判奇环)

[POJ 2942]Knights of the Round Table(双联通分量+染色判奇环) Time Limit: 7000MS   Memory Limit: 65536K Total Submissions: 11661   Accepted: 3824 Description Being a knight is a very attractive career: searching for the Holy Grail, saving damsels in distress, an

POJ2942 Knights of the Round Table[点双连通分量|二分图染色|补图]

Knights of the Round Table Time Limit: 7000MS   Memory Limit: 65536K Total Submissions: 12439   Accepted: 4126 Description Being a knight is a very attractive career: searching for the Holy Grail, saving damsels in distress, and drinking with the oth

UvaLive3523 Knights of the Round Table(点双联通分量+二分图染色)

UvaLive3523 Knights of the Round Table 参考了Kuangbin巨的题解. /* POJ 2942 Knights of the Round Table 亚瑟王要在圆桌上召开骑士会议,为了不引发骑士之间的冲突, 并且能够让会议的议题有令人满意的结果,每次开会前都必须对出席会议的骑士有如下要求: 1. 相互憎恨的两个骑士不能坐在直接相邻的2个位置: 2. 出席会议的骑士数必须是奇数,这是为了让投票表决议题时都能有结果. 注意:1.所给出的憎恨关系一定是双向的,不

UVALive 3523 Knights of the Round Table(二分图+双连通分量)

Description Being a knight is a very attractive career: searching for the Holy Grail, saving damsels in distress, and drinking with the other knights are fun things to do. Therefore, it is not very surprising that in recent years the kingdom of King