2024初三年前集训测试1

2024初三年前集训测试1

我 TM 以后比赛不造数据对拍就 TM 是大傻逼

打了 2 hours,觉得挺简单的,于是交了就润了。

所以我是傻逼。

  1. T1:

    显然题,但 scanf(" %c",&a) scanf("%c",&a)100pts30pts

    wkh2008 精通科技,可是我不会。

    科技
    #include <bits/stdc++.h>
    using namespace std;
    signed main() {
    freopen("word.in", "r", stdin);
    freopen("word.out", "w", stdout);
    string s; cin >> s;
    for (auto & c : s) if (c == '_') c = ' ';
    stringstream ss(s);
    string _;
    size_t ans = 0;
    while (ss >> _) ans = max(ans, _.size());
    cout << ans << endl;
    return 0;
    }
  2. T2:

    hash map 匹配即可

    CODE
    #include<bits/stdc++.h>
    using namespace std;
    typedef long long llt;
    typedef unsigned long long ull;
    #define For(i,a,b,c) for(int i=(a);i<=(b);i+=(c))
    #define For_(i,a,b,c) for(int i=(a);i>=(b);i-=(c))
    map<string,bool> c;
    int n,m;
    int main(){
    freopen("dalao.in","r",stdin);
    freopen("dalao.out","w",stdout);
    cin>>n;
    For(i,1,n,1){
    string s;cin>>s;
    c[s]=1;
    }
    cin>>m;
    For(i,1,m,1){
    string s;
    cin>>s>>s>>s;
    if(c.count(s)) puts("Yes");
    else puts("No");
    }
    }
  3. T3:

    01bfs 显然

    但在入队前判的重复,导致同时入队的重复一大把

    100pts60pts

    CODE
    #include<bits/stdc++.h>
    using namespace std;
    typedef long long llt;
    typedef unsigned long long ull;
    #define For(i,a,b,c) for(int i=(a);i<=(b);i+=(c))
    #define For_(i,a,b,c) for(int i=(a);i>=(b);i-=(c))
    const int N=303,X[]={0,0,0,-1,1},Y[]={0,1,-1,0,0};
    int n,m;
    char c[N][N];
    struct POS{int x=0,y=0;}to[N][N],ed;
    queue<pair<POS,int> > que;
    bool vis[N][N];
    int main(){
    freopen("maze.in","r",stdin);
    freopen("maze.out","w",stdout);
    scanf("%d%d",&n,&m);
    For(i,1,n,1) For(j,1,m,1) scanf(" %c",&c[i][j]);
    For(i,1,n,1) For(j,1,m,1){
    to[i][j]={i,j};
    if(c[i][j]=='@') que.push(make_pair(POS{i,j},0));
    else if(c[i][j]=='=') ed=POS{i,j};
    else if(c[i][j]!='#'&&c[i][j]!='.')
    For(a,1,n,1) For(b,1,m,1) if((i!=a||j!=b)&&c[i][j]==c[a][b]) to[i][j]=POS{a,b};
    }
    while(!que.empty()){
    int x=que.front().first.x,y=que.front().first.y,t=que.front().second; que.pop();
    if(vis[x][y]) continue;
    vis[x][y]=1;
    For(i,1,4,1){
    int xx=to[x+X[i]][y+Y[i]].x,yy=to[x+X[i]][y+Y[i]].y;
    if(vis[xx][yy]||xx<1||yy<1||c[xx][yy]=='#') continue;
    if(xx==ed.x&&yy==ed.y){cout<<t+1<<endl;return 0;}
    que.push(make_pair(POS{xx,yy},t+1));
    }
    }
    cout<<-1<<endl;
    }
  4. T4:

    显然的贪心。

    可以将数列想象成一个柱状图,一个柱的高度就是其数字大小。

    于是变成了将所有柱变等高。

    按层考虑,每层要么补,要么删,贪心选择。

    难点在怎么维护每层的块(相连的在这层存在的柱)的个数,可以差分,每输入一个数字时判断。

    具体的看代码。

    CODE
    #include<bits/stdc++.h>
    using namespace std;
    typedef long long llt;
    typedef unsigned long long ull;
    #define For(i,a,b,c) for(int i=(a);i<=(b);i+=(c))
    #define For_(i,a,b,c) for(int i=(a);i>=(b);i-=(c))
    const int N=2e6+4;
    int n,m,ans,s[N],e[N],ma,mi;
    int main(){
    freopen("game.in","r",stdin);
    freopen("game.out","w",stdout);
    scanf("%d",&n);
    int a,lst;scanf("%d",&lst),ma=mi=lst;
    For(i,2,n,1){
    scanf("%d",&a);ma=max(ma,a),mi=min(mi,a);
    if(lst>a) s[a+1]++,s[lst+1]--;
    else e[lst+1]++,e[a+1]--;
    lst=a;
    }
    s[0]++,s[lst+1]--;
    e[lst+1]++;
    For(i,1,ma,1) s[i]+=s[i-1],e[i]+=e[i-1];
    For(i,mi+1,ma,1){
    ans+=min(s[i],e[i]);
    }
    printf("%d",ans);
    }
posted @   5k_sync_closer  阅读(71)  评论(2编辑  收藏  举报
相关博文:
阅读排行:
· 【.NET】调用本地 Deepseek 模型
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· DeepSeek “源神”启动!「GitHub 热点速览」
· 我与微信审核的“相爱相杀”看个人小程序副业
· Plotly.NET 一个为 .NET 打造的强大开源交互式图表库
点击右上角即可分享
微信分享提示