Chladni Figure CodeForces - 1162D (暴力,真香啊~)

Chladni Figure CodeForces - 1162D 

Inaka has a disc, the circumference of which is nn units. The circumference is equally divided by nn points numbered clockwise from 11 to nn, such that points ii and i+1i+1 (1i<n1≤i<n) are adjacent, and so are points nn and 11.

There are mm straight segments on the disc, the endpoints of which are all among the aforementioned nn points.

Inaka wants to know if her image is rotationally symmetrical, i.e. if there is an integer kk (1k<n1≤k<n), such that if all segments are rotated clockwise around the center of the circle by kk units, the new image will be the same as the original one.

Input

The first line contains two space-separated integers nn and mm (2n1000002≤n≤100000, 1m2000001≤m≤200000) — the number of points and the number of segments, respectively.

The ii-th of the following mm lines contains two space-separated integers aiai and bibi (1ai,bin1≤ai,bi≤n, aibiai≠bi) that describe a segment connecting points aiai and bibi.

It is guaranteed that no segments coincide.

Output

Output one line — "Yes" if the image is rotationally symmetrical, and "No" otherwise (both excluding quotation marks).

You can output each letter in any case (upper or lower).

Examples

Input
12 6
1 3
3 7
5 7
7 11
9 11
11 3
Output
Yes
Input
9 6
4 5
5 6
7 8
8 9
1 2
2 3
Output
Yes
Input
10 3
1 2
3 2
7 2
Output
No
Input
10 2
1 6
2 7
Output
Yes

Note

The first two examples are illustrated below. Both images become the same as their respective original ones after a clockwise rotation of 120120 degrees around the center.

题意:在圆上有n个点和m条线段,问圆上这个图形在通过旋转是否能找到一个位置与之前的图形完全重合。

解法:暴力就完事了,开vector数组来存储两个点之间是否相连

   如果要重合的话,那么旋转的长度必定要被N整除。//剪枝情况

   先比较对应位置的点具有关系的线段数量是否相等,然后将对应点所存储的线段长度转移到int类型的数组冲进行排序比较。在比较过程中如果出现不相等的情况即跳出当前循环。

在此说一句:金大佬太强了! 暴力真香~

 1 #include<stdio.h>
 2 #include<string.h>
 3 #include<iostream>
 4 #include<algorithm>
 5 #include<map>
 6 #include<string>
 7 #include<set>
 8 #include<stack>
 9 #include<queue>
10 using namespace std;
11 const int maxn  = 201010;
12 vector<int>v[201010];
13 int a[maxn],b[maxn];
14 int x,y,n,m;
15 
16 
17 int sum(int x ,int y){//保证相关线段是最短的并且不是负数
18     if( x > y){
19         return min(x - y,y - x + n);
20     }else{
21         return min(y - x, x - y + n);
22     }
23 }
24 int main(){
25     scanf("%d %d",&n,&m);
26     for(int i = 1; i <= m ; i++){
27         scanf("%d %d",&x,&y);
28         v[x].push_back(y);//v[x]存储以v[x]为起点的线段
29         v[y].push_back(x);
30     }
31     int ret = 1;
32     for(int i = 1 ; i < n ; i++){
33         if(n % i == 0){
34             int flag = 1;
35             for(int j = 1 ; j <= n ; j++){
36                 if(v[j].size() != v[(j + i - 1)%n + 1].size()){//如果对应点所具有的线段的数量不相等,则图形不可能重合
37                     flag = 0;
38                     break;
39                 }
40                 int l = v[j].size();//对应点线段数量相等之后,将对应点所存的线段提取到a[],b[]数组中,排序后进行比较
41                 for(int k = 0 ; k < l ; k++ ){
42                     a[k] = sum(v[j][k],j);
43                     b[k] = sum(v[(j + i - 1)%n + 1][k],(j + i - 1)%n+1);
44                 }
45                 sort(a,a+v[j].size());//将对应点中所有的线段进行排序
46                 sort(b,b+v[j].size());
47                 for(int k = 0 ; k < l; k++){
48                     if(a[k] != b[k]){
49                         flag = 0;
50                         break;
51                     }
52                 }
53             }
54             if(flag){
55                 printf("Yes\n");
56                 ret = 0;
57                 break;
58             }
59         }
60     }
61     if(ret) printf("No\n");
62     return 0;
63 }
AC代码

一个从很久以前就开始做的梦。

猜你喜欢

转载自www.cnblogs.com/DreamACMer/p/10840590.html