求助vscode,玄关
  • 板块灌水区
  • 楼主bijhla
  • 当前回复1
  • 已保存回复1
  • 发布时间2024/3/17 11:22
  • 上次更新2024/3/17 12:58:34
查看原帖
求助vscode,玄关
708102
bijhla楼主2024/3/17 11:22

在以下代码中(P5021),我的vscode和小熊猫跑出来的结果不同(小熊猫是对的,vscode是错的)

#include <bits/stdc++.h>
#define PII pair <int, int>
#define ll long long
#define MP make_pair
#define PB push_back
using namespace std;
constexpr int N = 5e4 + 10;
int n, m, ans, f[N], tot;
vector <PII> g[N];
void dfs (int u, int fa, int len)
{
    multiset <int> s;
    for (int i = 0; i < (int) g[u].size (); i++)
    {
        int v = g[u][i].first, w = g[u][i].second;
        if (v == fa) continue;
        dfs (v, u, len);
        if (w + f[v] >= len) tot++;
        else s.insert (w + f[v]);
    }
    while (!s.empty ())
    {
        auto it = s.begin ();
        s.erase (it);
        auto itt = s.lower_bound (len - *it);
        if (itt == s.end ()) f[u] = max (f[u], *it);
        else 
        {
            tot++;
            s.erase (itt);
        }
    }
}
inline int check (int mid)
{
    tot = 0;
    memset (f, 0, sizeof (f));
    dfs (1, 0, mid);
    if (tot >= m) return 1;
    else return 0;
}
int main()
{
    ios::sync_with_stdio (false);
    cin.tie (0);
    cout.tie (0);
    cin >> n >> m;
    for (int i = 1; i < n; i++)
    {
        int u, v, w;
        cin >> u >> v >> w;
        g[u].PB (MP (v, w));
        g[v].PB (MP (u, w));
    }
    int l = 0, r = INT_MAX - 1e5;
    while (l <= r)
    {
        int mid = (l + r) >> 1;
        if (check (mid))
        {
            l = mid + 1;
            ans = mid;
        }
        else r = mid - 1;
    }
    cout << ans;
    return 0;
}

以下是vscode的配置文件

c_cpp_properties.json

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "compilerPath": "C:/Programs/mingw64/bin/g++.exe",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "gcc-x64"
        }
    ],
    "version": 4
}

launch.json

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [

        {
            "name": "(gdb) Launch",
            "preLaunchTask": "g++.exe build active file",//调试前执行的任务,就是之前配置的tasks.json中的label字段
            "type": "cppdbg",//配置类型,只能为cppdbg
            "request": "launch",//请求配置类型,可以为launch(启动)或attach(附加)
            "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",//调试程序的路径名称
            "args": [],//调试传递参数
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,//true显示外置的控制台窗口,false显示内置终端
            "MIMode": "gdb",
            "miDebuggerPath": "C:\\Programs\\mingw64\\bin\\gdb.exe",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

setting.json

{
    "cmake.configureOnOpen": true,
    "C_Cpp.errorSquiggles": "enabled"
     // vscode不自动补全
    // "editor.suggest.snippetsPreventQuickSuggestions": false,
    // "editor.quickSuggestionsDelay": 100,
    // "editor.quickSuggestions": null,
    // "window.zoomLevel": 0,
    // "terminal.integrated.rendererType": "dom",
    // "files.associations": {
    //   "*.vue": "html"
    // }
}

tasks.json

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558 
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "label": "g++.exe build active file",//任务的名字,就是刚才在命令面板中选择的时候所看到的,可以自己设置
            "command": "C:/Programs/mingw64/bin/g++.exe",
            "args": [//编译时候的参数
                "-g",//添加gdb调试选项
                "${file}",
                "-o",//指定生成可执行文件的名称
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "C:/Programs/mingw64/bin"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true//表示快捷键Ctrl+Shift+B可以运行该任务
            }
        }
    ]
}

2024/3/17 11:22
加载中...