10.16总结

· · 个人记录

题目列表

A 100 [入门赛 #52] 中秋灯会 30

B 100 「WWOI R4」二五一十 未提交

C 100 Xterfusion 10

D 100 [山东省小学组体验营 2026] 中位数 未提交

A题

❌️{\color{red}错误思路:}

::::error[❌️{\color{red}错误代码:}]

#include<bits/stdc++.h>
using namespace std;
int n,m,q;
int a[10010][10010];
int main(){
//    ios::sync_with_stdio(false);
//    cin.tie(0);
//    cout.tie(0);

    cin>>n>>m>>q;
    int cnt=1;
    while(q--)
    {
        int op;
        cin>>op;
        if(op==1)
        {
            int x,y,h,w,f=0;
            cin>>x>>y>>h>>w;
            if(x+h-1>n||y+w-1>m)
            {
                cout<<"Error"<<'\n';
                f=1;
            }
            for(int i=x;i<=x+h-1;i++)
            {

                for(int j=y;j<=y+w-1;j++)
                {
                    if(a[i][j]!=0)
                    {
                        cout<<"Error"<<'\n';
                        f=1;
                    }
                }

            }

            if(f==0)
            {
                for(int i=x;i<=x+h-1;i++)
                {

                    for(int j=y;j<=y+w-1;j++)
                    {
                        a[i][j]=cnt;
                    }

                }
                cout<<cnt<<'\n';cnt++;
            }




        }
        else if(op==2)
        {
            int id;
            cin>>id;
            int f=0;
            for(int i=1;i<=n;i++)
            {
                for(int j=1;j<=m;j++)
                {
                    if(a[i][j]==id)
                    {
                        a[i][j]=0;
                        f=1;
                    }
                }
            }
            if(f==0)
            {
                cout<<"Error\n";
            }
            else cout<<"Remove\n";
        }
        else if(op==3)
        {
            int x,y;
            cin>>x>>y;
            cout<<a[x][y]<<'\n';
        }
    }
    int ans=0;
    map<int,int>mp;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(a[i][j]!=0)
            {
                mp[a[i][j]]++;
                ans++;
            }
        }
    }
    cout<<mp.size()<<' '<<ans<<'\n';
    return 0;
}

::::

✅️{\color{green}正确思路:}

✅️ ::::success[{\color{green} 正确代码}\color{green}:]

#include<bits/stdc++.h>
using namespace std;
int n,m,q;
int a[10010][10010];
int main(){
//    ios::sync_with_stdio(false);
//    cin.tie(0);
//    cout.tie(0);

    cin>>n>>m>>q;
    int cnt=0;
    while(q--)
    {
        int op;
        cin>>op;
        if(op==1)
        {
            int x,y,h,w;
            cin>>x>>y>>h>>w;
            if(x+h-1>n||y+w-1>m)
            {
                cout<<"Error"<<'\n';
                continue;
            }
            int f=0;
            for(int i=x;i<=x+h-1;i++)
            {

                for(int j=y;j<=y+w-1;j++)
                {
                    if(a[i][j])
                    {

                        f=1;
                    }
                }

            }

            if(f==0)
            {
                cnt++;
                for(int i=x;i<=x+h-1;i++)
                {

                    for(int j=y;j<=y+w-1;j++)
                    {
                        a[i][j]=cnt;
                    }

                }
                cout<<cnt<<'\n';
            }
            else cout<<"Error\n";




        }
        else if(op==2)
        {
            int id;
            cin>>id;
            int f=0;
            for(int i=1;i<=n;i++)
            {
                for(int j=1;j<=m;j++)
                {
                    if(a[i][j]==id)
                    {
                        a[i][j]=0;
                        f=1;
                    }
                }
            }
            if(f)
            {
                cout<<"Remove\n";
            }
            else cout<<"Error\n";
        }
        else if(op==3)
        {
            int x,y;
            cin>>x>>y;
            cout<<a[x][y]<<'\n';
        }
    }
    int ans=0;
    map<int,int>mp;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(a[i][j])
            {
                mp[a[i][j]]++;
                ans++;
            }
        }
    }
    cout<<mp.size()<<' '<<ans<<'\n';
    return 0;
}

::::

B题

❌️{\color{red}错误思路:}

::::error[❌️{\color{red}错误代码:}]

//无

::::

✅️{\color{green}正确思路:}

✅️ ::::success[{\color{green} 正确代码}\color{green}:]

#include<bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        int a[10001][10010];
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=n;j++)
            {
                a[i][j]=1;

            }
        }
        for(int i=2;i<=n;i++)
        {
            for(int j=i;j<=n;j+=i)
            {
                a[i][j]=i;
                a[j][i]=i;
            }
        }
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=n;j++)
            {
                cout<<a[i][j]<<' ';
            }
            cout<<'\n';
        }
    }
    return 0;
}

::::

C题

❌️{\color{red}错误思路:}

::::error[❌️{\color{red}错误代码:}]


#include<bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout<<"无";//无
    return 0;
}

::::

✅️{\color{green}正确思路:}

✅️ ::::success[{\color{green} 正确代码}\color{green}:]

#include<bits/stdc++.h>
using namespace std;
int cnt[10010][10010];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        int x,y,r;
        cin>>x>>y>>r;
        for(int xx=1;xx<=1000;xx++)
        {
            for(int yy=1;yy<=1000;yy++)
            {
                if((x-xx)*(x-xx)+(y-yy)*(y-yy)<=r*r)
                cnt[xx][yy]++;
            }
        }

    }
    int q;
    cin>>q;
    while(q--)
    {
        int x,y;
        cin>>x>>y;
        if(cnt[x][y]%2)cout<<"Yes"<<'\n';
        else cout<<"No"<<'\n';
    }
    return 0;
}

::::

D题

❌️{\color{red}错误思路:}

::::error[❌️{\color{red}错误代码:}]

//无

::::

✅️{\color{green}正确思路:}

✅️ ::::success[{\color{green} 正确代码}\color{green}:]

#include<bits/stdc++.h>
using namespace std;
#define int long long
int a[10010],b[10010];
int dp[10010],dp1[10010];
int n,m;
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin>>n>>m;
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        ans+=a[i];
    }

    while(m--)
    {
        int k;
        cin>>k;
        for(int i=0;i<=n;i++)
        {
            dp[i]=dp1[i]=0;
            b[i]=(a[i]^k)-a[i];
        }
        int mmax=-1e18,mmin=1e18;
        for(int i=1;i<=n;i++)
        {
            dp[i]=max(b[i],dp[i-1]+b[i]);
            dp1[i]=min(b[i],dp1[i-1]+b[i]);
            mmax=max(mmax,dp[i]);
            mmin=min(mmin,dp1[i]);
        }
        cout<<ans+mmin<<' '<<ans+mmax<<'\n';
    }
    return 0;
}

::::