zoukankan      html  css  js  c++  java
  • Educational Codeforces Round 84 总结

    被 B 题卡了太久, D 题 OEIS 都能 O 错,无语

    A

    #include <bits/stdc++.h>
    using namespace std;
    
    #define int long long
    const int N = 1000005;
    
    signed main() {
        int t,n,k;
        cin>>t;
        while(t--) {
            cin>>n>>k;
            if(n>=k*k && (n-k*k)%2==0) puts("YES");
            else puts("NO");
        }
    }
    

    B

    贪心地考虑最后一个没有匹配的公主和第一个没有匹配的国王

    #include <bits/stdc++.h>
    using namespace std;
    
    #define int long long
    const int N = 1000005;
    
    int t,n,k,tmp,a[N],b[N];
    
    signed main() {
        ios::sync_with_stdio(false);
        cin>>t;
        while(t--) {
            cin>>n;
            for(int i=1;i<=n;i++) a[i]=b[i]=0;
            for(int i=1;i<=n;i++) {
                cin>>k;
                while(k--) {
                    cin>>tmp;
                    if(b[tmp]==0 && a[i]==0) {
                        a[i]=tmp;
                        b[tmp]=i;
                    }
                }
            }
            int x=0,y=0;
            for(int i=1;i<=n;i++) if(a[i]==0) x=i;
            for(int i=n;i>=1;--i) if(b[i]==0) y=i;
            if(x&&y) cout<<"IMPROVE"<<endl<<x<<" "<<y<<endl;
            else cout<<"OPTIMAL"<<endl;
        }
    }
    
    

    C

    先把所有家伙都挪到一起,然后遍历整个地图即可

    #include <bits/stdc++.h>
    using namespace std;
    
    #define int long long
    const int N = 1000005;
    
    int n,m,k;
    
    signed main() {
        cin>>n>>m>>k;
        cout<<(n-1)+(m-1)+(n-1)+n*(m-1)<<endl;
        for(int i=1;i<n;i++) cout<<"U";
        for(int i=1;i<m;i++) cout<<"L";
        for(int i=1;i<=n;i++) {
            for(int j=1;j<m;j++) if(i&1) cout<<"R"; else cout<<"L";
            if(i<n) cout<<"D";
        }
    }
    
    

    D

    (i)(p[i]) 连边,则在每个长度为 (l) 的环里,我们可以花费 (mathcal{O}(l^2)) 的时间去暴力枚举答案

    而答案 (k) 合法等价于答案 ((k,l)) 合法

    于是我们只需要枚举 (l) 的每个因数即可,复杂度 (mathcal{O}(n sqrt n))

    #include <bits/stdc++.h>
    using namespace std;
    
    #define int long long
    const int N = 1000005;
    
    int t,n,a[N],c[N],v[N],ans;
    
    int check(const vector<int> &vec,const int s) {
        int l=vec.size();
        int *u=new int[l];
        for(int i=0;i<l;i++) u[i]=0;
        for(int i=0;i<l;i++) if(u[i]==0) {
            int p=i;
            int fg=1;
            do {
                u[p]=1;
                if(c[vec[p]]!=c[vec[i]]) fg=0;
                p=(p+s)%l;
            } while(p!=i);
            if(fg) return 1;
        }
        return 0;
    }
    
    signed main() {
        ios::sync_with_stdio(false);
        cin>>t;
        while(t--) {
            cin>>n;
            ans=1e9;
            for(int i=1;i<=n;i++) cin>>a[i];
            for(int i=1;i<=n;i++) cin>>c[i];
            for(int i=1;i<=n;i++) if(v[i]==0) {
                vector <int> vec;
                int p=i;
                do {
                    vec.push_back(p);
                    v[p]=1;
                    p=a[p];
                } while(p!=i);
                int l=vec.size();
                for(int j=1;j*j<=l;j++) if(l%j==0) {
                    if(check(vec,j)) ans=min(ans,j);
                    if(check(vec,l/j)) ans=min(ans,l/j);
                }
            }
            cout<<ans<<endl;
            for(int i=1;i<=n;i++) v[i]=0;
        }
    }
    
    

    E

    OEIS 即可

    #include <bits/stdc++.h>
    using namespace std;
    
    #define int long long
    const int N = 1000005;
    const int mod = 998244353;
    
    int a[N],s[N];
    int n;
    
    int qpow(int p,int q) {
        return (q&1?p:1)*(q?qpow(p*p%mod,q/2):1)%mod;
    }
    
    signed main() {
        cin>>n;
        a[1]=10;
        a[2]=180;
        a[3]=2610;
        for(int i=4;i<=n;i++) {
            a[i]=20*a[i-1]%mod-100*a[i-2]%mod;
            a[i]=(a[i]+mod)%mod;
        }
        for(int i=n;i>=1;--i) cout<<(a[i])%mod<<" ";
    }
    
    
  • 相关阅读:
    centos7 设置mongodb远程连接
    计算两个坐标点之间的点的坐标
    vim 设置字体和解决乱码
    webpack无法通过 IP 地址访问 localhost 解决方案
    使用GitHub作为Maven仓库并引用
    ajax 文件下载
    展开被 SpringBoot 玩的日子 《 六 》 整合 Mybatis
    展开被 SpringBoot 玩的日子 《 五 》 spring data jpa 的使用
    展开被 SpringBoot 玩的日子 《 四 》 Session 会话共享
    展开被 SpringBoot 玩的日子 《 三 》 整合Redis
  • 原文地址:https://www.cnblogs.com/mollnn/p/12556634.html
Copyright © 2011-2022 走看看