被 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 即可
Educational Codeforces Round 84 总结

#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<<" ";
}

相关文章:

  • 2022-01-27
  • 2022-01-27
  • 2022-01-13
  • 2021-11-11
  • 2021-10-07
  • 2021-12-28
  • 2021-07-02
  • 2021-11-18
猜你喜欢
  • 2021-06-26
  • 2022-12-23
  • 2022-12-23
  • 2021-11-21
  • 2021-10-13
  • 2022-02-28
相关资源
相似解决方案