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<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 (1≤k<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 (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
12 6
1 3
3 7
5 7
7 11
9 11
11 3
Yes
9 6
4 5
5 6
7 8
8 9
1 2
2 3
Yes
10 3
1 2
3 2
7 2
No
10 2
1 6
2 7
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类型的数组冲进行排序比较。在比较过程中如果出现不相等的情况即跳出当前循环。
在此说一句:金大佬太强了! 暴力真香~
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<map>
#include<string>
#include<set>
#include<stack>
#include<queue>
using namespace std;
const int maxn = ;
vector<int>v[];
int a[maxn],b[maxn];
int x,y,n,m; int sum(int x ,int y){//保证相关线段是最短的并且不是负数
if( x > y){
return min(x - y,y - x + n);
}else{
return min(y - x, x - y + n);
}
}
int main(){
scanf("%d %d",&n,&m);
for(int i = ; i <= m ; i++){
scanf("%d %d",&x,&y);
v[x].push_back(y);//v[x]存储以v[x]为起点的线段
v[y].push_back(x);
}
int ret = ;
for(int i = ; i < n ; i++){
if(n % i == ){
int flag = ;
for(int j = ; j <= n ; j++){
if(v[j].size() != v[(j + i - )%n + ].size()){//如果对应点所具有的线段的数量不相等,则图形不可能重合
flag = ;
break;
}
int l = v[j].size();//对应点线段数量相等之后,将对应点所存的线段提取到a[],b[]数组中,排序后进行比较
for(int k = ; k < l ; k++ ){
a[k] = sum(v[j][k],j);
b[k] = sum(v[(j + i - )%n + ][k],(j + i - )%n+);
}
sort(a,a+v[j].size());//将对应点中所有的线段进行排序
sort(b,b+v[j].size());
for(int k = ; k < l; k++){
if(a[k] != b[k]){
flag = ;
break;
}
}
}
if(flag){
printf("Yes\n");
ret = ;
break;
}
}
}
if(ret) printf("No\n");
return ;
}
AC代码
一个从很久以前就开始做的梦。
Chladni Figure CodeForces - 1162D (暴力,真香啊~)的更多相关文章
- 从Eclipse切换到IDEA工具,哎~真香!
从Eclipse切换到IDEA工具,哎~真香!(图) 个人观点:IDEA工具用了就回不去了!!!对比很多人写,我就不赘述了.我在这里主要介绍一下IDEA工具的一些使用上的技巧,毕竟我开始学习java的 ...
- git 日常使用从入门到真香
目录 git 日常使用从入门到真香 一.Git简介 二.Git常用命令 三.git操作流程 四.报错处理 git 日常使用从入门到真香 一.Git简介 Git是一个开源的分布式版本控制系统,可以有效. ...
- 真香系列之 Golang 升级
Golang 以前的依赖管理一直饱受诟病,社区的方案也层出不穷,比如 vendor, glide, godep 等.之前的依赖管理一直是依靠 GOPATH 或者将依赖代码下载到本地,这种方式都有劣势. ...
- 真香的flex弹性布局
如何实现一个左中右的布局 在flex出现之前 #box{ color: white; } #left{ float: left; width: 30%; background-color: red; ...
- VSCode六大通用插件真香合集
目录 一.background:设置心水背景图 安利理由: 安装及设置步骤: 设置过程中使用的代码: 成果展示: 注意: 二.Material Theme(VSCode主题)+Material Ico ...
- 曾经你说chrome浏览器天下第一,现在你却说Microsoft edge真香!呸,渣男!!
曾经你说chrome浏览器天下第一,现在你却说Microsoft edge真香!呸,渣男!! 一个月前我每天打卡搜索的时候,老是有微软新版浏览器的广告.我刚才是内心其实是抵触的,直到我发现了它的奇妙之 ...
- JavaFX桌面应用-MVC模式开发,“真香”
使用mvc模块开发JavaFX桌面应用在JavaFX系列文章第一篇 JavaFX桌面应用开发-HelloWorld 已经提到过,这里单独整理使用mvc模式开发开发的流程. ~ JavaFX桌面应用开发 ...
- 国人开源了一款超好用的 Redis 客户端,真香!!
大家都知道,Redis Desktop Manager 是一款非常好用的 Redis 可视化客户端工具,但可惜的是 v0.9.4 版本之后需要收费了: 这个工具不再免费提供安装包了,要对所有安装包收费 ...
- 我把公司 10 年老系统改造 Maven,真香!!
公司有几个老古董项目,应该是 10 年前开发的了,有一个是 JSP + Servlet,有一个还用的 SSH 框架,打包用的 Ant,是有多老啊,我想在座的各位很多都没听过吧. 为了持续集成.持续部署 ...
随机推荐
- Docker部署Python应用程序
Docker部署Python应用程序 1. 单个py文件部署 生成Dockerfile 文件 插件用的豆瓣的镜像,,重置时间(容器的默认时间是UTC时间与宿主机的相差8小时). 文中需要三个插件(pe ...
- 如何在Ubuntu 18.04上安装和卸载TeamViewer
卸载命令:sudo apt --purge remove teamviewer 安装:https://www.linuxidc.com/Linux/2018-05/152282.htm 如何在Ubun ...
- Day3-T2
原题目 奶牛Bessie的电脑总是无缘无故地被 FJ 关掉,奶牛 Bessie 非常苦恼,也非常生气.FJ 却发现了 一个很神奇的规律(别问是怎么知道的),发现 Bessie 每吃一次草,她的生气值会 ...
- bzoj 4236JOIOJI
一开始忘掉特殊情况也是蛋疼2333(有一直到头的.mp[0][0]是要特判的) 做法也就是找mp[i][j]相同的东西.(貌似可以写成线性方程组(z=x+A,z=y+B)过这个的就是相等(可以先从2维 ...
- BZOJ 2749 [HAOI2012]外星人
题解:对每一个>2的质数分解,最后统计2的个数 注意:如果一开始没有2则ans需+1,因为第一次求phi的时候并没有消耗2 WA了好几遍 #include<iostream> #in ...
- 十、CI框架之通过参数的办法输出URI路径
一.代码如下,index函数有2个参数 二.效果如下: 不忘初心,如果您认为这篇文章有价值,认同作者的付出,可以微信二维码打赏任意金额给作者(微信号:382477247)哦,谢谢.
- Hour of Code|京东云邀您一起,“码”上行动
"如果我并不希望成为一名程序员,那么为什么需要学习编程呢?" 相信很多人对于现在鼓励从小就学习编程的趋势都在心里问过这样的一个问题.在回答这个问题前,先和大家分享一个小故事吧. 1 ...
- JavaWeb之搭建自己的MVC框架(一)
1. 介绍 MVC全名是Model View Controller,是模型(model)-视图(view)-控制器(controller)的缩写,一种软件设计典范,用一种业务逻辑.数据.界面显示分离的 ...
- redis常用命令--strings
strings常用命令: set key value:存值 get key:取值 append key value:在值后追加值 strlen key:获取长度 mset key1 value1 ke ...
- 18 12 2 数据库 sql 的增删改查
---恢复内容开始--- 1 开始进入MySQL 的安装 https://www.cnblogs.com/ayyl/p/5978418.html 膜拜大神的博客 2 默认安装的时候 m ...