跳到正文

个人记录

2025.07.29课堂总结

huyunshen约 4 分钟
原文
文章信息与版本

文章信息

发布
2025年7月29日
收录
2025年12月12日
更新
2026年11月15日
篇幅
约 4 分钟

版本

  1. v1当前

2025.07.29课堂总结

闲话

哎呀,差点就成神了!!!

T638298 小明搭公交

这道题就是一道简单的模拟题,上代码!:

C++
#include<bits/stdc++.h>
using namespace std;
struct S{
	int s,t;
}a[114]; 
bool cmp(S x, S y){
	return x.s < y.s;
}
int n, x, maxx;
int main(){
	cin >> n >> x;
	for(int i = 1; i <= n; i++) cin>> a[i].s >> a[i].t;
	sort(a + 1, a + n + 1, cmp);//排序
	for(int i = 1; i <= n; i++){
		if(a[i].s + a[i].t <= x) maxx = max(maxx, a[i].s);//满足条件时找最晚出发
	}
	if(maxx == 0) cout<< -1;//特判
	else cout << maxx;//输出答案
	return 0;
 } 

T638280 兜兜转转还是你

这道题挂了个黄题,有难度的,正解如下:

C++
#include<bits/stdc++.h>
using namespace std;
int n, m, si, sj, flag;
vector<vector<char> > f;
vector<vector<int> > vis;
int dir[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
void dfs(int x, int y, int step){//搜索
    for(int i = 0;i < 4; i++){
        int xx = x + dir[i][0];
        int yy = y + dir[i][1];
        
        if(xx >= 1 && xx <= n && yy >= 1 && yy <= m && !vis[xx][yy]){
            if(f[xx][yy] == 'S' && step >= 3){
                flag = 1;
                return ;
            }
            if(f[xx][yy] == '.'){
                vis[xx][yy] = 1;
                dfs(xx, yy, step + 1);
            }
        }
    }
}
int main(){
    cin >> n >> m;
    f.resize(n + 1, vector<char>(m + 1));
    vis.resize(n + 1, vector<int>(m + 1, 0));
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            cin >> f[i][j];
            if(f[i][j] == 'S'){
                si = i;
                sj = j;
            }
        }
    }
    
    for(int i = 0; i < 4;i ++){
        int xx = si + dir[i][0];
        int yy = sj + dir[i][1];
        if(xx >= 1&& xx <= n && yy >= 1&& yy <= m && f[xx][yy] == '.'){//检查连通性
            vis[xx][yy] = 1;
            dfs(xx, yy, 1);
            vis[xx][yy] = 0;
            if(flag) break;
        }
    }
    
    cout << (flag ? "Yes" : "No");//输出
    return 0;
}

好了,这次的总结就写到这了,感谢您的观看!😊😊😊

原文