• 个人简介

    誓超前桌文

    期中考试毕,吾观榜单,前桌之位,赫然在前,吾之名次,竟落其后。

    抚心自问,非吾才疏,实乃往日懈怠,疏于温习,浅于钻研。课上偶有分神,案上常置闲书,习题未勤加演练,知识点未反复巩固,是以与前桌有此差距。

    然吾非甘居人下之辈!马年当有马不停蹄之志,今立此誓,以明初心。自此以后,鸡鸣即起,诵念诗书;夜阑仍读,推敲数理。前桌所做之题,吾必尽皆完成,前桌所悟之理,吾必深究透彻。遇疑惑则勤问,逢难题则勇攻,不敢有半分懈怠,不敢有一时松懈。

    待下次考试,吾必策马扬鞭,奋起直追,跨越此距,重回前列。若违此誓,天地共鉴,学业不进,万事难成!

    What the fack!!! bfs

    #include<bits/stdc++.h>
    using namespace std;
    int a,b;
    char c[10000][10000];
    int ox[21]{0,0,1,-1,0};
    int oy[10]{0,1,0,0,-1};
    struct st{
    	int sx;
    	int sy;
    };
    bool vis[10009][10000];
    int ans=0;
    int check(int sx,int sy){
    	if(c[sx][sy]!='W')return 0;
        if(sx<1||sx>a||sy<1||sy>b)return 0;
    	if(vis[sx][sy]==1)return 0;
        return 1;
    }
    void bfs(int x,int y){
    	queue<st>s;
    	s.push(st{x,y});
        vis[x][y]=1;
    	while(!s.empty()){
    	st fr=s.front();	
    		s.pop();
    		for(int i=1;i<=4;i++){
    			int nx=fr.sx+ox[i];
    			int ny=fr.sy+oy[i];
    		if(check(nx,ny)){
    			vis[nx][ny]=1;
    			s.push(st{nx,ny});
    		}			
    		}
    	}
        ans++;
    }
    int main(){
    	cin>>a>>b;
    	for(int i=1;i<=a;i++){
    		for(int j=1;j<=b;j++){
    			cin>>c[i][j];
    		}
    	}
        for(int i=1;i<=a;i++){
    		for(int j=1;j<=b;j++){
    			if(c[i][j]=='W'&&vis[i][j]==0){
    				bfs(i,j);
    			}
    		}
    	}
    cout<<ans;
    	return 0;
    }
    
    

    砝码

    #include<bits/stdc++.h>
    using namespace std;
    int ox[21] {0,0,1,-1,0};
    int oy[10] {0,1,0,0,-1};
    bool vis[10000][10000];
    char c[10000][100000];
    int a,b;
    int sx,sy,ex,ey;
    struct st {
    	int ix;
    	int iy;
    	int step;
    };
    bool check(int o,int p) {
    	if(o>a||o<1||p>b||p<1)return 0;
    	if(vis[o][p]==1)return 0;
    	if(c[o][p]=='#')return 0;
    	return 1;
    }
    void bfs(int x,int y) {
    	vis[x][y]=1;
    	queue<st>s;
    	s.push(st {x,y,0});
    	while(!s.empty()) {
    		st fr=s.front();
    		s.pop();
    		for(int i=1; i<=4; i++) {
    			int nx=fr.ix+ox[i];
    			int ny=fr.iy+oy[i];
    			if(nx==ex&&ny==ey){
    				cout<<fr.step+1;
    				exit(0);
    			}
    			if(check(nx,ny)) {
    				vis[nx][ny]=1;
    				s.push(st {nx,ny,fr.step+1});
    			}
    		}
    	}
    }
    int main() {
    	cin>>a>>b;
    	for(int i=1; i<=a; i++) {
    		for(int j=1; j<=b; j++) {
    			cin>>c[i][j];
    			if(c[i][j]=='@') {
    				sx=i;
    				sy=j;
    			}
    			if(c[i][j]=='*') {
    				ex=i;
    				ey=j;
    			}
    		}
    	}
    	bfs(sx,sy);
    	return 0;
    }
    
    
    ox[]{1,2,2,1,-1,-2,-2,-1};
    oy[]{2,1,-1,-2,-2,-1,1,2}; 
         
    
    #include<bits/stdc++.h>
    using namespace std;
    int a,b;
    int c[1005];
    int nx;
    int ans=0;
    bool vis[1005];
    struct st{
    	int zhon;
    	int shu;
    };
    bool check(int si){
    	if(si>b||si<0)return 0;
        if(vis[si]==1)return 0;
        return 1;
    }
    void bfs(int x){
    queue<st>s;
    vis[x]=1;
    int px;
    s.push({0,0});
    while(!s.empty()){
        st fr=s.front();
        s.pop();
            if(fr.zhon == b){
                cout << fr.shu;
                return ;
            }
        for(int i=1;i<=a;i++){
             nx=fr.zhon+c[i]; 
            if(check(nx)){
            vis[nx]=1;
            s.push({nx,fr.shu+1});
            }	
    	}
    }
    cout<<"Impossible";
    }
    int main(){
    cin>>a>>b;
    for(int i=1;i<=a;i++)cin>>c[i];
    bfs(0);
    return 0;
    }
    
    
    
    
  • 最近活动