那个大好人帮我一下,全部超时。

P11228 [CSP-J 2024] 地图探险

keyifan520 @ 2024-12-08 14:15:08

#include<bits/stdc++.h>
#include<queue> 
using namespace std;
bool g[100][100];
int n, m;
struct node{
    int x, y;
};
int dx[8] ={-1,};
int dy[8] ={-1,};
void bfs(int xx, int yy){
    queue <node> q;
    q.push({xx, yy});
    while(!q.empty()){
        node f = q.front();
        q.pop();
        for(int i = 0; i < 8; i++){
            int tx = f.x+dx[i];
            int ty = f.x+dx[i];
            if(1<=tx&&tx<=n && 1<= ty&&ty<=m && g[tx][ty]){
                q.push({tx,ty});
                g[tx][ty]='*' ;
            }
        }
    }
}
int main()
{
    cin >> n >>m;
    int a, t, bi;
    for(int i = 1; i <= 100; i++){
        for(int j = 0; j < 3600; j++){
            cin >> g[i][j];
        }   
    }
    for(int i = -3600; i < 3600; i--){
        if(bi == -3600 < bi < 3600 && n == 1 < n < 16 && t == t < 100){
        } 
    }
    cin >> bi >> a >> t; 
    return 0; 
}

by lklmum @ 2024-12-08 14:17:08

多练一下


by DDD_et @ 2024-12-08 14:18:07

@keyifan520
哥们你g数组怎么开的是 bool 的啊


by Zhi_ptb @ 2024-12-08 14:18:39

@keyifan520 这题正解不是BFS吧这不是模拟题嘛?


by keyifan520 @ 2024-12-08 14:19:35

#include<bits/stdc++.h>
#include<queue> 
using namespace std;
int g[100][100];
int n, m;
struct node{
    int x, y;
};
int dx[8] ={-1,};
int dy[8] ={-1,};
void bfs(int xx, int yy){
    queue <node> q;
    q.push({xx, yy});
    while(!q.empty()){
        node f = q.front();
        q.pop();
        for(int i = 0; i < 8; i++){
            int tx = f.x+dx[i];
            int ty = f.x+dx[i];
            if(1<=tx&&tx<=n && 1<= ty&&ty<=m && g[tx][ty]){
                q.push({tx,ty});
                g[tx][ty]='*' ;
            }
        }
    }
}
int main()
{
    cin >> n >>m;
    int a, t, bi;
    for(int i = 1; i <= 100; i++){
        for(int j = 0; j < 3600; j++){
            cin >> g[i][j];
        }   
    }
    for(int i = -3600; i < 3600; i--){
        if(bi == -3600 < bi < 3600 && n == 1 < n < 16 && t == t < 100){
        } 
    }
    cin >> bi >> a >> t; 
    return 0; 
}

by DDD_et @ 2024-12-08 14:20:37

@Zhi_ptb @keyifan520

确实是模拟,用 BFS 干嘛


by keyifan520 @ 2024-12-08 14:21:41

@DDD_et那该咋作啊!


by Zhi_ptb @ 2024-12-08 14:22:15

@keyifan520 模拟K次操作,最后输出答案


by DDD_et @ 2024-12-08 14:22:42

@keyifan520

直接模拟啊,模拟还要说怎么做吗,题目不是说得很清楚了吗


by keyifan520 @ 2024-12-08 14:23:10

@Zhi_ptb发个代码


by Zhi_ptb @ 2024-12-08 14:23:24

对了,经过位置要用set去重


| 下一页