栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

Windows C++ 对拍

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Windows C++ 对拍

Powered by:NEFU AB-IN

文章目录
  • Windows C++ 对拍
    • 前言
    • 举例

Windows C++ 对拍
  • 前言

    在比赛时,对对拍的掌握还是比较必要的

    • 基本架构:
      std.cpp   自己写的正解(可能不对)
      bl.cpp    暴力解法(保证正确)
      mkd.cpp   生成数据的程序
      dp.bat    对拍执行的脚本
      1.txt     生成的输入
      2.txt     std的输出
      3.txt     bl的输出
      
    • 基本思路:
      先对这三个程序编译,利用mkd.cpp造的数据,分别输入进std.cpp和bl.cpp,输出的结果进行比对,如果不对就停下
  • 举例

    以判断一个数是否为质数举例

    std.cpp

    #include 
    using namespace std;
    #define int long long
    #define SZ(X) ((int)(X).size())
    #define ALL(X) (X).begin(), (X).end()
    #define IOS                                                                                                            
        ios::sync_with_stdio(false);                                                                                       
        cin.tie(0);                                                                                                        
        cout.tie(0);
    #define DEBUG(X) cout << #X << ": " << X << endl;
    typedef pair PII;
    
    const int INF = 0x3f3f3f3f;
    const int N = 1e6 + 10;
    int n;
    
    bool judge(int x)
    {
        if (x == 1)
            return false;
        for (int i = 2; i < n / i; ++i)
        {
            if (x % i == 0)
                return false;
        }
        return true;
    }
    
    signed main()
    {
        IOS;
        cin >> n;
        cout << judge(n);
        return 0;
    }
    

    bl.cpp

    #include 
    using namespace std;
    #define int long long
    #define SZ(X) ((int)(X).size())
    #define ALL(X) (X).begin(), (X).end()
    #define IOS                                                                                                            
        ios::sync_with_stdio(false);                                                                                       
        cin.tie(0);                                                                                                        
        cout.tie(0);
    #define DEBUG(X) cout << #X << ": " << X << endl;
    typedef pair PII;
    
    const int INF = 0x3f3f3f3f;
    const int N = 1e6 + 10;
    int n;
    
    bool judge(int x)
    {
        if (x == 1)
            return false;
        for (int i = 2; i < n; ++i)
        {
            if (x % i == 0)
                return false;
        }
        return true;
    }
    
    signed main()
    {
        IOS;
        cin >> n;
        cout << judge(n);
        return 0;
    }
    

    mkd.cpp

    srand(time(0)); 生成随机种子
    rand() % 10000 + 1 生成 1 到 10000的随机数
    random_shuffle(a, a + n) 对a数组随机排列

    #include 
    using namespace std;
    #define int long long
    #define SZ(X) ((int)(X).size())
    #define ALL(X) (X).begin(), (X).end()
    #define IOS                                                                                                            
        ios::sync_with_stdio(false);                                                                                       
        cin.tie(0);                                                                                                        
        cout.tie(0);
    #define DEBUG(X) cout << #X << ": " << X << endl;
    typedef pair PII;
    
    const int INF = 0x3f3f3f3f;
    const int N = 1e6 + 10;
    int n;
    
    signed main()
    {
        IOS;
        srand(time(0));
        cout << rand() % 10000 + 1;
        return 0;
    }
    

    dp.bat
    前三行时编译,后三行是循环执行
    (背过即可)

    g++ -Wall -std=c++20 std.cpp -o std
    g++ -Wall -std=c++20 bl.cpp -o bl
    g++ -Wall -std=c++20 mkd.cpp -o mkd
    
    :loop
        mkd.exe > 1.txt
        std.exe < 1.txt > 2.txt
        bl.exe < 1.txt > 3.txt
        fc 2.txt 3.txt
    
    if not errorlevel 1 goto loop
    pause
    goto loop
    

    最后运行脚本即可,结果如下

    如果遇到错,结果如下

    此时先不要动,错误的数据就在1.txt中,可以去调试;调试完了,在退出重新运行脚本即可

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/853404.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号