bfs CE 悬一关

P1001 A+B Problem

xiayunpeng @ 2023-09-03 13:30:46

#include<bits/stdc++.h>
using namespace std;
int a[40010][40010], f[40010][40010];
int k=0,as=1000000005, sang=0;//sang是根号10^9,k用来暴力
int n,m,ans;
struct st {
    int x,y;
};
queue<st>Q;
void bfs () {
    while(!Q.empty()){
        st q=Q.front();
        if(a[q.x][q.y]==n+m){ans=a[q.x][q.y];break;}//找到了答案
        if(q.x>sang||q.y>sang){Q.pop();continue;}//判断越界
        if(f[q.x][q.y]==1){Q.pop();continue;}//剪枝
        f[q.x][q.y]=1;
        Q.push({q.x+1,q.y});
        Q.push({q.x,q.y+1});
        Q.pop();
    }
}
int main () {
    for (sang=0; sang*sang<as; sang++) {sang+=0;}
    cout << sang;
    for (int i = 0; i < sang; i++) {//<=测试平方
        for (int j = 0; j < sang; j++) {
            a[i][j]=k++;//<=录入暴力数据
        }
    }
    cin >> n >> m;
    Q.push({0,0});
    bfs();
    cout << ans << endl;
    return 0;
}

//练一下bfs
悬一关
错误-》value of 00000002fb522b90 too large for field of 4 bytes at 000000000000010

0000000 2fb522b90的值对于000000000000010处的4字节字段太大


by Argvchs @ 2023-09-03 13:32:16

@xiayunpeng 内存炸了


by Heartstrings @ 2023-09-03 13:38:35

数组开的太大了

二维数组开5000吧


by Heartstrings @ 2023-09-03 13:38:42

@xiayunpeng


by Chris_Potter @ 2023-09-03 13:56:49

数组40010也太大了吧,减数组!TLE,CE是肯定的啊


by Chris_Potter @ 2023-09-03 13:57:23

@xiayunpeng 数组40010也太大了吧,减数组!TLE,CE是肯定的啊


by xiayunpeng @ 2023-09-03 15:10:52

那怎么办呢,急!


by xiayunpeng @ 2023-09-03 15:12:24

已关注,谢谢


by 0_QAQ_0 @ 2023-09-12 19:21:10

你键盘废了吗

#include<iostream>
using namespace std;
int main()
{
    int a,b=0;
    cin>>a;
    b+=a;
    cin>>a;
    b+=a;
    cout<<b;
    return 0;
}

|