SDUT 2021 Spring Individual Contest(for 20) - 3补题

Insert picture description here
Meaning of the question: Give three binary strings of length 10, and you can adjust the numbers in one of the strings at will, find the string to be XORed, and find the maximum value that can be obtained
1 ^ 1 ^ 1=1,1 ^ 0 ^ 0=1. Only these two types can get 1. Because the required value is as large as possible, we put 1 to the front as much as possible, because we want to get more 1s. So we first use the 1 0 0 combination. If 1 0 0 cannot be used, then see if 1 1 1 can be used. If neither can be used, the position is 0.

#include<bits/stdc++.h>
using namespace std;
struct node
{
    
    
    int n1=0;
    int n2=0;
};
bool cmp(node a,node b)
{
    
    
    return a.n1>b.n1;
}
int main()
{
    
    
    int t;
    cin>>t;
    while(t--)
    {
    
    
        string s1,s2,s3;
        cin>>s1>>s2>>s3;
        node a[4];
        for(int i=0;i<s1.size();i++)
            if(s1[i]=='1')
                a[1].n1++;
            else
                a[1].n2++;
        for(int i=0;i<s2.size();i++)
            if(s2[i]=='1')
                a[2].n1++;
            else
                a[2].n2++;
        for(int i=0;i<s3.size();i++)
            if(s3[i]=='1')
                a[3].n1++;
            else
                a[3].n2++;
        for(int i=0;i<10;i++)
        {
    
    
            sort(a+1,a+4,cmp);
            if(a[1].n1>0&&a[2].n2>0&&a[3].n2>0)
            {
    
    
                cout<<1;
                a[1].n1--;
                a[2].n2--;
                a[3].n2--;
            }
            else if(a[1].n1>0&&a[2].n1>0&&a[3].n1>0)
            {
    
    
                cout<<1;
                a[1].n1--;
                a[2].n1--;
                a[3].n1--;
            }
            else
            {
    
    
                cout<<0;
            }
        }
        cout<<endl;
    }
    return 0;
}

Insert picture description here
Meaning of the question: give you an n×m table, find the same number of elements between every two layers.
Memory search. Use a map to store it in one layer, and then recycle the query to store it in the next layer of the layer, and then clear the map and enter the query layer, and so on (only using cincout will time out, so add fast reading)

#include<bits/stdc++.h>
using namespace std;
const int N=1e3+10;
long long  a[N][N];
int main()
{
    
    
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin>>t;
    while(t--)
    {
    
    
        int n,m;
        cin>>n>>m;
        for(int i=0;i<n;i++)
        {
    
    
            for(int j=0;j<m;j++)
            {
    
    
                cin>>a[i][j];
            }
        }
        int res=0;
        map<int,int >ma;
        for(int j=0;j<m;j++)
        ma[a[0][j]]++;
        for(int i=1;i<n;i++)
        {
    
    
            for(int j=0;j<m;j++)
            {
    
    
                if(ma[a[i][j]])
                {
    
    
                    res++;
                    ma[a[i][j]]--;
                }
            }
            ma.clear();
            for(int j=0;j<m;j++)
            {
    
    
                ma[a[i][j]]++;
            }

        }
        cout<<res<<endl;
    }
}

Guess you like

Origin blog.csdn.net/weixin_51768569/article/details/114494913