跳转至

线下赛环境配置

整理线下赛环境配置,虽然也就只能参加个蓝桥杯

前言

难以想象这周竟然就要参加蓝桥杯了但我现在才开始准备环境配置,啊还有好多想说的等之后再写吧,现在直接开始

希望考场的机器会有vscode,这样终端就在下面舒服一点

编译脚本

平时练习的习惯都是使用cr.ps1脚本,然后输入输出重定向

内容

param([string]$f, [string]$i)
c++ "$f.cpp" -o $f --std=c++11
if($i){
  Get-Content $i | & ./$f
}else{
  & ./$f
}
  • 第1行,param(...)参数定义,接收两个字符串,一个f,一个i,没收到就为空
  • 第2行,编译,生成$f.exe
  • 第4行,input不为空,就使用Get-Content查找到$i并打印其内容
  • &调用运算符,作用是执行脚本、可执行文件、函数,./$f是变量拼接的路径,powershell不会自动把他识别为可执行命令,所以要显示调用

配置流程

  1. 创建script文件夹,编写cr.ps1
  2. 加入环境变量
  3. 管理员运行powershell
  4. 输入Set-ExecutionPolicy RemoteSigned
  5. 即可执行cr A in

对拍

编写watool.ps1

param([string]$wa,[string]$ac,[string]$gen)
c++ "wa.cpp" -o $wa -O2 --std=c++11
c++ "ac.cpp" -o $ac -O2 --std=c++11
c++ "gen.cpp" -o $gen -O2 --std=c++11

$time = 0
while($true){
  & ./$gen > input
  Get-Content input | & ./$ac > ac.out
  Get-Content input | & ./$wa > ac.out
  $acout = Get-Content ac.out
  $waout = Get-Content wa.out
  if(Compare-Object $acout $waout){
    Get-Content input
    Write-Host "===== AC ====="
    Get-Content ac.out
    Write-Host "===== WA ====="
    Get-Content wa.out
    break
  }else{
    $time = $time + 1
    Write-Host $time
  }
}

编写 gen.cpp

#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(time(0));
int main() {
  int x = rnd() % 100 + 1; // 1~100随机数
}

调试

虽然写了,但是放弃配了,第一次写容易写错,反正蓝桥杯不看手速

debugger.h

支持打印基础类型:int, string, bool, double

vector

#include <iostream>
using namespace std;
class Debug {
 public:
  template <typename T>
  typename enable_if<is_fundamental<T>::value, void>::type output(T& v) {
    cout << v << ", ";
  }

  template <typename T>
  typename enable_if<!is_fundamental<T>::value, void>::type output(T& v, int dummy = 0) {
    cout << '[';
    for (auto& x : v) output(x);
    cout << "]\n";
  }
} dout;
#define debug(x) cout << #x << ": ", dout.output(x)

DEV c++ 配置

工具-编译选项-64bit debug-代码生成-代码生成-语言标准 选择 GNU c++11

工具-编译选项-64bit debug-代码生成-代码生成-优化级别 选择 Debug级别

工具-编译选项-64bit debug-代码生成-连接器 产生调试信息 选择Yes

代码补全 很重要

工具-快捷键选项-Show Code Completion 设为ctrl + enter

C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\9.2.0\include\c++\x86_64-w64-mingw32\bits

全部复制到文件中,代替include万能头