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 ...
随机推荐
- SQLServer死锁查询
--查询死锁 select request_session_id spid, OBJECT_NAME(resource_associated_entity_id) tableName from sys ...
- RABBITMQ 协议 AMQP协议
https://baike.baidu.com/item/rabbitmq/9372144?fr=aladdin https://github.com/CopernicaMarketingSoftwa ...
- PHP: thinkPHP踩坑记录(实现API接口以及处理莫名其妙的500问题)
因为各种原因开始学习PHP,并且要在两周内能够对PHP项目进行二次开发,还好PHP够简单,至少入门很简单,很快就接触thinkPHP框架. 在了解了路由匹配视图的规则之后,开始着手尝试编写API接口, ...
- windows下数字以2进制打印
#include <cstdlib> _itoa(num, buf, 2); 打印buf既是二进制
- tf.matmul / tf.multiply
import tensorflow as tfimport numpy as np 1.tf.placeholder placeholder()函数是在神经网络构建graph的时候在模型中的占位,此时 ...
- Codeforces 图论题板刷(2000~2400)
前言 首先先刷完这些在说 题单 25C Roads in Berland 25D Roads not only in Berland 9E Interestring graph and Apples ...
- git & gerrit & shell
g公司使用Gerrit改善评审流程. 比较麻烦.gerrit提交后会触发vertifyCI, 实施代码扫描. 这一堆过程, 打印出一堆信息, 都在log中, 所以处理log就需要自己写shell了. ...
- JavaWeb(七):EL表达式、自定义标签和JSTL
一.EL表达式 语法 el.jsp <%@page import="java.util.Date"%> <%@page import="com.atgu ...
- C语言版本学生信息管理系统
仍然有一些小bug,后续会发布OC完善版的图书馆管理系统,欢迎批评指正. #include <stdio.h> void menu_choose(); typedef struct { i ...
- Telegraf根据配置文件启动(Influxdb的数据收集)
1.创建一个telegraf.config文件 telegraf -sample-config -input-filter cpu:disk:diskio:net:system:mem -output ...