鱼C论坛

 找回密码
 立即注册
查看: 305|回复: 3

为什么说我编译失败啊

[复制链接]
发表于 2024-2-18 21:12:46 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
#include <iostream>
#include <cstring>
using namespace std;
int n,m,h;
int startx,starty,endx,endy;
int a[100010][100010];
int vis[100010][100010];
int xx[4] = {1,0,-1,0};
int yy[4] = {0,1,0,-1};
bool yes = false;
void dfs(int x,int y,int xue)
{
    if(xue>=h or yes)
    {
        return;
    }
    else if(x==endx and y==endy)
    {
        cout << "Yes" << '\n';
        yes = true;
        return;
    }
    vis[x][y] = 1;
    for(int i = 0;i<4;i++)
    {
        int newx = x+xx[i];
        int newy = y+yy[i];
        if(newx>=1 and newx<=n and newy>=1 and newy<=m and  vis[newx][newy]==0)
        {
            dfs(newx,newy,xue+a[newx][newy]);
        }
    }
}
int main()
{
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(0);
    int q;
    cin >> q;
    while(q--)
    {
        memset(vis,0,sizeof(vis));
        yes = false;
        cin >> n >> m >> h;
        for(int i = 1;i<=n;i++)
        {
            for(int j = 1;j<=m;j++)
            {
                char s;
                cin >> s;
                if(s=='S')
                {
                    startx = i;
                    starty = j;
                }
                else if(s=='T')
                {
                    endx = i;
                    endy = j;
                }
                else
                {
                    a[i][j] = s-'0';
                }
            }
        }
        dfs(startx,starty,0);
        if(not yes)
        {
            cout << "No" << "\n";
        }
    }
    return 0;
}
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2024-2-18 21:13:09 | 显示全部楼层
你的代码出现了一些问题,导致编译失败。让我来帮你修复一下。

首先,你需要包含`iostream`头文件,这样才能使用输入输出流。然后,在代码中有几个地方需要做一些修改。

1. 数组`xx`和`yy`的声明方式不正确。你可以将它们声明为`int xx[] = {1,0,-1,0};`和`int yy[] = {0,1,0,-1};`。

2. 在`cout << n >> m >> h;`这一行,你需要将左移运算符`<<`改为右移运算符`>>`,这样才能正确读取`n`、`m`和`h`的值。即`cout >> n >> m >> h;`改为`cin >> n >> m >> h;`。

3. 在最后一行的`cout`语句中,`not`是Python中的关键字,而在C++中使用`!`来表示否定。所以将`not yes`改为`!yes`。

修复完这些问题后,你的代码应该可以顺利编译了。如果还有其他问题,请随时告诉我。

以上回复来自 FishC AI 小助理,如未能正确解答您的问题,请继续追问。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2024-2-21 16:03:41 | 显示全部楼层
检查有没有缺头文件神马的
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2024-2-22 10:23:46 | 显示全部楼层
问题:尺度过大
试一下我修改后的吧
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4. int n,m,h;
  5. int startx,starty,endx,endy;
  6. int a[10001][10001];
  7. int vis[10001][10001];
  8. int xx[4] = {1,0,-1,0};
  9. int yy[4] = {0,1,0,-1};
  10. bool yes = false;
  11. void dfs(int x,int y,int xue)
  12. {
  13.     if(xue>=h or yes)
  14.     {
  15.         return;
  16.     }
  17.     else if(x==endx and y==endy)
  18.     {
  19.         cout << "Yes" << '\n';
  20.         yes = true;
  21.         return;
  22.     }
  23.     vis[x][y] = 1;
  24.     for(int i = 0;i<4;i++)
  25.     {
  26.         int newx = x+xx[i];
  27.         int newy = y+yy[i];
  28.         if(newx>=1 and newx<=n and newy>=1 and newy<=m and  vis[newx][newy]==0)
  29.         {
  30.             dfs(newx,newy,xue+a[newx][newy]);
  31.         }
  32.     }
  33. }
  34. int main()
  35. {
  36.     cin.tie(0);
  37.     cout.tie(0);
  38.     ios::sync_with_stdio(0);
  39.     int q;
  40.     cin >> q;
  41.     while(q--)
  42.     {
  43.         memset(vis,0,sizeof(vis));
  44.         yes = false;
  45.         cin >> n >> m >> h;
  46.         for(int i = 1;i<=n;i++)
  47.         {
  48.             for(int j = 1;j<=m;j++)
  49.             {
  50.                 char s;
  51.                 cin >> s;
  52.                 if(s=='S')
  53.                 {
  54.                     startx = i;
  55.                     starty = j;
  56.                 }
  57.                 else if(s=='T')
  58.                 {
  59.                     endx = i;
  60.                     endy = j;
  61.                 }
  62.                 else
  63.                 {
  64.                     a[i][j] = s-'0';
  65.                 }
  66.             }
  67.         }
  68.         dfs(startx,starty,0);
  69.         if(not yes)
  70.         {
  71.             cout << "No" << "\n";
  72.         }
  73.     }
  74.     return 0;
  75. }
复制代码


给个最佳答案吧,求求了
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-4-28 05:11

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表