Jeanny
寂兮,寥兮,独立不改,周行而不殆

t1学说话

#include<bits/stdc++.h>
using namespace std;
string str;
int ans;
int main()
{
    // freopen("word.in","r",stdin);
    // freopen("word.out","w",stdout);
    ios::sync_with_stdio(false);
    cin>>str;
    int now=0;
    for(int i=0;i<str.size();++i)
    {
        if(str[i]=='_')
            now=0;
        else
            ++now;
        ans=max(ans,now);
    }
    cout<<ans<<endl; 
    return 0;
}

 

t2模大佬

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
#define fox(i,a,b) for(int i=a;i<=b;++i)
using namespace std;

typedef unsigned long long ULL;

const int P = 157;
int n, m;
char c[30010];
ULL h[3010];

int main(){
    // freopen("dalao.in", "r", stdin);
    // freopen("dalao.out", "w", stdout);
    scanf("%d\n",&n);
    ULL x;
    int len = 0;
    for(int i=1; i<=n; ++i) {
        scanf("%s", c + 1); len = strlen(c + 1);
        x = 0;
        for(int j=1; j<=len; ++j)
            x = x * P + c[j];
        h[i] = x;
    }
    bool f;
    scanf("%d\n", &m);
    for(int i=1; i<=m; ++i) {
        memset(c,0,sizeof c);
        scanf("%s", c + 1);
        len = strlen(c + 1);

        memset(c,0,sizeof c);
        scanf("%s", c + 1);
        len = strlen(c + 1);

        memset(c,0,sizeof c);
        scanf("%s", c + 1);
        len = strlen(c + 1);
        x = 0, f = 0;
        for(int j=1; j<=len; ++j) x = x * P + c[j];
        for(int i=1; i<=n; ++i) if (x == h[i]) f = 1;
        if (f) puts("Yes");
        else puts("No");
    }
    return 0;
}
/*
3
Srf
Pcf
Czy
2
Qty mod Srf
Pcf mod cbQty
*/

 

t3 迷宫 maze

宽搜:是字母和非字母的处理方法不一样,因此状态标记不一样.

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;
const int maxn=3E2+5;
const int inf=1E6+5;
int n,m;
int a[maxn][maxn];
int f[maxn][maxn][2];
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int size[555];
bool vis[maxn][maxn];
string str;
struct pt{
    int x,y,dis;
    pt(int a = 0,int b = 0,int d = 0):x(a),y(b),dis(d){}
}where[555][2],S,T;
int main(){
    ios::sync_with_stdio(false);
    cin>>n>>m;
    for(int i=1;i<=n;++i)
    {
        cin>>str;
        for(int j=1;j<=m;++j)
        {
            if(str[j-1]=='#')
                a[i][j]=1;
            else if(str[j-1]=='.')
                a[i][j]=0;
            else if(str[j-1]=='@')
                S.x=i,S.y=j;
            else if(str[j-1]=='=')
                T.x=i,T.y=j,a[i][j]=0;
            else
            {
                a[i][j]=str[j-1];
                where[str[j-1]][size[str[j-1]]++]=pt(i,j);
            }
        }
    }
    queue<pt>Q;
    S.dis = 0; Q.push(S);
    // f[S.x][S.y][0]=0;
    while(!Q.empty()){
        pt u = Q.front(); Q.pop();
        // cout<<u.x<<" "<<u.y<<" ,"<<a[u.x][u.y]<<" &"<<char(a[u.x][u.y])<<", "<<u.dis<<endl;
        if(u.x == T.x && u.y == T.y){
            printf("%d\n",u.dis);
            return 0;
        }
        for(int i=0;i<4;++i){
            int nx=u.x+dx[i], ny=u.y+dy[i];
            if(nx<1 || n<nx || ny<1 || m<ny) continue;
            if(a[nx][ny]==0){
                if(vis[nx][ny]) continue;
                vis[nx][ny]=1;
                Q.push(pt(nx, ny, u.dis + 1));
            }
            else if(a[nx][ny]!=1)//是字母
            {
                for(int j=0;j<2;++j){
                    pt v= where[a[nx][ny]][j];
                    if((v.x==nx && v.y==ny) || vis[v.x][v.y])
                        continue;
                    //若走到其中一个传送装置上,她 会立马传送到另一个传送装置。
                    vis[v.x][v.y]=1;
                    Q.push(pt(v.x, v.y, u.dis+1));
                }
            }
        }
    }
    cout<<-1<<endl;
    return 0;
}
/*
5 6
###=##
#.W.##
#.####
#.@W##
######
*/

 

posted on 2020-07-21 10:10  Jeanny  阅读(149)  评论(0)    收藏  举报