题目链接

A. Minimal Square

题意:


题解:




AC代码

/*
    Author:zzugzx
    Lang:C++
    Blog:blog.csdn.net/qq_43756519
*/
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
//const int mod=1e9+7;
const int mod=998244353;
const double eps = 1e-10;
const double pi=acos(-1.0);
const int maxn=2e6+10;
const ll inf=0x3f3f3f3f;
const int dir[4][2]={{0,1},{1,0},{0,-1},{-1,0}};


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int _;
    cin>>_;
    while(_--){
        int a,b;
        cin>>a>>b;
        int s=max(a,2*b);
        int s1=max(b,2*a);
        int ans=min(s,s1);
        cout<<ans*ans<<endl;
    }
    return 0;
}

B. Honest Coach

题意:



题解:



AC代码

/*
    Author:zzugzx
    Lang:C++
    Blog:blog.csdn.net/qq_43756519
*/
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
//const int mod=1e9+7;
const int mod=998244353;
const double eps = 1e-10;
const double pi=acos(-1.0);
const int maxn=1e6+10;
const ll inf=0x3f3f3f3f;
const int dir[4][2]={{0,1},{1,0},{0,-1},{-1,0}};

int a[maxn];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int _;
    cin>>_;
    while(_--){
        int n;
        cin>>n;
        for(int i=1;i<=n;i++)cin>>a[i];
        sort(a+1,a+1+n);
        int ans=inf;
        for(int i=2;i<=n;i++){
            ans=min(ans,a[i]-a[i-1]);
        }
        cout<<ans<<endl;
    }
    return 0;
}

C. Similar Pairs

题意:


题解:




AC代码

/*
    Author:zzugzx
    Lang:C++
    Blog:blog.csdn.net/qq_43756519
*/
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
//const int mod=1e9+7;
const int mod=998244353;
const double eps = 1e-10;
const double pi=acos(-1.0);
const int maxn=1e6+10;
const ll inf=0x3f3f3f3f;
const int dir[4][2]={{0,1},{1,0},{0,-1},{-1,0}};

int a[110],cnt[110];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int _;
    cin>>_;
    while(_--){
        memset(cnt,0,sizeof cnt);
        int n;
        cin>>n;
        int x=0,y=0;
        for(int i=1;i<=n;i++){
            cin>>a[i];
            cnt[a[i]]++;
            if(a[i]&1)x++;
            else y++;
        }
        bool f=0;
        for(int i=1;i<=n;i++)
            if(cnt[a[i]+1]||cnt[a[i]-1]){f=1;break;}
        if(!f&&(x&1))cout<<"NO"<<endl;
        else cout<<"YES"<<endl;
    }
    return 0;
}

D. Buying Shovels

题意:



题解:


AC代码

/*
    Author:zzugzx
    Lang:C++
    Blog:blog.csdn.net/qq_43756519
*/
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
//const int mod=1e9+7;
const int mod=998244353;
const double eps = 1e-10;
const double pi=acos(-1.0);
const int maxn=1e6+10;
const ll inf=0x3f3f3f3f;
const int dir[4][2]={{0,1},{1,0},{0,-1},{-1,0}};


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int _;
    cin>>_;
    while(_--){
        int n,k;
        cin>>n>>k;
        int ans=inf;
        for(int i=1;i*i<=n;i++){
            int t=n/i;
            if(n%i==0&&i<=k)ans=min(ans,n/i);
            if(n%t==0&&t<=k)ans=min(ans,n/t);
        }
        cout<<ans<<endl;
    }
    return 0;
}

E. Polygon

题意:




题意:



AC代码

/*
    Author:zzugzx
    Lang:C++
    Blog:blog.csdn.net/qq_43756519
*/
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
//const int mod=1e9+7;
const int mod=998244353;
const double eps = 1e-10;
const double pi=acos(-1.0);
const int maxn=1e6+10;
const ll inf=0x3f3f3f3f;
const int dir[4][2]={{0,1},{1,0},{0,-1},{-1,0}};

char g[100][100];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int _;
    cin>>_;
    while(_--){
        int n;
        cin>>n;
        for(int i=1;i<=n;i++)cin>>g[i]+1;
        bool f=0;
        for(int i=1;i<=n;i++){
            for(int j=1;j<=n;j++){
                if(g[i][j]=='1'){
                    if(i==n||j==n)continue;
                    if(g[i][j+1]=='0'&&g[i+1][j]=='0'){f=1;break;}
                }
            }
            if(f)break;
        }
        if(f)cout<<"NO"<<endl;
        else cout<<"YES"<<endl;
    }
    return 0;
}

