东塘周二晚上训练课【401】总结

· · 个人记录

东塘周二晚上训练课【401】总结

作者又双叒叕来写总结了TwT

240分……

按顺序来

T1

40分 思路……好像没有思路。

模拟,模拟,还是模拟

代码其实对了,但是40分,就是因为 {\color{red} m,n输入反了}
csp不能这样了。
反正正确代码与错误代码没有多少区别错误代码就不贴了

正确代码

#include<bits/stdc++.h> 
using namespace std;
int x[1005][1005],y[1005][1005];
int main()
{
    int n,m,sx,sy;
    cin>>m>>n>>sx>>sy;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            cin>>x[i][j]>>y[i][j];
        }
    }
    cout<<sx<<' '<<sy<<endl;
    while(x[sx][sy]!=0&&y[sx][sy]!=0)
    {
        cout<<x[sx][sy]<<' '<<y[sx][sy]<<endl;
        int xx=x[sx][sy],yy=y[sx][sy];
        sx=xx;
        sy=yy;
    }
    return 0;
}

原题目:B3702 [语言月赛202301] 华小科的旅行开始了

T2

100分 思路是我写暴力解时想到的。
首先明确一点,十位的数是不会影响个位的
个位最大为9,那么9\times3>23
暴力枚举{三个个位相加之和\% 10 = 3}的所有可能

额……打表 然后,本题完结 是的,作者用的if

#include<bits/stdc++.h> 
using namespace std;
int t[100005];
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        int a;
        cin>>a;
        t[a%10]++;
    }//手废了
    if((t[0]>=2&&t[3]>=1)||(t[0]>=1&&t[1]>=1&&t[2]>=1))
    {
        cout<<"YES";
        return 0;
    }
    if((t[0]>=1&&t[4]>=1&&t[9]>=1)||(t[0]>=1&&t[5]>=1&&t[8]>=1))
    {
        cout<<"YES";
        return 0;
    }
    if(t[1]>=3||(t[0]>=1&&t[6]>=1&&t[7]>=1))
    {
        cout<<"YES";
        return 0;
    }
    if((t[1]>=1&&t[3]>=1&&t[9]>=1)||(t[1]>=1&&t[4]>=1&&t[8]>=1))
    {
        cout<<"YES";
        return 0;
    }
    if((t[1]>=1&&t[5]>=1&&t[7]>=1)||(t[1]>=1&&t[6]>=2))
    {
        cout<<"YES";
        return 0;
    }
    if((t[2]>=2&&t[9]>=1)||(t[2]>=1&&t[3]>=1&&t[8]>=1))
    {
        cout<<"YES";
        return 0;
    }
    if((t[2]>=1&&t[4]>=1&&t[7]>=1)||(t[2]>=1&&t[5]>=1&&t[6]>=1))
    {
        cout<<"YES";
        return 0;
    }
    if((t[3]>=2&&t[7]>=1)||(t[3]>=1&&t[4]>=1&&t[6]>=1))
    {
        cout<<"YES";
        return 0;
    }
    if((t[3]>=1&&t[5]>=2)||(t[4]>=2&&t[5]>=1))
    {
        cout<<"YES";
        return 0;
    }
    if((t[5]>=1&&t[9]>=2)||(t[6]>=1&&t[8]>=1&&t[9]>=1))
    {
        cout<<"YES";
        return 0;
    }
    if((t[7]>=2&&t[9]>=1)||(t[7]>=1&&t[8]>=2))
    {
        cout<<"YES";
        return 0;
    }
    cout<<"NO";
    return 0;
}

T3

100分
思路:

\normalsize栈 \large栈 \Large栈

直接用栈模拟,但是千万不要算次方,合并a_i与a_i+1的结果直接使用a_i +1即可。

#include<bits/stdc++.h> 
using namespace std;
int a[1000000];
stack<int>s;
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    s.push(a[1]);
    for(int i=2;i<=n;i++)
    {
        s.push(a[i]);
        while(1) 
        {
            if(s.size()<2)
            {
                break; 
            }
            int x=s.top();
            s.pop();
            int y=s.top();
            s.pop();
            if(x!=y)
            {
                s.push(y);
                s.push(x);
                break;
            }
            else
            {
                s.push(x+1);
            }
        }
    }
    cout<<s.size();
    return 0;
}

T4

0分
分析题目:

i+j+k=l

三种解:{\color{orange}o(n^4),}{\color{gold}o(n^3),}{\color{lightgreen}o(n^2)}

{\color{orange}o(n^4)}:

枚举i,j,k,l

{\color{gold}o(n^3)}:

枚举i、j、k,用桶确定i+j+k是否存在

{\color{lightgreen}o(n^2)}:

i+j+k=l$->$i+j=l-k