chladni图形matlab模拟,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 (1≤i

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 (1≤k

Input

The first line contains two space-separated integers nn and mm (2≤n≤1000002≤n≤100000, 1≤m≤2000001≤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 (1≤ai,bi≤n1≤ai,bi≤n, ai≠biai≠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.

a2e4ff159abc11512ac8e788a1ad9cf3?v=1557038296

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

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

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

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

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

c92f882e0561455b5f1e17efe0232a25a18.jpg

efe1310ee9ddb9b706b445ce790d0ee5ef3.jpg

1 #include

2 #include

3 #include

4 #include

5 #include

6 #include

7 #include

8 #include

9 #include

10 using namespacestd;11 const int maxn = 201010;12 vectorv[201010];13 inta[maxn],b[maxn];14 intx,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 intmain(){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代码

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

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值