F. Spy-string

题意:



题解:






AC代码

/*
    Author:zzugzx
    Lang:C++
    Blog:blog.csdn.net/qq_43756519
*/
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
//const int mod=1e9+7;
const int mod=998244353;
const double eps = 1e-10;
const double pi=acos(-1.0);
const int maxn=1e6+10;
const ll inf=0x3f3f3f3f;
const int dir[4][2]={{0,1},{1,0},{0,-1},{-1,0}};

bool f;
int n,m,cnt[26];
vector<char> v[20];
char ans[20];
string s[20];
void dfs(int cur){
    if(f)return;
    for(int i=1;i<=n;i++)if(cnt[i]>1)return;
    if(cur==m){
        for(int i=0;i<m;i++)cout<<ans[i];
        cout<<endl;
        f=1;return;
    }
    for(auto i:v[cur]){
        for(int j=1;j<=n;j++)if(s[j][cur]!=i)cnt[j]++;
        ans[cur]=i;
        dfs(cur+1);if(f)return;
        for(int j=1;j<=n;j++)if(s[j][cur]!=i)cnt[j]--;
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int _;
    cin>>_;
    while(_--){
        cin>>n>>m;
        for(int i=1;i<=n;i++)cin>>s[i];
        f=0;
        for(int i=0;i<m;i++){
            v[i].clear();
            memset(cnt,0,sizeof cnt);
            for(int j=1;j<=n;j++)
                cnt[s[j][i]-'a']++;
            for(int j=0;j<26;j++)
                if(cnt[j])v[i].pb(j+'a');
        }
        memset(cnt,0,sizeof cnt);
        dfs(0);if(!f)cout<<-1<<endl;
    }
    return 0;
}

G. A/B Matrix

题意:




题解:







AC代码

/*
    Author:zzugzx
    Lang:C++
    Blog:blog.csdn.net/qq_43756519
*/
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
//const int mod=1e9+7;
const int mod=998244353;
const double eps = 1e-10;
const double pi=acos(-1.0);
const int maxn=1e6+10;
const ll inf=0x3f3f3f3f;
const int dir[4][2]={{0,1},{1,0},{0,-1},{-1,0}};

int g[100][100];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int _;
    cin>>_;
    while(_--){
        int n,m,a,b;
        cin>>n>>m>>a>>b;
        memset(g,0,sizeof g);
        if(n*a!=m*b){cout<<"NO"<<endl;continue;}
        cout<<"YES"<<endl;
        int x=0;
        for(int i=0;i<n;i++)
            for(int j=0;j<a;j++){
                g[i][x++]=1;
                if(x==m)x=0;
            }
        for(int i=0;i<n;i++,cout<<endl)
            for(int j=0;j<m;j++)
                cout<<g[i][j];
    }
    return 0;
}

H. Binary Median

题意:



题解:





AC代码

/*
    Author:zzugzx
    Lang:C++
    Blog:blog.csdn.net/qq_43756519
*/
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
//const int mod=1e9+7;
const int mod=998244353;
const double eps = 1e-10;
const double pi=acos(-1.0);
const int maxn=1e6+10;
const ll inf=0x3f3f3f3f;
const int dir[4][2]={{0,1},{1,0},{0,-1},{-1,0}};

ll a[maxn];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int _;
    cin>>_;
    while(_--){
        int n,m;
        cin>>n>>m;
        for(int i=1;i<=n;i++){
            string s;
            cin>>s;
            a[i]=0;
            for(int j=0;j<m;j++)
                a[i]=(a[i]<<1)|(s[j]=='1');
        }
        ll ok=((1ll<<m)-n+1)>>1;
        sort(a+1,a+1+n);
        ll l=0,r=(1ll<<m)-1,ans;
        while(l<=r){
            ll mid=l+r>>1;
            ll sz=upper_bound(a+1,a+1+n,mid)-(a+1);
            sz=mid+1-sz;
            if(sz>=ok)ans=mid,r=mid-1;
            else l=mid+1;
        }
        for(int i=m-1;i>=0;i--)
            cout<<((ans>>i)&1);
        cout<<endl;
    }
    return 0;
}