zoukankan      html  css  js  c++  java
  • Codeforces 1162D Chladni Figure(枚举因子)

    这个题好像可以直接暴力过。我是先用num[len]统计所有每个长度的数量有多少,假如在长度为len下,如果要考虑旋转后和原来图案保持一致,我们用a表示在一个旋转单位中有几个长度为len的线段,b表示有几个这样的旋转单位,那么可以表示a*b=num[len],满足这样的a,b一定可以满足要求,这时候就可以发现只需要枚举因子暴力扫过去即可,我们用map存下所有点的位置,在枚举块的数量时是直接可以算出旋转角,那我们直接对所有点进行判断,旋转后是否存在这样的一个点。有一个坑,当num[len]长度为1时,只存在n==2时满足要求,其他的时候是不可能存在,这里要进行特判。

      1 //      ——By DD_BOND 
      2 
      3 //#include<bits/stdc++.h>
      4 #include<functional>
      5 #include<algorithm>
      6 #include<iostream>
      7 #include<sstream>
      8 #include<iomanip>
      9 #include<climits>
     10 #include<cstring>
     11 #include<cstdlib>
     12 #include<cstddef>
     13 #include<cstdio>
     14 #include<memory>
     15 #include<vector>
     16 #include<cctype>
     17 #include<string>
     18 #include<cmath>
     19 #include<queue>
     20 #include<deque>
     21 #include<ctime>
     22 #include<stack>
     23 #include<map>
     24 #include<set>
     25 
     26 #define fi first
     27 #define se second
     28 #define MP make_pair
     29 #define pb push_back
     30 #define INF 0x3f3f3f3f
     31 #define pi 3.1415926535898
     32 #define lowbit(a)  (a&(-a))
     33 #define lson l,(l+r)/2,rt<<1
     34 #define rson (l+r)/2+1,r,rt<<1|1
     35 #define Min(a,b,c)  min(a,min(b,c))
     36 #define Max(a,b,c)  max(a,max(b,c))
     37 #define debug(x)  cerr<<#x<<"="<<x<<"
    ";
     38 
     39 using namespace std;
     40 
     41 typedef long long ll;
     42 typedef pair<int,int> P;
     43 typedef pair<ll,ll> Pll;
     44 typedef unsigned long long ull;
     45 
     46 const ll LLMAX=2e18;
     47 const int MOD=1e9+7;
     48 const double eps=1e-8;
     49 const int MAXN=1e6+10;
     50 
     51 inline ll sqr(ll x){ return x*x; }
     52 inline int sqr(int x){ return x*x; }
     53 inline double sqr(double x){ return x*x; }
     54 ll gcd(ll a,ll b){ return b==0? a: __gcd(b,a%b); }
     55 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; }
     56 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;}
     57 inline int dcmp(double x){  if(fabs(x)<eps) return 0;   return (x>0? 1: -1); }
     58 
     59 P que[MAXN];
     60 int num[MAXN];
     61 map<int,map<int,int> >mp;
     62 
     63 int main(void)
     64 {
     65     ios::sync_with_stdio(false);    cin.tie(0);   cout.tie(0);   
     66     int n,m,l,r,len;    cin>>n>>m;
     67     if(n==2)    return cout<<"YES"<<endl,0;
     68     for(int i=0;i<m;i++){
     69         cin>>l>>r;
     70         len=min((r-l+n)%n,n-(r-l+n)%n);
     71         mp[l][r]=mp[r][l]=1;
     72         num[len]++;
     73         que[i]=P(l,r);
     74     }
     75     for(int i=1;i*i<=num[len];i++){
     76         if(num[len]%i==0){
     77             if(i!=1&&n%i==0){
     78                 int flag=0,d=n/i;
     79                 for(int j=0;j<m;j++){
     80                     int l=que[j].fi,r=que[j].se,ld=l+d,rd=r+d;
     81                     if(ld>n)    ld-=n;  
     82                     if(rd>n)    rd-=n;
     83                     if(mp[ld].find(rd)==mp[ld].end()){
     84                         flag=1;
     85                         break;
     86                     }
     87                 }
     88                 if(!flag)   return cout<<"Yes"<<endl,0;
     89             }
     90             if(num[len]/i!=1&&n%(num[len]/i)==0){
     91                 int flag=0,d=n/(num[len]/i);
     92                 for(int j=0;j<m;j++){
     93                     int l=que[j].fi,r=que[j].se,ld=l+d,rd=r+d;
     94                     if(ld>n)    ld-=n;  
     95                     if(rd>n)    rd-=n;
     96                     if(mp[ld].find(rd)==mp[ld].end()){
     97                         flag=1;
     98                         break;
     99                     }
    100                 }
    101                 if(!flag)   return cout<<"Yes"<<endl,0;
    102             }
    103         }
    104     }
    105     cout<<"No"<<endl;
    106     return 0;
    107 }
  • 相关阅读:
    【HIDS】关于HIDS的一些看法
    图片在容器内水平垂直居中显示
    C++ 实现Cholesky分解
    Minikube 安装和简单使用
    关于.net的一些记录
    C#将窗体Form嵌入主窗体Panel中的一些问题
    Pod持久化
    Maven打包包含jar包
    Adam
    [漏洞]DNS Server Spoofed Request Amplification DDoS
  • 原文地址:https://www.cnblogs.com/dd-bond/p/10815301.html
Copyright © 2011-2022 走看看