跳到正文

个人记录

7.29

LLC6858约 5 分钟
原文
文章信息与版本

文章信息

发布
2025年7月30日
收录
2025年12月12日
更新
2026年11月16日
篇幅
约 5 分钟

版本

  1. v1当前

T638908 宾果

错误代码

输出-1骗分,赛时原代码错在标记不了a在原数组中的位置

C++
#include<bits/stdc++.h>
using namespace std;
int n,t;
int a,sum;
int vis[2005][2005];

int main(){
	cin >> n >> t;
	
	for(int i = 1;i <= t;i++){
		cin >> a;
	

		//cout << x << ' ' << y << '\n';
	}

	cout << -1;
	return 0;
}

正确代码

分析:找到x在原数组中对应的位置,如果位于主对角线、副对角线则让对应标记用的变量++,让行列的标记数组++

C++
#include<bits/stdc++.h>
using namespace std;
int n,t;
int a,sum;
int vis[2005][2005];
int hang[200005],lie[200005],zdj,fdj;
int main(){
	cin >> n >> t;
	bool f = 0;
	int x;
	for(int i = 1;i <= t;i++){
		cin >> x;
		int r = (x - 1) / n + 1;//找到输入的数在原数组中的位置 
		int c = (x - 1) % n + 1; 
		hang[r]++,lie[c]++;//使用行、列、对角线的标记数组 
		if(r == c) zdj++;//主对角 
		if(r + c == n + 1) fdj++;//副对角 
		if(zdj == n or fdj == n or hang[r] == n or lie[c] == n){//如果达到“宾果”
			cout << i;
			return 0;
		} 
	}

	cout << -1;
	return 0;
}

T638280 兜兜转转还是你

错误代码:时间不够直接骗的

C++
#include<bits/stdc++.h>
using namespace std;
char a[1005][1005];
int n,w;
int main(){
	cin>>n>>w;
	for(int i = 1;i <= n;i++){
		for(int j = 1;j <= w;j++){
			cin >> a[i][j];
		}
	}
	cout << "Yes";
	return 0;
}

分析:

C++
#include<bits/stdc++.h>
using namespace std;
int n, m, si, sj, flag;
vector<vector<char> > f;//二维数组行或列都可能超过1e4就要用二维动态数组
vector<vector<int> > vis;
int dx[4] = {-1,1,0,0};
int dy[4] = {0,0,-1,1};
void dfs(int x, int y, int step){
    for(int i = 0;i < 4; i++){
        int xx = x + dx[i];
        int yy = y + dy[i];
        
        if(xx >= 1 && xx <= n && yy >= 1 && yy <= m && !vis[xx][yy]){
            if(f[xx][yy] == 'S' && step >= 3){//在搜索开始时已经动了一步,所以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 ++){//进行4次深搜,相当于围绕起点绕一圈,从起点相邻的任意一个点能搜索到其他三个相邻的点
        int xx = si + dx[i];
        int yy = sj + dy[i];
        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;
        }
    }
    
    if(flag == 1){
    	cout << "Yes";
	}else cout << "No";
    return 0;
}
原文