这个题好像可以直接暴力过。我是先用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+7; const double eps=1e-8; const int MAXN=1e6+10; 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==0? a: __gcd(b,a%b); } ll exgcd(ll a,ll b,ll &x,ll &y){ ll d; (b==0? (x=1,y=0,d=a): (d=exgcd(b,a%b,y,x),y-=a/b*x)); return d; } ll qpow(ll a,ll n){ll sum=1;while(n){if(n&1)sum=sum*a%MOD;a=a*a%MOD;n>>=1;}return sum;} inline int dcmp(double x){ if(fabs(x)<eps) return 0; return (x>0? 1: -1); } P que[MAXN]; int num[MAXN]; map<int,map<int,int> >mp; int main(void) { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n,m,l,r,len; cin>>n>>m; if(n==2) return cout<<"YES"<<endl,0; for(int i=0;i<m;i++){ cin>>l>>r; len=min((r-l+n)%n,n-(r-l+n)%n); mp[l][r]=mp[r][l]=1; num[len]++; que[i]=P(l,r); } for(int i=1;i*i<=num[len];i++){ if(num[len]%i==0){ if(i!=1&&n%i==0){ int flag=0,d=n/i; for(int j=0;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=1; break; } } if(!flag) return cout<<"Yes"<<endl,0; } if(num[len]/i!=1&&n%(num[len]/i)==0){ int flag=0,d=n/(num[len]/i); for(int j=0;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=1; break; } } if(!flag) return cout<<"Yes"<<endl,0; } } } cout<<"No"<<endl; return 0; }
Codeforces 1162D Chladni Figure(枚举因子)
原文:https://www.cnblogs.com/dd-bond/p/10815301.html