在桌面随便新建一个文件夹,命名为英文(我这里命名为 cpp)

点击左上角File,勾选 Auto Save
(在 vscode 设置 Auto Save开启自动保存,一定要开,不然每次写完代码都需要手动 ctrl+s保存)
打开你刚才新建的空文件夹 cpp


bat@echo off for %%i in (a b c d e f g h i j k l m) do ( mkdir "%%i" cd.>"%%i\%%i.cpp" cd.>"%%i\%%i.in" cd.>"%%i\%%i.out" cd.>"%%i\tm%%i.cpp" )
bat@echo off g++ -o main %1\%1.cpp main < %1\%1.in > %1\%1.out type %1\%1.out

在桌面右键,打开终端

切换到 cpp目录,执行 init.bat
cd cpp .\init.bat

cpp#include <bits/stdc++.h>
using namespace std;
int main()
{
string s;
cin >> s;
cout << s << endl;
return 0;
}

把输入数据放到 a.in中,就可以运行了(前提是配置了g++环境变量,赛场上的机房默认会配好,不用自己下载,如果在自己本地电脑上,就需要先下载g++并配置环境变量,如果你还没有配置,请去网上自行寻找配置方案)
.\run.bat a

.\run.bat a 表示执行run.bat 脚本,a表示参数,这条命令相当于在运行a/a.cpp文件,输入数据是a/a.in,输出数据在文件a/a.out中。
如果你想运行 b/b.cpp,只需要改成.\run.bat b (前提是已经编写好了代码和输入数据)。
但是每次运行一个文件都需要输入.\run.bat a 吗?不需要,在终端输入键盘上下左右键的上键可以弹出上一条命令,这样就不用每次都输入一遍命令了。
但是我们依然无法使用调试功能,只能自己手动打印调试了。不过这种方案相比于使用devcpp还是更方便,而且正式赛场上不一定有你想要的 ide,但是命令行编译是万能的,而且运行的效率肯定比依赖插件要快。
如果还有问题,可以私聊我:3051863421(qq)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 佛祖保佑 永无BUG */ /* // _ooOoo_ // o8888888o // 88" . "88 // (| -_- |) // O\ = /O // ____/`---'\____ // . ' \\| |// `. // / \\||| : |||// \ // / _||||| -:- |||||- \ // | | \\\ - /// | | // | \_| ''\---/'' | | // \ .-\__ `-` ___/-. / // ___`. .' /--.--\ `. . __ // ."" '< `.___\_<|>_/___.' >'"". // | | : `- \`.;`\ _ /`;.`/ - ` : | | // \ \ `-. \_ __\ /__ _/ .-` / / // ======`-.____`-.___\_____/___.-`____.-'====== // `=---=' // // ............................................. // 佛祖保佑 永无BUG // 佛曰: // 写字楼里写字间,写字间里程序员; // 程序人员写程序,又拿程序换酒钱。 // 酒醒只在网上坐,酒醉还来网下眠; // 酒醉酒醒日复日,网上网下年复年。 // 但愿老死电脑间,不愿鞠躬老板前; // 奔驰宝马贵者趣,公交自行程序员。 // 别人笑我忒疯癫,我笑自己命太贱; // 不见满街漂亮妹,哪个归得程序员?
/* _ooOoo_ o8888888o 88" . "88 (| -_- |) O\ = /O ____/`---'\____ .' \\| |// `. / \\||| : |||// \ / _||||| -:- |||||- \ | | \\\ - /// | | | \_| ''\---/'' | | \ .-\__ `-` ___/-. / ___`. .' /--.--\ `. . __ ."" '< `.___\_<|>_/___.' >'"". | | : `- \`.;`\ _ /`;.`/ - ` : | | \ \ `-. \_ __\ /__ _/ .-` / / ======`-.____`-.___\_____/___.-`____.-'====== `=---=' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 佛祖保佑 永无BUG */ /* // _ooOoo_ // o8888888o // 88" . "88 // (| -_- |) // O\ = /O // ____/`---'\____ // . ' \\| |// `. // / \\||| : |||// \ // / _||||| -:- |||||- \ // | | \\\ - /// | | // | \_| ''\---/'' | | // \ .-\__ `-` ___/-. / // ___`. .' /--.--\ `. . __ // ."" '< `.___\_<|>_/___.' >'"". // | | : `- \`.;`\ _ /`;.`/ - ` : | | // \ \ `-. \_ __\ /__ _/ .-` / / // ======`-.____`-.___\_____/___.-`____.-'====== // `=---=' // // ............................................. // 佛祖保佑 永无BUG // 佛曰: // 写字楼里写字间,写字间里程序员; // 程序人员写程序,又拿程序换酒钱。 // 酒醒只在网上坐,酒醉还来网下眠; // 酒醉酒醒日复日,网上网下年复年。 // 但愿老死电脑间,不愿鞠躬老板前; // 奔驰宝马贵者趣,公交自行程序员。 // 别人笑我忒疯癫,我笑自己命太贱; // 不见满街漂亮妹,哪个归得程序员? */ /* * _ooOoo_ * o8888888o * 88" . "88 * (| -_- |) * O\ = /O * ___/`---'\____ * . ' \\| |// `. * / \\||| : |||// \ * / _||||| -:- |||||- \ * | | \\\ - /// | | * | \_| ''\---/'' | | * \ .-\__ `-` ___/-. / * ___`. .' /--.--\ `. . __ * ."" '< `.___\_<|>_/___.' >'"". * | | : `- \`.;`\ _ /`;.`/ - ` : | | * \ \ `-. \_ __\ /__ _/ .-` / / * ======`-.____`-.___\_____/___.-`____.-'====== * `=---=' * ............................................. * 佛曰:bug泛滥,我已瘫痪! */ <!-- ´´´´´´´´██´´´´´´´ ´´´´´´´████´´´´´´ ´´´´´████████´´´´ ´´`´███▒▒▒▒███´´´´´ ´´´███▒●▒▒●▒██´´´ ´´´███▒▒▒▒▒▒██´´´´´ ´´´███▒▒▒▒██´ 项目:vue-user-center ´´██████▒▒███´´´´´ 语言: ES6-babel ´██████▒▒▒▒███´´ 框架: vue+vue-router+vuex+iview+axios ██████▒▒▒▒▒▒███´´´´ 构建工具: webpack ´´▓▓▓▓▓▓▓▓▓▓▓▓▓▒´´ 版本控制: git-github ´´▒▒▒▒▓▓▓▓▓▓▓▓▓▒´´´´´ css预处理: less ´.▒▒▒´´▓▓▓▓▓▓▓▓▒´´´´´ 代码风格:eslint-standard ´.▒▒´´´´▓▓▓▓▓▓▓▒ 编辑器: phpstorm ..▒▒.´´´´▓▓▓▓▓▓▓▒ 数据库: mysql ´▒▒▒▒▒▒▒▒▒▒▒▒ 服务器端脚本: php go ´´´´´´´´´███████´´´´´ author: codeRabbit ´´´´´´´´████████´´´´´´´ ´´´´´´´█████████´´´´´´ ´´´´´´██████████´´´´ 大部分人都在关注你飞的高不高,却没人在乎你飞的累不累,这就是现实! ´´´´´´██████████´´´ 我从不相信梦想,我,只,相,信,自,己! ´´´´´´´█████████´´ ´´´´´´´█████████´´´ ´´´´´´´´████████´´´´´ ________▒▒▒▒▒ _________▒▒▒▒ _________▒▒▒▒ ________▒▒_▒▒ _______▒▒__▒▒ _____ ▒▒___▒▒ _____▒▒___▒▒ ____▒▒____▒▒ ___▒▒_____▒▒ ███____ ▒▒ ████____███ █ _███_ _█_███ ——————————————————————————女神保佑,代码无bug—————————————————————— --> /* // .::::. // .::::::::. // ::::::::::: // ..:::::::::::' // '::::::::::::' // .:::::::::: // '::::::::::::::.. // ..::::::::::::. // ``:::::::::::::::: // ::::``:::::::::' .:::. // ::::' ':::::' .::::::::. // .::::' :::: .:::::::'::::. // .:::' ::::: .:::::::::' ':::::. // .::' :::::.:::::::::' ':::::. // .::' ::::::::::::::' ``::::. // ...::: ::::::::::::' ``::. // ````':. ':::::::::' ::::.. // '.:::::' ':'````.. */ <!-- _.._ ,------------. ,' `. (I want you! ) / __) __` \ `-,----------' ( (`-`(-') ) _.-' /) \ = / ( /' |--' . \ ( ,---| `-.)__` )( `-.,--' _`-. '/,' ( Uu", (_ , `/,-' ) `.__, : `-'/ /`--' | `--' | ` `-._ / \ ( /\ . \. / |` \ ,-\ / \| .) / \ ( ,'|\ ,' : | \,`.`--"/ } `,' \ |,' / / "-._ `-/ | "-. "-.,'| ; / _/["---'""] : / |"- ' ' | / ` | --> # # ┏┓ ┏┓ # ┏┛┻━━━┛┻┓ # ┃ ┃ # ┃ ━ ┃ # ┃ ┳┛ ┗┳ ┃ # ┃ ┃ # ┃ ┻ ┃ # ┃ ┃ # ┗━┓ ┏━┛Codes are far away from bugs with the animal protecting # ┃ ┃ 神兽保佑,代码无bug # ┃ ┃ # ┃ ┗━━━┓ # ┃ ┣┓ # ┃ ┏┛ # ┗┓┓┏━┳┓┏┛ # ┃┫┫ ┃┫┫ # ┗┻┛ ┗┻┛ # # ┏┓ ┏┓ # ┏┛┻━━━┛┻┓ # ┃ ┃ # ┃ ━ ┃ # ┃ > <┃ # ┃ ┃ # ┃ . ⌒ ..┃ # ┃ ┃ # ┗━┓ ┏━┛ # ┃ ┃ Codes are far away from bugs with the animal protecting # ┃ ┃ 神兽保佑,代码无bug # ┃ ┃ # ┃ ┃ # ┃ ┃ # ┃ ┃ # ┃ ┗━━━┓ # ┃ ┣┓ # ┃ ┏┛ # ┗┓┓┏━┳┓┏┛ # ┃┫┫ ┃┫┫ # ┗┻┛ ┗┻┛ # ┏┓ ┏┓+ + # ┏┛┻━━━┛┻┓ + + # ┃ ┃ # ┃ ━ ┃ ++ + + + # ████━████ ┃+ # ┃ ┃ + # ┃ ┻ ┃ # ┃ ┃ + + # ┗━┓ ┏━┛ # ┃ ┃ # ┃ ┃ + + + + # ┃ ┃ Codes are far away from bugs with the animal protecting # ┃ ┃ + 神兽保佑,代码无bug # ┃ ┃ # ┃ ┃ + # ┃ ┗━━━┓ + + # ┃ ┣┓ # ┃ ┏┛ # ┗┓┓┏━┳┓┏┛ + + + + # ┃┫┫ ┃┫┫ # ┗┻┛ ┗┻┛+ + + + /*code is far away from bug with the animal protecting * ┏┓ ┏┓ *┏┛┻━━━┛┻┓ *┃ ┃ *┃ ━ ┃ *┃ ┳┛ ┗┳ ┃ *┃ ┃ *┃ ┻ ┃ *┃ ┃ *┗━┓ ┏━┛ * ┃ ┃神兽保佑 * ┃ ┃代码无BUG! * ┃ ┗━━━┓ * ┃ ┣┓ * ┃ ┏┛ * ┗┓┓┏━┳┓┏┛ * ┃┫┫ ┃┫┫ * ┗┻┛ ┗┻┛ * */ # # ┌─┐ ┌─┐ # ┌──┘ ┴───────┘ ┴──┐ # │ │ # │ ─── │ # │ ─┬┘ └┬─ │ # │ │ # │ ─┴─ │ # │ │ # └───┐ ┌───┘ # │ │ # │ │ # │ │ # │ └──────────────┐ # │ │ # │ ├─┐ # │ ┌─┘ # │ │ # └─┐ ┐ ┌───────┬──┐ ┌──┘ # │ ─┤ ─┤ │ ─┤ ─┤ # └──┴──┘ └──┴──┘ # 神兽保佑 # 代码无BUG! # ___====-_ _-====___ # _--^^^#####// \\#####^^^--_ # _-^##########// ( ) \\##########^-_ # -############// |\^^/| \\############- # _/############// (@::@) \\############\_ # /#############(( \\// ))#############\ # -###############\\ (oo) //###############- # -#################\\ / VV \ //#################- # -###################\\/ \//###################- # _#/|##########/\######( /\ )######/\##########|\#_ # |/ |#/\#/\#/\/ \#/\##\ | | /##/\#/ \/\#/\#/\#| \| # ` |/ V V ` V \#\| | | |/#/ V ' V V \| ' # ` ` ` ` / | | | | \ ' ' ' ' # ( | | | | ) # __\ | | | | /__ # (vvv(VVV)(VVV)vvv) # 神兽保佑 # 代码无BUG! # __----~~~~~~~~~~~------___ # . . ~~//====...... __--~ ~~ # -. \_|// |||\\ ~~~~~~::::... /~ # ___-==_ _-~o~ \/ ||| \\ _/~~- # __---~~~.==~||\=_ -_--~/_-~|- |\\ \\ _/~ # _-~~ .=~ | \\-_ '-~7 /- / || \ / # .~ .~ | \\ -_ / /- / || \ / # / ____ / | \\ ~-_/ /|- _/ .|| \ / # |~~ ~~|--~~~~--_ \ ~==-/ | \~--===~~ .\ # ' ~-| /| |-~\~~ __--~~ # |-~~-_/ | | ~\_ _-~ /\ # / \ \__ \/~ \__ # _--~ _/ | .-~~____--~-/ ~~==. # ((->/~ '.|||' -_| ~~-/ , . _|| # -_ ~\ ~~---l__i__i__i--~~_/ # _-~-__ ~) \--______________--~~ # //.-~~~-~_--~- |-------~~~~~~~~ # //.-~~~--\ # 神兽保佑 # 代码无BUG! # ,----------------, ,---------, # ,-----------------------, ," ,"| # ," ,"| ," ," | # +-----------------------+ | ," ," | # | .-----------------. | | +---------+ | # | | | | | | -==----'| | # | | I LOVE DOS! | | | | | | # | | Bad command or | | |/----|`---= | | # | | C:\>_ | | | ,/|==== ooo | ; # | | | | | // |(((( [33]| ," # | `-----------------' |," .;'| |(((( | ," # +-----------------------+ ;; | | |," # /_)______________(_/ //' | +---------+ # ___________________________/___ `, # / oooooooooooooooo .o. oooo /, \,"----------- # / ==ooooooooooooooo==.o. ooo= // ,`\--{)B ," # /_==__==========__==_ooo__ooo=_/' /___________," # # .-~~~~~~~~~-._ _.-~~~~~~~~~-. # __.' ~. .~ `.__ # .'// \./ \\`. # .'// | \\`. # .'// .-~"""""""~~~~-._ | _,-~~~~"""""""~-. \\`. # .'//.-" `-. | .-' "-.\\`. # .'//______.============-.. \ | / ..-============.______\\`. # .'______________________________\|/______________________________`. /**********/**********/**********//**********//**********//**********//**********/ .--, .--, ( ( \.---./ ) ) '.__/o o\__.' {= ^ =} > - < / \ // \\ //| . |\\ "'\ /'"_.-~^`'-. \ _ /--' ` ___)( )(___ (((__) (__))) 高山仰止,景行行止.虽不能至,心向往之。 /**********/**********/**********//**********//**********//**********//**********/ <!-- :: :;J7, :, ::;7: ,ivYi, , ;LLLFS: :iv7Yi :7ri;j5PL ,:ivYLvr ,ivrrirrY2X, :;r@Wwz.7r: :ivu@kexianli. :iL7::,:::iiirii:ii;::::,,irvF7rvvLujL7ur ri::,:,::i:iiiiiii:i:irrv177JX7rYXqZEkvv17 ;i:, , ::::iirrririi:i:::iiir2XXvii;L8OGJr71i :,, ,,: ,::ir@mingyi.irii:i:::j1jri7ZBOS7ivv, ,::, ::rv77iiiriii:iii:i::,rvLq@huhao.Li ,, ,, ,:ir7ir::,:::i;ir:::i:i::rSGGYri712: ::: ,v7r:: ::rrv77:, ,, ,:i7rrii:::::, ir7ri7Lri , 2OBBOi,iiir;r:: ,irriiii::,, ,iv7Luur: ,, i78MBBi,:,:::,:, :7FSL: ,iriii:::i::,,:rLqXv:: : iuMMP: :,:::,:ii;2GY7OBB0viiii:i:iii:i:::iJqL;:: , ::::i ,,,,, ::LuBBu BBBBBErii:i:i:i:i:i:i:r77ii , : , ,,:::rruBZ1MBBqi, :,,,:::,::::::iiriri: , ,,,,::::i: @arqiao. ,:,, ,:::ii;i7: :, rjujLYLi ,,:::::,:::::::::,, ,:i,:,,,,,::i:iii :: BBBBBBBBB0, ,,::: , ,:::::: , ,,,, ,,::::::: i, , ,8BMMBBBBBBi ,,:,, ,,, , , , , , :,::ii::i:: : iZMOMOMBBM2::::::::::,,,, ,,,,,,:,,,::::i:irr:i:::, i ,,:;u0MBMOG1L:::i:::::: ,,,::, ,,, ::::::i:i:iirii:i:i: : ,iuUuuXUkFu7i:iii:i:::, :,:,: ::::::::i:i:::::iirr7iiri:: : :rk@Yizero.i:::::, ,:ii:::::::i:::::i::,::::iirrriiiri::, : 5BMBBBBBBSr:,::rv2kuii:::iii::,:i:,, , ,,:,:i@petermu., , :r50EZ8MBBBBGOBBBZP7::::i::,:::::,: :,:,::i;rrririiii:: :jujYY7LS0ujJL7r::,::i::,::::::::::::::iirirrrrrrr:ii: ,: :@kevensun.:,:,,,::::i:i:::::,,::::::iir;ii;7v77;ii;i, ,,, ,,:,::::::i:iiiii:i::::,, ::::iiiir@xingjief.r;7:i, , , ,,,:,,::::::::iiiiiiiiii:,:,:::::::::iiir;ri7vL77rrirri:: :,, , ::::::::i:::i:::i:i::,,,,,:,::i:i:::iir;@Secbone.ii::: -- /** * ┌───┐ ┌───┬───┬───┬───┐ ┌───┬───┬───┬───┐ ┌───┬───┬───┬───┐ ┌───┬───┬───┐ * │Esc│ │ F1│ F2│ F3│ F4│ │ F5│ F6│ F7│ F8│ │ F9│F10│F11│F12│ │P/S│S L│P/B│ ┌┐ ┌┐ ┌┐ * └───┘ └───┴───┴───┴───┘ └───┴───┴───┴───┘ └───┴───┴───┴───┘ └───┴───┴───┘ └┘ └┘ └┘ * ┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───────┐ ┌───┬───┬───┐ ┌───┬───┬───┬───┐ * │~ `│! 1│@ 2│# 3│$ 4│% 5│^ 6│& 7│* 8│( 9│) 0│_ -│+ =│ BacSp │ │Ins│Hom│PUp│ │N L│ / │ * │ - │ * ├───┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─────┤ ├───┼───┼───┤ ├───┼───┼───┼───┤ * │ Tab │ Q │ W │ E │ R │ T │ Y │ U │ I │ O │ P │{ [│} ]│ | \ │ │Del│End│PDn│ │ 7 │ 8 │ 9 │ │ * ├─────┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴─────┤ └───┴───┴───┘ ├───┼───┼───┤ + │ * │ Caps │ A │ S │ D │ F │ G │ H │ J │ K │ L │: ;│" '│ Enter │ │ 4 │ 5 │ 6 │ │ * ├──────┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴────────┤ ┌───┐ ├───┼───┼───┼───┤ * │ Shift │ Z │ X │ C │ V │ B │ N │ M │< ,│> .│? /│ Shift │ │ ↑ │ │ 1 │ 2 │ 3 │ │ * ├─────┬──┴─┬─┴──┬┴───┴───┴───┴───┴───┴──┬┴───┼───┴┬────┬────┤ ┌───┼───┼───┐ ├───┴───┼───┤ E││ * │ Ctrl│ │Alt │ Space │ Alt│ │ │Ctrl│ │ ← │ ↓ │ → │ │ 0 │ . │←─┘│ * └─────┴────┴────┴───────────────────────┴────┴────┴────┴────┘ └───┴───┴───┘ └───────┴───┴───┘ */ /** ************************************************************** * * * .=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-. * * | ______ | * * | .-" "-. | * * | / \ | * * | _ | | _ | * * | ( \ |, .-. .-. ,| / ) | * * | > "=._ | )(__/ \__)( | _.=" < | * * | (_/"=._"=._ |/ /\ \| _.="_.="\_) | * * | "=._"(_ ^^ _)"_.=" | * * | "=\__|IIIIII|__/=" | * * | _.="| \IIIIII/ |"=._ | * * | _ _.="_.="\ /"=._"=._ _ | * * | ( \_.="_.=" `--------` "=._"=._/ ) | * * | > _.=" "=._ < | * * | (_/ \_) | * * | | * * '-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=' * * * * LASCIATE OGNI SPERANZA, VOI CH'ENTRATE * ************************************************************** */ /** * 頂頂頂頂頂頂頂頂頂 頂頂頂頂頂頂頂頂頂 * 頂頂頂頂頂頂頂 頂頂 * 頂頂 頂頂頂頂頂頂頂頂頂頂頂 * 頂頂 頂頂頂頂頂頂頂頂頂頂頂 * 頂頂 頂頂 頂頂 * 頂頂 頂頂 頂頂頂 頂頂 * 頂頂 頂頂 頂頂頂 頂頂 * 頂頂 頂頂 頂頂頂 頂頂 * 頂頂 頂頂 頂頂頂 頂頂 * 頂頂 頂頂頂 * 頂頂 頂頂 頂頂 頂頂 * 頂頂頂頂 頂頂頂頂頂 頂頂頂頂頂 * 頂頂頂頂 頂頂頂頂 頂頂頂頂 */ ▄▄▄▄▄ ▀▀▀██████▄▄▄ _______________ ▄▄▄▄▄ █████████▄ / \ ▀▀▀▀█████▌ ▀▐▄ ▀▐█ | Gotta go fast! | ▀▀█████▄▄ ▀██████▄██ | _________________/ ▀▄▄▄▄▄ ▀▀█▄▀█════█▀ |/ ▀▀▀▄ ▀▀███ ▀ ▄▄ ▄███▀▀██▄████████▄ ▄▀▀▀▀▀▀█▌ ______________________________ ██▀▄▄▄██▀▄███▀ ▀▀████ ▄██ █ \\ ▄▀▀▀▄██▄▀▀▌████▒▒▒▒▒▒███ ▌▄▄▀▀▀▀█_____________________________ // ▌ ▐▀████▐███▒▒▒▒▒▐██▌ ▀▄▄▄▄▀ ▀▀████▒▒▒▒▄██▀ ▀▀█████████▀ ▄▄██▀██████▀█ ▄██▀ ▀▀▀ █ ▄█ ▐▌ ▄▄▄▄█▌ ▀█▄▄▄▄▀▀▄ ▌ ▐ ▀▀▄▄▄▀ ▀▀▄▄▀ ██ \ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀ \- ▌ SanicCRUD-vue ▀ ▀ - ▌ (o) ▀ /- ▌ Go Go Go ! ▀ ▀ / ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀ ██ # d*##$. # zP"""""$e. $" $o #4$ '$ $" $ #'$ '$ J$ $F # 'b $k $> $ # $k $r J$ d$ # '$ $ $" $~ # '$ "$ '$E $ # $ $L $" $F ... # $. 4B $ $$$*"""*b # '$ $. $$ $$ $F # "$ R$ $F $" $ # $k ?$ u* dF .$ # ^$. $$" z$ u$$$$e # #$b $E.dW@e$" ?$ # #$ .o$$# d$$$$c ?F # $ .d$$#" . zo$> #$r .uF # $L .u$*" $&$$$k .$$d$$F # $$" ""^"$$$P"$P9$ # JP .o$$$$u:$P $$ # $ ..ue$" "" $" # d$ $F $ # $$ ....udE 4B # #$ """"` $r @$ # ^$L '$ $F # RN 4N $ # *$b d$ # $$k $F # $$b $F # $"" $F # '$ $ # $L $ # '$ $ # $ $ # ......................................&&......................... ....................................&&&.......................... .................................&&&&............................ ...............................&&&&.............................. .............................&&&&&&.............................. ...........................&&&&&&....&&&..&&&&&&&&&&&&&&&........ ..................&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&.............. ................&...&&&&&&&&&&&&&&&&&&&&&&&&&&&&................. .......................&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&......... ...................&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&............... ..................&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&............ ...............&&&&&@ &&&&&&&&&&..&&&&&&&&&&&&&&&&&&&........... ..............&&&&&&&&&&&&&&&.&&....&&&&&&&&&&&&&..&&&&&......... ..........&&&&&&&&&&&&&&&&&&...&.....&&&&&&&&&&&&&...&&&&........ ........&&&&&&&&&&&&&&&&&&&.........&&&&&&&&&&&&&&&....&&&....... .......&&&&&&&&.....................&&&&&&&&&&&&&&&&.....&&...... ........&&&&&.....................&&&&&&&&&&&&&&&&&&............. ..........&...................&&&&&&&&&&&&&&&&&&&&&&&............ ................&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&............ ..................&&&&&&&&&&&&&&&&&&&&&&&&&&&&..&&&&&............ ..............&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&....&&&&&............ ...........&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&......&&&&............ .........&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&.........&&&&............ .......&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&...........&&&&............ ......&&&&&&&&&&&&&&&&&&&...&&&&&&...............&&&............. .....&&&&&&&&&&&&&&&&............................&&.............. ....&&&&&&&&&&&&&&&.................&&........................... ...&&&&&&&&&&&&&&&.....................&&&&...................... ...&&&&&&&&&&.&&&........................&&&&&................... ..&&&&&&&&&&&..&&..........................&&&&&&&............... ..&&&&&&&&&&&&...&............&&&.....&&&&...&&&&&&&............. ..&&&&&&&&&&&&&.................&&&.....&&&&&&&&&&&&&&........... ..&&&&&&&&&&&&&&&&..............&&&&&&&&&&&&&&&&&&&&&&&&......... ..&&.&&&&&&&&&&&&&&&&&.........&&&&&&&&&&&&&&&&&&&&&&&&&&&....... ...&&..&&&&&&&&&&&&.........&&&&&&&&&&&&&&&&...&&&&&&&&&&&&...... ....&..&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&...........&&&&&&&&..... .......&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&..............&&&&&&&.... .......&&&&&.&&&&&&&&&&&&&&&&&&..&&&&&&&&...&..........&&&&&&.... ........&&&.....&&&&&&&&&&&&&.....&&&&&&&&&&...........&..&&&&... .......&&&........&&&.&&&&&&&&&.....&&&&&.................&&&&... .......&&&...............&&&&&&&.......&&&&&&&&............&&&... ........&&...................&&&&&&.........................&&&.. .........&.....................&&&&........................&&.... ...............................&&&.......................&&...... ................................&&......................&&....... .................................&&.............................. ..................................&..............................
cpp#include <bits/stdc++.h>
using namespace std;
// #define int long long
const int M=5e5+5;
vector<int>f[M];
int dep[M],son[M],fa[M],sz[M],top[M];
void dfs1(int now,int t) {
dep[now]=dep[t]+1;
sz[now]=1;
fa[now]=t;
for(auto x:f[now]) {
if(x==t)continue;
dfs1(x,now);
sz[now]+=sz[x];
if(sz[x]>sz[son[now]]) son[now]=x;
}
}
void dfs2(int now,int t) {
top[now]=t;
if(son[now])dfs2(son[now],t);
for(auto x:f[now]) {
if(x==son[now]||x==fa[now])continue;
dfs2(x,x);
}
}
int lca(int x,int y) {
while(top[x]!=top[y]) {
if(dep[top[x]]<dep[top[y]])swap(x,y);
x=fa[top[x]];
}
return dep[x]<dep[y]?x:y;
}
void solve() {
int n,m,s;
cin>>n>>m>>s;
for(int i=1;i<n;++i) {
int x,y;
cin>>x>>y;
f[x].push_back(y);
f[y].push_back(x);
}
dfs1(s,s);
dfs2(s,s);
while (m--) {
int x,y;
cin>>x>>y;
cout<<lca(x,y)<<"\n";
}
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL),cout.tie(NULL);
solve();
return 0;
}
cpp#include <bits/stdc++.h>
using namespace std;
// #define int long long
const int M = 1e6 + 5;
int fa[M][22], dep[M];
vector<int> f[M];
inline void dfs(int x, int t)
{
fa[x][0] = t;
dep[x] = dep[t] + 1;
for (auto to : f[x])
if (to != t)
dfs(to, x);
} // 求 fa[i][0]
inline int lca(int x, int y)
{
if (dep[x] < dep[y])
swap(x, y);
for (int i = 20; i >= 0; i--)
{
if (dep[fa[x][i]] >= dep[y])
x = fa[x][i];
}
if (x == y)
return x;
for (int i = 20; i >= 0; i--)
{
if (fa[x][i] != fa[y][i])
{
x = fa[x][i];
y = fa[y][i];
}
}
return fa[x][0];
} // 求两个节点的 LCA
void solve()
{
int n, m, s;
cin >> n >> m >> s;
for (int i = 1; i < n; ++i)
{
int x, y;
cin >> x >> y;
f[x].push_back(y);
f[y].push_back(x);
}
dfs(s, 0);
for (int j = 1; (1 << j) <= n; ++j)
for (int i = 1; i <= n; ++i)
fa[i][j] = fa[fa[i][j - 1]][j - 1];
for (int i = 1; i <= m; ++i)
{
int x, y;
cin >> x >> y;
cout << lca(x, y) << "\n";
}
}
int main()
{
ios ::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t = 1;
// cin>>t;
while (t--)
solve();
return 0;
}
服务器操作系统:ubuntu22.04(建议和我使用一样的)
先执行sudo apt update 更新
shsudo apt install -y docker-compose
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": [
"https://98t8vkfg.mirror.aliyuncs.com",
"https://2a6bf1988cb6428c877f723ec7530dbc.mirror.swr.myhuaweicloud.com",
"https://docker.m.daocloud.io",
"https://hub-mirror.c.163.com",
"https://mirror.baidubce.com",
"https://your_preferred_mirror",
"https://dockerhub.icu",
"https://docker.registry.cyou",
"https://docker-cf.registry.cyou",
"https://dockercf.jsdelivr.fyi",
"https://docker.jsdelivr.fyi",
"https://dockertest.jsdelivr.fyi",
"https://mirror.aliyuncs.com",
"https://dockerproxy.com",
"https://mirror.baidubce.com",
"https://docker.m.daocloud.io",
"https://docker.nju.edu.cn",
"https://docker.mirrors.sjtug.sjtu.edu.cn",
"https://docker.mirrors.ustc.edu.cn",
"https://mirror.iscas.ac.cn",
"https://docker.rainbond.cc",
"https://docker.registry.cyou",
"https://docker-cf.registry.cyou",
"https://dockercf.jsdelivr.fyi",
"https://docker.jsdelivr.fyi",
"https://dockertest.jsdelivr.fyi",
"https://mirror.aliyuncs.com",
"https://dockerproxy.com",
"https://mirror.baidubce.com",
"https://docker.m.daocloud.io",
"https://docker.nju.edu.cn",
"https://docker.mirrors.sjtug.sjtu.edu.cn",
"https://docker.mirrors.ustc.edu.cn",
"https://mirror.iscas.ac.cn",
"https://docker.rainbond.cc"
]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
在项目启动之前,还需要修改一个配置文件。
shsudo vim /etc/default/grub
找到 GRUB_CMDLINE_LINUX_DEFAULT 换成:
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash systemd.unified_cgroup_hierarchy=0 cgroup_enable=memory swapaccount=1"
然后保存,重启
shsudo update-grub sudo reboot
当前在 dom 目录下
输入自己的密码
MYSQL_ROOT_PASSWORD=@xxx114514 MYSQL_PASSWORD=xxx114514
JUDGEDAEMON_PASSWORD=xxx114514
ymlversion: "3.9"
services:
dj-mariadb:
container_name: dj-mariadb
image: mariadb:10.5
restart: unless-stopped
ports:
- "13306:3306"
volumes:
- ./database:/var/lib/mysql
env_file: database.secret
environment:
- MYSQL_USER=domjudge
- MYSQL_DATABASE=domjudge
- CONTAINER_TIMEZONE=Asia/Shanghai
command: --max-connections=1024 --max-allowed-packet=1G --innodb-log-file-size=512M
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "root", "--password=$$MYSQL_ROOT_PASSWORD"]
start_period: 30s
interval: 10s
timeout: 5s
retries: 10
domserver:
container_name: domserver
image: domjudge/domserver:8.3.1
restart: unless-stopped
ports:
- "80:80"
depends_on:
dj-mariadb:
condition: service_healthy
env_file: database.secret
environment:
- MYSQL_HOST=dj-mariadb
- MYSQL_USER=domjudge
- MYSQL_DATABASE=domjudge
- CONTAINER_TIMEZONE=Asia/Shanghai
volumes:
- ./backups:/opt/domjudge/domserver/backups
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost/"]
interval: 30s
timeout: 10s
retries: 3
judgehost:
image: domjudge/judgehost:8.3.1
restart: unless-stopped
depends_on:
domserver:
condition: service_healthy
privileged: true
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
env_file: judgehost.secret
environment:
- DAEMON_ID=1
- CONTAINER_TIMEZONE=Asia/Shanghai
deploy:
replicas: 5 #评测机数量
bashdocker-compose up -d dj-mariadb
bash# 检查数据库健康状态
until docker-compose exec dj-mariadb mysqladmin ping -u root -p$(grep MYSQL_ROOT_PASSWORD database.secret | cut -d= -f2) --silent; do
echo "等待数据库启动..."
sleep 10
done
echo "数据库已就绪!"
bashdocker-compose up -d domserver
sh# 在 dom 目录下执行
# 创建必要的目录
mkdir -p database backups domserver_data/{public/images,public/flags,var}
# 从运行的容器中复制默认数据到宿主机
echo "正在复制 DOMServer 默认数据到宿主机..."
# 复制图片和标志文件
docker cp domserver:/opt/domjudge/domserver/webapp/public/images/. domserver_data/public/images/
docker cp domserver:/opt/domjudge/domserver/webapp/public/flags/. domserver_data/public/flags/
# 复制变量数据
docker cp domserver:/opt/domjudge/domserver/webapp/var/. domserver_data/var/
# 验证数据复制成功
echo "验证复制的数据:"
ls -la domserver_data/public/images/
ls -la domserver_data/public/flags/
echo "数据复制完成!"
ymlversion: "3.9"
services:
dj-mariadb:
container_name: dj-mariadb
image: mariadb:10.5
restart: unless-stopped
ports:
- "13306:3306"
volumes:
- ./database:/var/lib/mysql
env_file: database.secret
environment:
- MYSQL_USER=domjudge
- MYSQL_DATABASE=domjudge
- CONTAINER_TIMEZONE=Asia/Shanghai
command: --max-connections=1024 --max-allowed-packet=1G --innodb-log-file-size=512M
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "root", "--password=$$MYSQL_ROOT_PASSWORD"]
start_period: 30s
interval: 10s
timeout: 5s
retries: 10
domserver:
container_name: domserver
image: domjudge/domserver:8.3.1
restart: unless-stopped
ports:
- "80:80"
depends_on:
dj-mariadb:
condition: service_healthy
env_file: database.secret
environment:
- MYSQL_HOST=dj-mariadb
- MYSQL_USER=domjudge
- MYSQL_DATABASE=domjudge
- CONTAINER_TIMEZONE=Asia/Shanghai
volumes:
- ./backups:/opt/domjudge/domserver/backups
- ./domserver_data/public/images:/opt/domjudge/domserver/webapp/public/images
- ./domserver_data/public/flags:/opt/domjudge/domserver/webapp/public/flags
- ./domserver_data/var:/opt/domjudge/domserver/webapp/var
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost/"]
interval: 30s
timeout: 10s
retries: 3
judgehost:
image: domjudge/judgehost:8.3.1
restart: unless-stopped
depends_on:
domserver:
condition: service_healthy
privileged: true
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
env_file: judgehost.secret
environment:
- DAEMON_ID=1
- CONTAINER_TIMEZONE=Asia/Shanghai
deploy:
replicas: 5
bash# 获取自动生成的 judgehost 密码
echo "JUDGEDAEMON_PASSWORD=$(docker-compose exec domserver cat /opt/domjudge/domserver/etc/restapi.secret | awk 'END{print $4}')" > judgehost.secret
bash
# 获取管理员 admin 密码,用于登录 web 页面
docker exec -it domserver cat /opt/domjudge/domserver/etc/initial_admin_password.secret
# 可选:将管理员密码保存到文件
echo "$(docker exec -it domserver cat /opt/domjudge/domserver/etc/initial_admin_password.secret)" > adm-psd.txt

bashdocker-compose down docker-compose up -d
然后打开网页登录,账号是 admin

bash
echo "password=$(docker exec -it domserver cat /opt/domjudge/domserver/etc/initial_admin_password.secret)" > adm-psd.txt