Codeforces 1162D Chladni Figure(枚举因子)
这个题好像可以直接暴力过。我是先用num[len]统计所有每个长度的数量有多少,假如在长度为len下,如果要考虑旋转后和原来图案保持一致,我们用a表示在一个旋转单位中有几个长度为len的线段,b表示有几个这样的旋转单位,那么可以表示a*b=num[len],满足这样的a,b一定可以满足要求,这时候就可以发现只需要枚举因子暴力扫过去即可,我们用map存下所有点的位置,在枚举块的数量时是直接可以算出旋转角,那我们直接对所有点进行判断,旋转后是否存在这样的一个点。有一个坑,当num[len]长度为1时,只存在n==2时满足要求,其他的时候是不可能存在,这里要进行特判。
// ——By DD_BOND //#include<bits/stdc++.h>
#include<functional>
#include<algorithm>
#include<iostream>
#include<sstream>
#include<iomanip>
#include<climits>
#include<cstring>
#include<cstdlib>
#include<cstddef>
#include<cstdio>
#include<memory>
#include<vector>
#include<cctype>
#include<string>
#include<cmath>
#include<queue>
#include<deque>
#include<ctime>
#include<stack>
#include<map>
#include<set> #define fi first
#define se second
#define MP make_pair
#define pb push_back
#define INF 0x3f3f3f3f
#define pi 3.1415926535898
#define lowbit(a) (a&(-a))
#define lson l,(l+r)/2,rt<<1
#define rson (l+r)/2+1,r,rt<<1|1
#define Min(a,b,c) min(a,min(b,c))
#define Max(a,b,c) max(a,max(b,c))
#define debug(x) cerr<<#x<<"="<<x<<"\n"; using namespace std; typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef unsigned long long ull; const ll LLMAX=2e18;
const int MOD=1e9+;
const double eps=1e-;
const int MAXN=1e6+; inline ll sqr(ll x){ return x*x; }
inline int sqr(int x){ return x*x; }
inline double sqr(double x){ return x*x; }
ll gcd(ll a,ll b){ return b==? a: __gcd(b,a%b); }
ll exgcd(ll a,ll b,ll &x,ll &y){ ll d; (b==? (x=,y=,d=a): (d=exgcd(b,a%b,y,x),y-=a/b*x)); return d; }
ll qpow(ll a,ll n){ll sum=;while(n){if(n&)sum=sum*a%MOD;a=a*a%MOD;n>>=;}return sum;}
inline int dcmp(double x){ if(fabs(x)<eps) return ; return (x>? : -); } P que[MAXN];
int num[MAXN];
map<int,map<int,int> >mp; int main(void)
{
ios::sync_with_stdio(false); cin.tie(); cout.tie();
int n,m,l,r,len; cin>>n>>m;
if(n==) return cout<<"YES"<<endl,;
for(int i=;i<m;i++){
cin>>l>>r;
len=min((r-l+n)%n,n-(r-l+n)%n);
mp[l][r]=mp[r][l]=;
num[len]++;
que[i]=P(l,r);
}
for(int i=;i*i<=num[len];i++){
if(num[len]%i==){
if(i!=&&n%i==){
int flag=,d=n/i;
for(int j=;j<m;j++){
int l=que[j].fi,r=que[j].se,ld=l+d,rd=r+d;
if(ld>n) ld-=n;
if(rd>n) rd-=n;
if(mp[ld].find(rd)==mp[ld].end()){
flag=;
break;
}
}
if(!flag) return cout<<"Yes"<<endl,;
}
if(num[len]/i!=&&n%(num[len]/i)==){
int flag=,d=n/(num[len]/i);
for(int j=;j<m;j++){
int l=que[j].fi,r=que[j].se,ld=l+d,rd=r+d;
if(ld>n) ld-=n;
if(rd>n) rd-=n;
if(mp[ld].find(rd)==mp[ld].end()){
flag=;
break;
}
}
if(!flag) return cout<<"Yes"<<endl,;
}
}
}
cout<<"No"<<endl;
return ;
}
Codeforces 1162D Chladni Figure(枚举因子)的更多相关文章
- Chladni Figure CodeForces - 1162D (暴力,真香啊~)
Chladni Figure CodeForces - 1162D Inaka has a disc, the circumference of which is nn units. The circ ...
- 洛谷-P1414 又是毕业季II -枚举因子
P1414 又是毕业季II:https://www.luogu.org/problemnew/show/P1414 题意: 给定一个长度为n的数列.要求输出n个数字,每个数字代表从给定数列中最合理地取 ...
- codeforces 895A Pizza Separation 枚举
codeforces 895A Pizza Separation 题目大意: 分成两大部分,使得这两部分的差值最小(注意是圆形,首尾相连) 思路: 分割出来的部分是连续的,开二倍枚举. 注意不要看成0 ...
- 【cf842C】 Ilya And The Tree(dfs、枚举因子)
C. Ilya And The Tree 题意 给一棵树求每个点到根的路上允许修改一个为0,gcd的最大值. 题解 g是从根到当前点允许修改的最大gcd,gs为不修改的最大gcd.枚举当前点的因子,更 ...
- Educational Codeforces Round 61 C 枚举 + 差分前缀和
https://codeforces.com/contest/1132/problem/C 枚举 + 差分前缀和 题意 有一段[1,n]的线段,有q个区间,选择其中q-2个区间,使得覆盖线段上的点最多 ...
- Vasya and Beautiful Arrays CodeForces - 354C (数论,枚举)
Vasya and Beautiful Arrays CodeForces - 354C Vasya's got a birthday coming up and his mom decided to ...
- hdu5108枚举因子求最小的m
题意: 给一个n(<=10Y),然后让找到一个最小的m使得n/m是一个素数. 思路: 先用sqrt(n)的时间把所有的因子都求出来,然后在排序,枚举,就行了,这个题目这么做 ...
- CodeForces 617C【序枚举】
题意: 有两个点喷水,有很多个点有花,给出坐标. 求使得每个花都可以被喷到,两个喷水的半径的平方的和最小是多少. 思路: 枚举其中一个喷水的最大半径. 坑: 这题我贪心的思路有很大问题.一开始也是想这 ...
- codeforces 613B B. Skills(枚举+二分+贪心)
题目链接: B. Skills time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
随机推荐
- SwiftUI 实战:从 0 到 1 研发一个 App
心得感悟 起初看到 WWDC 上的演示 SwiftUI 时,我就觉得 SwiftUI 有种陌生的熟悉感(声明式语法),所以体验下,看看有没有什么启发. 先说下整体项目完成下来的感受: 用 Swift ...
- React-请求篇
请求方式: (1)后台API:HttpPost [FromForm] UserRetisterDTO dto 前端请求: { body:qs.stringify(dto), header ...
- [POI2008]Sta(树形dp)
[POI2008]Sta Description 给出一个N个点的树,找出一个点来,以这个点为根的树时,所有点的深度之和最大 Input 给出一个数字N,代表有N个点.N<=1000000 下面 ...
- shell脚本--expect自动应答
expect自动应答 TCL语言 需求1:远程登录到A主机,什么事情也不做 #! /usr/bin/env expect # 开启一个程序 spawn ssh root@192.144.213.11 ...
- php内置函数分析之strtoupper()、strtolower()
strtoupper(): PHP_FUNCTION(strtoupper) { zend_string *str; ZEND_PARSE_PARAMETERS_START(, ) Z_PARAM_S ...
- mysql 备份和还原
1.使用mysqldump命令 备份:mysqldump -u username -p dbname table1 table2 ...> BackupName.sql 还原:mysql -u ...
- Spring---MongoDB
1.MongoDB概述 1.1.NoSQL数据库 1.1.1.NoSQL的主要特点: 不使用SQL语言 作为查询条件: 数据存储 也不是固定的表.字段: 1.1.2.NoSQL数据库 主要有 ...
- ConversionService HttpMessageConverter
ConversionService是属于spring core部分 所有spring管理的bean等等 都使用它进行类型转换,而它又需要注册一些converter 来完成类型转换. 这个可以看我博客 ...
- .Net Core 学习目录(搁置)
简介 .NET Core 是.NET Framework的新一代版本,是微软开发的第一个官方版本,具有跨平台 (Windows.Mac OSX.Linux) 能力的应用程序开发框架 (Applicat ...
- 基于ELK Stack7.1.0构建多用户安全认证日志系统
配置tls加密通信及身份验证,主要目的是为了确保集群数据安全.在es早期版本,安全认证相关功能都属于商业付费服务,一般普通公司如果集群部署在内网,基本上就忽略了这些安全认证,当然也可以通过Ngin ...