This commit is contained in:
HuangHai
2025-08-30 18:35:01 +08:00
commit 1f397eca87
6258 changed files with 1487241 additions and 0 deletions

View File

@@ -0,0 +1,213 @@
# 语言: None, Cpp, Java, JavaScript, ObjC, Proto, TableGen, TextProto
Language: Cpp
BasedOnStyle: LLVM
# 访问说明符(public、private等)的偏移
AccessModifierOffset: -4
# 开括号(开圆括号、开尖括号、开方括号)后的对齐: Align, DontAlign, AlwaysBreak(总是在开括号后换行)
AlignAfterOpenBracket: Align
# 连续赋值时,对齐所有等号
AlignConsecutiveAssignments: false
# 连续声明时,对齐所有声明的变量名
AlignConsecutiveDeclarations: false
# 右对齐逃脱换行(使用反斜杠换行)的反斜杠
AlignEscapedNewlines: Right
# 水平对齐二元和三元表达式的操作数
AlignOperands: true
# 对齐连续的尾随的注释
AlignTrailingComments: true
# 不允许函数声明的所有参数在放在下一行
AllowAllParametersOfDeclarationOnNextLine: false
# 不允许短的块放在同一行
AllowShortBlocksOnASingleLine: true
# 允许短的case标签放在同一行
AllowShortCaseLabelsOnASingleLine: true
# 允许短的函数放在同一行: None, InlineOnly(定义在类中), Empty(空函数), Inline(定义在类中,空函数), All
AllowShortFunctionsOnASingleLine: None
# 允许短的if语句保持在同一行
AllowShortIfStatementsOnASingleLine: true
# 允许短的循环保持在同一行
AllowShortLoopsOnASingleLine: true
# 总是在返回类型后换行: None, All, TopLevel(顶级函数,不包括在类中的函数),
# AllDefinitions(所有的定义,不包括声明), TopLevelDefinitions(所有的顶级函数的定义)
AlwaysBreakAfterReturnType: None
# 总是在多行string字面量前换行
AlwaysBreakBeforeMultilineStrings: false
# 总是在template声明后换行
AlwaysBreakTemplateDeclarations: true
# false表示函数实参要么都在同一行,要么都各自一行
BinPackArguments: true
# false表示所有形参要么都在同一行,要么都各自一行
BinPackParameters: true
# 大括号换行,只有当BreakBeforeBraces设置为Custom时才有效
BraceWrapping:
# class定义后面
AfterClass: false
# 控制语句后面
AfterControlStatement: false
# enum定义后面
AfterEnum: false
# 函数定义后面
AfterFunction: false
# 命名空间定义后面
AfterNamespace: false
# struct定义后面
AfterStruct: false
# union定义后面
AfterUnion: false
# extern之后
AfterExternBlock: false
# catch之前
BeforeCatch: false
# else之前
BeforeElse: false
# 缩进大括号
IndentBraces: false
# 分离空函数
SplitEmptyFunction: false
# 分离空语句
SplitEmptyRecord: false
# 分离空命名空间
SplitEmptyNamespace: false
# 在二元运算符前换行: None(在操作符后换行), NonAssignment(在非赋值的操作符前换行), All(在操作符前换行)
BreakBeforeBinaryOperators: NonAssignment
# 在大括号前换行: Attach(始终将大括号附加到周围的上下文), Linux(除函数、命名空间和类定义,与Attach类似),
# Mozilla(除枚举、函数、记录定义,与Attach类似), Stroustrup(除函数定义、catch、else,与Attach类似),
# Allman(总是在大括号前换行), GNU(总是在大括号前换行,并对于控制语句的大括号增加额外的缩进), WebKit(在函数前换行), Custom
# 注:这里认为语句块也属于函数
BreakBeforeBraces: Custom
# 在三元运算符前换行
BreakBeforeTernaryOperators: false
# 在构造函数的初始化列表的冒号后换行
BreakConstructorInitializers: AfterColon
#BreakInheritanceList: AfterColon
BreakStringLiterals: false
# 每行字符的限制,0表示没有限制
ColumnLimit: 0
CompactNamespaces: true
# 构造函数的初始化列表要么都在同一行,要么都各自一行
ConstructorInitializerAllOnOneLineOrOnePerLine: false
# 构造函数的初始化列表的缩进宽度
ConstructorInitializerIndentWidth: 4
# 延续的行的缩进宽度
ContinuationIndentWidth: 4
# 去除C++11的列表初始化的大括号{后和}前的空格
Cpp11BracedListStyle: true
# 继承最常用的指针和引用的对齐方式
DerivePointerAlignment: false
# 固定命名空间注释
FixNamespaceComments: true
# 缩进case标签
IndentCaseLabels: false
IndentPPDirectives: None
# 缩进宽度
IndentWidth: 4
# 函数返回类型换行时,缩进函数声明或函数定义的函数名
IndentWrappedFunctionNames: false
# 保留在块开始处的空行
KeepEmptyLinesAtTheStartOfBlocks: false
# 连续空行的最大数量
MaxEmptyLinesToKeep: 1
# 命名空间的缩进: None, Inner(缩进嵌套的命名空间中的内容), All
NamespaceIndentation: None
# 指针和引用的对齐: Left, Right, Middle
PointerAlignment: Right
# 允许重新排版注释
ReflowComments: true
# 允许排序#include
SortIncludes: false
# 允许排序 using 声明
SortUsingDeclarations: false
# 在C风格类型转换后添加空格
SpaceAfterCStyleCast: false
# 在Template 关键字后面添加空格
SpaceAfterTemplateKeyword: true
# 在赋值运算符之前添加空格
SpaceBeforeAssignmentOperators: true
# SpaceBeforeCpp11BracedList: true
# SpaceBeforeCtorInitializerColon: true
# SpaceBeforeInheritanceColon: true
# 开圆括号之前添加一个空格: Never, ControlStatements, Always
SpaceBeforeParens: ControlStatements
# SpaceBeforeRangeBasedForLoopColon: true
# 在空的圆括号中添加空格
SpaceInEmptyParentheses: false
# 在尾随的评论前添加的空格数(只适用于//)
SpacesBeforeTrailingComments: 1
# 在尖括号的<后和>前添加空格
SpacesInAngles: false
# 在C风格类型转换的括号中添加空格
SpacesInCStyleCastParentheses: false
# 在容器(ObjC和JavaScript的数组和字典等)字面量中添加空格
SpacesInContainerLiterals: true
# 在圆括号的(后和)前添加空格
SpacesInParentheses: false
# 在方括号的[后和]前添加空格,lamda表达式和未指明大小的数组的声明不受影响
SpacesInSquareBrackets: false
# 标准: Cpp03, Cpp11, Auto
Standard: Cpp11
# tab宽度
TabWidth: 4
# 使用tab字符: Never, ForIndentation, ForContinuationAndIndentation, Always
UseTab: Never

View File

@@ -0,0 +1,25 @@
{
"configurations": [
{
"name": "Win32",
"compilerArgs": [
"-fexec-charset=GBK"
],
"includePath": [
"${workspaceFolder}/**",
"C:/TDM-GCC-64/lib/gcc/x86_64-w64-mingw32/10.3.0/**",
"C:/TDM-GCC-64/x86_64-w64-mingw32/include/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "C:/TDM-GCC-64/bin/gcc.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-x64"
}
],
"version": 4
}

View File

@@ -0,0 +1,5 @@
{
"recommendations": [
"MS-CEINTL.vscode-language-pack-zh-hans"
]
}

View File

@@ -0,0 +1,28 @@
// https://github.com/Microsoft/vscode-cpptools/blob/master/launch.md
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch", // 配置名称,将会在启动配置的下拉菜单中显示
"type": "cppdbg", // 配置类型,cppdbg对应cpptools提供的调试功能;可以认为此处只能是cppdbg
"request": "launch", // 请求配置类型,可以为launch(启动)或attach(附加)
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe", // 将要进行调试的程序的路径
"args": [], // 程序调试时传递给程序的命令行参数,一般设为空即可
"stopAtEntry": false, // 设为true时程序将暂停在程序入口处,相当于在main上打断点
"externalConsole": false,
"cwd": "${fileDirname}\\", // 调试程序时的工作目录,此为工作区文件夹;改成${fileDirname}可变为文件所在目录
"environment": [], // 环境变量
"internalConsoleOptions": "neverOpen", // 如果不设为neverOpen,调试时会跳到“调试控制台”选项卡,你应该不需要对gdb手动输命令吧?
"MIMode": "gdb", // 指定连接的调试器,可以为gdb或lldb。但我没试过lldb
"miDebuggerPath": "gdb.exe", // 调试器路径,Windows下后缀不能省略,Linux下则不要
"setupCommands": [
{ // 模板自带,好像可以更好地显示STL容器的内容,具体作用自行Google
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": false
}
],
"preLaunchTask": "Compile" // 调试会话开始前执行的任务,一般为编译程序。与tasks.json的label相对应
}
]
}

View File

@@ -0,0 +1,112 @@
{
"files.defaultLanguage": "c", // ctrl+N新建文件后默认的语言
"editor.formatOnType": true, // 输入分号(C/C++的语句结束标识)后自动格式化当前这一行的代码
"editor.suggest.snippetsPreventQuickSuggestions": false, // clangd的snippets有很多的跳转点,不用这个就必须手动触发Intellisense了
"editor.acceptSuggestionOnEnter": "off", // 我个人的习惯,按回车时一定是真正的换行,只有tab才会接受Intellisense
"code-runner.runInTerminal": true, // 设置成false会在“输出”中输出,无法输入
"code-runner.saveFileBeforeRun": true, // run code前保存
"code-runner.preserveFocus": true, // 若为false,run code后光标会聚焦到终端上。如果需要频繁输入数据可设为false
"code-runner.clearPreviousOutput": false, // 每次run code前清空属于code runner的终端消息,默认false
"code-runner.ignoreSelection": true, // 默认为false,效果是鼠标选中一块代码后可以单独执行,但C是编译型语言,不适合这样用
"C_Cpp.clang_format_sortIncludes": true,
"files.associations": {
"array": "cpp",
"atomic": "cpp",
"*.tcc": "cpp",
"cctype": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"unordered_map": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"optional": "cpp",
"string": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"fstream": "cpp",
"initializer_list": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"limits": "cpp",
"new": "cpp",
"ostream": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"typeinfo": "cpp",
"valarray": "cpp",
"cassert": "cpp",
"cerrno": "cpp",
"cfloat": "cpp",
"chrono": "cpp",
"ciso646": "cpp",
"climits": "cpp",
"complex": "cpp",
"csetjmp": "cpp",
"csignal": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cuchar": "cpp",
"numeric": "cpp",
"ratio": "cpp",
"version": "cpp",
"bitset": "cpp",
"regex": "cpp",
"random": "cpp",
"unordered_set": "cpp",
"list": "cpp",
"any": "cpp",
"functional": "cpp",
"mutex": "cpp",
"shared_mutex": "cpp",
"thread": "cpp",
"variant": "cpp",
"map": "cpp",
"scoped_allocator": "cpp",
"future": "cpp",
"iomanip": "cpp",
"forward_list": "cpp",
"bit": "cpp",
"ccomplex": "cpp",
"cfenv": "cpp",
"charconv": "cpp",
"cinttypes": "cpp",
"codecvt": "cpp",
"condition_variable": "cpp",
"cstdalign": "cpp",
"cstdbool": "cpp",
"ctgmath": "cpp",
"set": "cpp",
"iterator": "cpp",
"filesystem": "cpp",
"ios": "cpp",
"locale": "cpp",
"queue": "cpp",
"stack": "cpp",
"typeindex": "cpp",
"compare": "cpp",
"concepts": "cpp",
"coroutine": "cpp",
"numbers": "cpp",
"ranges": "cpp",
"span": "cpp",
"stop_token": "cpp"
}, // 格式化时调整include的顺序(按字母排序)
}

View File

@@ -0,0 +1,40 @@
// https://code.visualstudio.com/docs/editor/tasks
{
"version": "2.0.0",
"tasks": [
{
"label": "Compile", // 任务名称,与launch.json的preLaunchTask相对应
"command": "g++", // 要使用的编译器,C++用g++
"args": [
"${file}",
"-o", // 指定输出文件名,不加该参数则默认输出a.exe,Linux下默认a.out
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"-g", // 生成和调试有关的信息
"-Wall", // 开启额外警告
"-static-libgcc", // 静态链接libgcc,一般都会加上
"-fexec-charset=GBK", // 生成的程序使用GBK编码,不加这一条会导致Win下输出中文乱码
"-std=c++17", // C++最新标准为c++17,或根据自己的需要进行修改
], // 编译的命令,其实相当于VSC帮你在终端中输了这些东西
"type": "process", // process是vsc把预定义变量和转义解析后直接全部传给command;shell相当于先打开shell再输入命令,所以args还会经过shell再解析一遍
"group": {
"kind": "build",
"isDefault": true // 不为true时ctrl shift B就要手动选择了
},
"presentation": {
"echo": true,
"reveal": "always", // 执行任务时是否跳转到终端面板,可以为always,silent,never。具体参见VSC的文档
"focus": false, // 设为true后可以使执行task时焦点聚集在终端,但对编译C/C++来说,设为true没有意义
"panel": "shared" // 不同的文件的编译信息共享一个终端面板
},
},
{
"label": "commit gitee",
"type": "shell",
"command": "D:\\python\\一键推拉.cmd",
"group": {
"kind": "build",
"isDefault": true
},
}
]
}

View File

@@ -0,0 +1,12 @@
#include <bits/stdc++.h>
using namespace std;
int n, cnt;
int main() {
cin >> n;
for (int i = 3; i <= n; i++)
if (i % 10 == 3) cnt++;
cout << cnt << endl;
return 0;
}

View File

@@ -0,0 +1,14 @@
#include <bits/stdc++.h>
using namespace std;
const int N = 110;
char a[N];
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
sort(a + 1, a + 1 + n);
for (int i = 1; i <= n; i++) cout << a[i];
return 0;
}

View File

@@ -0,0 +1,54 @@
### 一、 理论知识
裴蜀定理:任意两个数的组合必定是它们最大公约数的倍数。
* 推广:如果$n$个数的最大公约数是$d$,那么它们的组合是$d$的倍数,如果$d≠1$,则必然有无限个数无法被组合出来
* 如果每笼包子数目的最大公约数不是$1$,应该输出$INF$
* 如果给出的这些包子数互质,即最大公约数为$1$,那么由定理可知,是有有限个数不能被凑出来的,应该输出个数。
* 赛瓦维斯特定理
如果这些包子数互质,那么最大不能被表示出来的数字就是 (最小$a$和次小$b$) $a*b-a-b$
### 二、形象理解
* 不互质栗子:
比如$3$ 和 $6$两种规格,能组装的就是 $3,6,9,12,15,...$,这个变化就是它们的最大公约数3。
此时 ,类似于 $1,2,?,4,5,?,7,8,?,10,11,?,13,14,?,16,17,?,19,20, ,...$之类的数字均是无法凑出的,有无穷多个。
* 互质栗子
比如 $3$ 和 $4$
$11$->$1*3+2*4$
$12-> 3*4$
$13->1*4+3*3$
$14->4*2+3*2$
$15->3*5$
$16->4*4$
$17->3*3+4*2$
...
再来 $4$ 和 $7$
$29->3*7+4*2$
$30->2*7+4*4$
$31->1*7+4*6$
$32->4*8$
$33->3*7+4*3$
$34->2*7+4*5$
...
再来 $5$ 和 $7$
$31->3*7+5*2$
$32->1*7+5*5$
$33->4*7+1*5$
$34->2*7+4*5$
$35->5*7$
$36->3*7+3*5$
...
* ### 二、完全背包求方案数
[$AcWing$ $1371$. 货币系统](https://www.cnblogs.com/littlehb/p/16199799.html)

Binary file not shown.

View File

@@ -0,0 +1,55 @@
#include <bits/stdc++.h>
using namespace std;
const int N = 30;
const int M = 1e4 + 10;
/*
2
3 5
答案:
4
最大不能表示的应该是:3*5-3-5=7
四个不能表示的数是:1 2 4 7
*/
int f[N][M];
int w[N];
int res;
int gcd(int a, int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) cin >> w[i];
sort(w + 1, w + 1 + n);
int m1 = w[1], m2 = w[2];
int M = m1 * m2 - m1 - m2; // a*b-a-b =7
int g = w[1];
for (int i = 2; i <= n; i++) g = gcd(g, w[i]);
if (g > 1) {
cout << -1 << endl;
return 0;
}
// 完全背包二维写法
for (int i = 1; i <= n; i++)
for (int j = 1; j <= M; j++)
if (j >= w[i])
f[i][j] = max(f[i - 1][j], f[i][j - w[i]] + w[i]);
else
f[i][j] = f[i - 1][j];
for (int i = 1; i <= M; i++)
if (f[n][i] < i) res++;
printf("%d\n", res);
return 0;
}

View File

@@ -0,0 +1,51 @@
#include <bits/stdc++.h>
using namespace std;
const int N = 30;
const int M = 1e4 + 10;
/*
2
3 5
答案:
4
最大不能表示的应该是:3*5-3-5=7
四个不能表示的数是:1 2 4 7
*/
int f[M];
int w[N];
int res;
int gcd(int a, int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) cin >> w[i];
sort(w + 1, w + 1 + n);
int m1 = w[1], m2 = w[2];
int M = m1 * m2 - m1 - m2;
int g = w[1];
for (int i = 2; i <= n; i++) g = gcd(g, w[i]);
if (g > 1) {
cout << "-1" << endl;
return 0;
}
//完全背包一维写法
for (int i = 1; i <= n; i++)
for (int j = w[i]; j <= M; j++)
f[j] = max(f[j], f[j - w[i]] + w[i]);
for (int i = 1; i <= M; i++)
if (f[i] < i) res++;
printf("%d\n", res);
return 0;
}

View File

@@ -0,0 +1,36 @@
#include <bits/stdc++.h>
/**
5 2
200 145 240 50 45
150 300
答案
4
*/
using namespace std;
int m, n;
const int N = 310;
int a[N], b[N];
int res;
void dfs(int u, int s) {
if (u == n + 1) {
res = max(res, s);
return;
}
dfs(u + 1, s);
for (int i = 1; i <= m; i++)
if (a[u] <= b[i]) {
b[i] -= a[u]; //回溯
dfs(u + 1, s + 1);
b[i] += a[u];
}
}
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= m; i++) cin >> b[i];
dfs(1, 0);
printf("%d\n", res);
return 0;
}

View File

@@ -0,0 +1,48 @@
#include <bits/stdc++.h>
/**
5 4
1 2
1 3
2 4
2 5
答案
2 1 3 2
*/
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 110;
int n, m;
int g[N][N];
int f[N];
bool st[N];
void bfs() {
queue<int> q;
q.push(n);
st[n] = true;
while (q.size()) {
auto u = q.front();
q.pop();
for (int i = 1; i < n; i++)
if (!st[i] && g[u][i] != INF) {
f[i] = f[u] + 1;
q.push(i);
st[i] = true;
}
}
}
int main() {
memset(g, 0x3f, sizeof g); // 地图初始化
cin >> n >> m;
while (m--) {
int a, b;
cin >> a >> b;
g[a][b] = g[b][a] = 1;
}
bfs();
for (int i = 1; i < n; i++) cout << f[i] << " ";
return 0;
}

View File

@@ -0,0 +1,54 @@
#include <bits/stdc++.h>
/**
5 4
1 2
1 3
2 4
2 5
答案
2 1 3 2
bfs求的是无权图或边权相等图的最短路径算法
*/
using namespace std;
const int INF = 0x3f3f3f3f;
typedef pair<int, int> PII;
const int N = 110;
int n, m;
int g[N][N]; // 邻接矩阵装图
int f[N]; // 离n点的距离
bool st[N]; // 是不是走过
void bfs() {
queue<PII> q; // PII: first sencond
q.push({n, 0}); // first:n号点是起点,second:离出发点的距离
st[n] = true;
while (q.size()) {
auto u = q.front();
q.pop();
for (int i = 1; i < n; i++)
// 1、没走过
// 2、有路可走
if (!st[i] && g[u.first][i] != INF) {
f[i] = u.second + 1;
q.push({i, f[i]});
st[i] = true;
}
}
}
int main() {
cin >> n >> m;
memset(g, 0x3f, sizeof g); // 初始化每两个点之间的距离无穷大
memset(f, -1, sizeof f);
while (m--) {
int a, b;
cin >> a >> b;
g[a][b] = g[b][a] = 1;
}
bfs();
for (int i = 1; i < n; i++)
cout << f[i] << " ";
return 0;
}

View File

@@ -0,0 +1,38 @@
#include <bits/stdc++.h>
/**
5 4
1 2
1 3
2 4
2 5
答案
2 1 3 2
*
*/
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 110;
int d[N][N];
int n, m;
void floyd() {
for (int k = 0; k < n; k++)
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
}
int main() {
cin >> n >> m;
memset(d, 0x3f, sizeof d);
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
d[a][b] = d[b][a] = 1;
}
floyd();
for (int i = 1; i < n; i++)
if (d[n][i] == INF)
cout << -1 << " ";
else
cout << d[n][i] << " ";
return 0;
}

View File

@@ -0,0 +1,52 @@
#include <bits/stdc++.h>
/*
测试用例I:
5 6
1 0 1 0 0 0
0 1 0 1 0 0
1 0 0 0 1 0
0 1 0 0 0 1
1 0 1 0 0 0
答案
4
测试用例II:
5 6
1 0 1 0 0 0
0 1 0 1 1 0
1 0 0 0 1 0
0 1 0 0 0 1
1 0 1 0 0 0
答案
3
*/
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 110;
int a[N][N];
int res;
int main() {
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
cin >> a[i][j];
// 1e8 =100000000
// 1500000000
for (int i = 1; i <= n; i++) // 1000
for (int j = 1; j <= m; j++) { // 1000
for (int k = 0;; k++) { // 1000 *SQRT(2)=1500
if (i + k > n || j + k > m) break; //越界
if (a[i + k][j + k] == 0) break;
//从[i,j]出发,边长长度为k+1的矩形,内部数字为1的有多少个
res = max(res, k + 1);
}
}
cout << res << endl;
return 0;
}

View File

@@ -0,0 +1,55 @@
#include <bits/stdc++.h>
/*
测试用例I:
5 6
1 0 1 0 0 0
0 1 0 1 0 0
1 0 0 0 1 0
0 1 0 0 0 1
1 0 1 0 0 0
答案
4
测试用例II:
5 6
1 0 1 0 0 0
0 1 0 1 1 0
1 0 0 0 1 0
0 1 0 0 0 1
1 0 1 0 0 0
答案
2
*/
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 110;
int a[N][N];
int s[N][N];
int res;
int main() {
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) {
cin >> a[i][j];
s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + a[i][j];
}
for (int i = 1; i <= n; i++) // 100
for (int j = 1; j <= m; j++) { // 100
for (int r = 0;; r++) {
if (i + r > n || j + r > m) break; // 越界
if (a[i + r][j + r] == 0) break;
int x1 = i, y1 = j, x2 = i + r, y2 = j + r;
int sum = s[x2][y2] - s[x1 - 1][y2] - s[x2][y1 - 1] + s[x1 - 1][y1 - 1];
if (sum != r + 1) break;
res = max(res, r + 1);
}
}
printf("%d\n", res);
return 0;
}

View File

@@ -0,0 +1,63 @@
#include <bits/stdc++.h>
/*
测试用例:
5 6
1 0 1 0 0 0
0 1 0 1 0 0
1 0 0 0 1 0
0 1 0 0 0 1
1 0 1 0 0 0
测试用例II:
5 6
1 0 1 0 0 0 2 0 4 0 0 0
0 1 0 1 1 0 0 1 0 3 1 0
1 0 0 0 1 0 3 0 0 0 2 0
0 1 0 0 0 1 0 2 0 0 0 1
1 0 1 0 0 0 1 0 1 0 0 0
5 6
1 0 1 0 0 0
0 1 0 1 1 0
1 0 0 0 1 0
0 1 0 0 0 1
1 0 1 0 0 0
测试用例III:
5 6
1 0 1 0 0 0
0 1 0 1 1 0
1 0 0 0 1 0
0 1 0 1 0 1
1 0 1 0 1 0
*/
using namespace std;
const int N = 110;
int a[N][N];
int res;
int main() {
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
cin >> a[i][j];
//直接在原数组上递推
for (int i = n; i >= 1; i--) //从倒数第二行开始
for (int j = 1; j <= m; j++) //这个需要考虑一下边界问题
if (a[i][j]) //只有当前位置大于0才有考虑的价值
a[i][j] += a[i + 1][j + 1]; //递推式
cout << "====================" << endl;
//打印出这个新的递推数组看看是什么情况
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++)
cout << a[i][j] << " ";
cout << endl;
}
return 0;
}

View File

@@ -0,0 +1,57 @@
#include <bits/stdc++.h>
/*
测试用例:
5 6
1 0 1 0 0 0
0 1 0 1 0 0
1 0 0 0 1 0
0 1 0 0 0 1
1 0 1 0 0 0
答案
4
测试用例II:
5 6
1 0 1 0 0 0
0 1 0 1 1 0
1 0 0 0 1 0
0 1 0 0 0 1
1 0 1 0 0 0
答案
2
*/
using namespace std;
const int N = 110;
int a[N][N];
int s[N][N];
int res;
int main() {
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) {
cin >> a[i][j];
//维护二维前缀和
s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + a[i][j];
}
//直接在原数组上递推
for (int i = n - 1; i >= 1; i--) //从倒数第二行开始
for (int j = 1; j <= m; j++) //这个需要考虑一下边界问题
if (a[i][j]) { //只有当前位置大于0才有考虑的价值
a[i][j] += a[i + 1][j + 1]; //递推式,当前位置可以向下扩展的最长对角线长度
//利用二维前缀和计算区域的总和
int x1 = i, y1 = j, x2 = i + a[i][j] - 1, y2 = j + a[i][j] - 1;
int cnt = s[x2][y2] - s[x1 - 1][y2] - s[x2][y1 - 1] + s[x1 - 1][y1 - 1];
if (cnt == a[i][j])
res = max(res, a[i][j]); //在递推过程中不断求最大值
}
//输出
cout << res << endl;
return 0;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 114 KiB

View File

@@ -0,0 +1,36 @@
/*
小马需要将N件物品从河的一岸搬运到河的另一岸,每次搬运的物品为1到3件。
请问小马将N件物品全部搬运过去有多少种方案。
例如:N=3,将3件物品全部搬运过去有4种方案:
方案一:第一次搬运1件,第二次搬运1件,第三次搬运1件;
方案二:第一次搬运1件,第二次搬运2件;
方案三:第一次搬运2件,第二次搬运1件;
方案四:一次搬运3件。
*/
#include <bits/stdc++.h>
using namespace std;
const int N = 110;
int a[N];
int res;
int n;
/**
* @brief
*
* @param step 第几次
* @param r 剩余件数
*/
void dfs(int u, int r) {
if (r == 0) res++; //剩余为0,就得到一组答案
//本轮运几件
for (int i = 1; i <= 3; i++)
if (r - i >= 0) dfs(u + 1, r - i);
}
int main() {
cin >> n;
dfs(0, n);
printf("%d", res);
return 0;
}

View File

@@ -0,0 +1,63 @@
/*
有一片海域划分为N*M个方格,其中有些海域已被污染(用0表示),
有些海域没被污染(用1表示)。请问这片N*M海域中有几块是没被污染的独立海域
(没被污染的独立海域是指该块海域上下左右被已污染的海域包围,
且N*M以外的海域都为已被污染的海域)
例如:N=4,M=5,4*5的海域中,已被污染海域和没被污染的海域如下图:
这块4*5的海域,有3块海域(绿色)没被污染,因为每一块的上下左右都被污染的海域包围。
4 5
1 1 0 0 0
1 0 1 0 0
1 0 0 0 0
1 1 0 1 1
样例输出
3
*/
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
typedef pair<int, int> PII;
const int N = 110;
int a[N][N];
int n, m;
int dx[] = {-1, 0, 1, 0}; //上右下左
int dy[] = {0, 1, 0, -1}; //上右下左
void bfs(int x, int y) {
a[x][y] = 0;
queue<PII> q;
q.push({x, y});
while (q.size()) {
auto u = q.front();
q.pop();
for (int i = 0; i <= 3; i++) {
int tx = u.x + dx[i], ty = u.y + dy[i];
if (tx < 1 || tx > n || ty < 1 || ty > m) continue;
if (a[tx][ty]) {
a[tx][ty] = 0;
q.push({tx, ty});
}
}
}
}
int res;
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
cin >> a[i][j];
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) {
if (a[i][j]) {
bfs(i, j);
res++;
}
}
printf("%d", res);
return 0;
}

View File

@@ -0,0 +1,22 @@
#include <bits/stdc++.h>
using namespace std;
int cnt;
const int N = 1010;
int f[N];
int main() {
int n = 1000, m = 1000;
for (int x = 1; x <= n; x++)
for (int y = 1; y <= m; y++)
for (int len = 1;; len++) {
int tx = x + len - 1, ty = y + len - 1;
if (tx > n || ty > m) break;
f[len]++;
}
for (int i = 1; i <= min(n, m); i++)
cout << f[i] << " ";
return 0;
}

View File

@@ -0,0 +1,72 @@
#include <bits/stdc++.h>
using namespace std;
/**
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2
3 5
<20><><EFBFBD><EFBFBD>
4
*/
const int N = 30;
int f[N]; //<2F><>ʾ<EFBFBD>ճ<EFBFBD>j<EFBFBD><6A><EFBFBD><EFBFBD><EFBFBD>ӵķ<D3B5><C4B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int a[N]; //ÿ<>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD>а<EFBFBD><D0B0>ӵ<EFBFBD><D3B5><EFBFBD><EFBFBD><EFBFBD>
int ans; //<2F><>װ<EFBFBD><D7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>İ<EFBFBD><C4B0>Ӹ<EFBFBD><D3B8><EFBFBD>
//<2F><><EFBFBD><EFBFBD>
bool isHz(int a, int b) {
for (int i = 2; i <= min(a, b); i++) //a,b<><62><EFBFBD>ܴ<EFBFBD><DCB4>ڵĹ<DAB5><C4B9><EFBFBD><EFBFBD><EFBFBD>
if (a % i == 0 && b % i == 0)
return false;
return true;
}
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
//<2F><><EFBFBD><EFBFBD>
sort(a + 1, a + 1 + n);
//a<><61><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD><D0A3>Dz<EFBFBD><C7B2>Ǵ<EFBFBD><C7B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5><EFBFBD>
bool flag = false;
int mx;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++)
if (isHz(a[i], a[j])) {
flag = true;
mx = a[i] * a[j] - a[i] - a[j];
break;
}
if (flag)
break;
}
if (!flag) {
cout << -1 << endl;
return 0;
}
/**
<20><>ȫ<EFBFBD><C8AB><EFBFBD><EFBFBD>
f[j]<5D><>ʾ<EFBFBD>ճ<EFBFBD>j<EFBFBD><6A><EFBFBD><EFBFBD><EFBFBD>ӵķ<D3B5><C4B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>f[j]>0<>ʹյó<D5B5><C3B3><EFBFBD>f[j]=0<>ʹղ<CDB4><D5B2><EFBFBD><EFBFBD><EFBFBD>
*/
f[0] = 1; // 0<><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬<D7B4>ǺϷ<C7BA><CFB7>ģ<EFBFBD><C4A3>ǿ<EFBFBD><C7BF>Ե<EFBFBD><D4B5><EFBFBD><EFBFBD><EFBFBD>״̬<D7B4><CCAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֻ<EFBFBD><D6BB><EFBFBD><EFBFBD>һ<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Dz<EFBFBD><C7B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>Ų<EFBFBD>Ҫ
for (int i = 1; i <= n; i++)
for (int j = 1; j <= mx; j++)
if (j >= a[i] && f[j - a[i]])//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>װ<EFBFBD>£<EFBFBD><C2A3><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɴ<C9B4><EFA3AC><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD>Լ<EFBFBD><D4BC><EFBFBD><EFBFBD>ƽ<EFBFBD>
f[j]++;
//ö<><C3B6>ÿ<EFBFBD><C3BF><EFBFBD><EFBFBD><EFBFBD>ܵ<EFBFBD><DCB5><EFBFBD><EFBFBD>֣<EFBFBD><D6A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD><D6B4><EFBFBD>1<EFBFBD><31><EFBFBD><EFBFBD><EFBFBD>ϵķ<CFB5><C4B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǿ<EFBFBD><C7BF>Դճ<D4B4><D5B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>޷<EFBFBD><DEB7>ճ<EFBFBD>
for (int i = 1; i <= mx; i++)
if (!f[i])
ans++;
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
cout << ans << endl;
return 0;
}

View File

@@ -0,0 +1,73 @@
#include <bits/stdc++.h>
using namespace std;
const int N = 30;
int a[N];
int n;
//<2F><><EFBFBD>մ<EFBFBD><D5B4><EFBFBD>
int res;
//<2F><><EFBFBD><EFBFBD>
bool isHz(int a, int b) {
for (int i = 2; i <= min(a, b); i++) //a,b<><62><EFBFBD>ܴ<EFBFBD><DCB4>ڵĹ<DAB5><C4B9><EFBFBD><EFBFBD><EFBFBD>
if (a % i == 0 && b % i == 0)
return false;
return true;
}
bool found = false; //<2F><><EFBFBD><EFBFBD><EFBFBD>Dz<EFBFBD><C7B2><EFBFBD><EFBFBD>ܱ<EFBFBD>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD> found=true<75>ǿ<EFBFBD><C7BF>Ա<EFBFBD><D4B1>found=false<73>Dz<EFBFBD><C7B2>ܱ<EFBFBD><DCB1><EFBFBD>
//<2F>ܱ<EFBFBD>ʾ
void dfs(int sum, int u) { //<2F><>a[]<5D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ԫ<EFBFBD><D4AA><EFBFBD><EFBFBD><EFBFBD>ϣ<EFBFBD><CFA3>ܲ<EFBFBD><DCB2>ܱ<EFBFBD>ʾ<EFBFBD><CABE>x<EFBFBD><78><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֣<EFBFBD><D6A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܷ<EFBFBD><DCB7><EFBFBD>true,<2C><><EFBFBD>򷵻<EFBFBD>false
if (u == n + 1) {
if (sum == 0)
found = true;
return;
}
//<2F><><EFBFBD>Ե<EFBFBD>ǰa[u]ѡ<><D1A1>i<EFBFBD><69>
for (int i = 0; sum >= i * a[u]; i++) //i<><69>ö<EFBFBD>ٵ<EFBFBD>a[u]<5D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĸ<EFBFBD><C4B8><EFBFBD>
dfs(sum - i * a[u], u + 1);
}
int main() {
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
//<2F><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD><D0A1><EFBFBD><EFBFBD>
sort(a + 1, a + 1 + n);
//a<><61><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD><D0A3>Dz<EFBFBD><C7B2>Ǵ<EFBFBD><C7B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5><EFBFBD>
bool flag = false;
int mx;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++)
if (isHz(a[i], a[j])) {
flag = true;
mx = a[i] * a[j] - a[i] - a[j];
break;
}
if (flag)
break;
}
if (flag) {
for (int i = 1; i <= mx; i++) {
//һ<><D2BB>Ҫ<EFBFBD>ǵ<EFBFBD><C7B5><EFBFBD><EFBFBD><EFBFBD>
found = false;
dfs(i, 1);
if (!found)
res++;
}
cout << res << endl;
} else
cout << -1 << endl;
return 0;
}

View File

@@ -0,0 +1,19 @@
#include <bits/stdc++.h>
using namespace std;
int cnt;
const int N = 30000;
int f[N];
int main() {
int n = 3000, m = 3000;
for (int x = 1; x <= n; x++)
for (int y = 1; y <= m; y++)
for (int len = 1;; len++) {
int tx = x + len - 1, ty = y + len - 1;
if (tx > n || ty > m) break;
f[len]++;
}
for (int i = 1; i <= min(n,m); i++)
printf("%d ", f[i]);
return 0;
}

View File

@@ -0,0 +1,76 @@
## 1、激光炸弹
#### 录入训练
https://www.acwing.com/problem/content/101/
#### 温故知新
- 点坐标如何修改为数组方格坐标
- 二维前缀和
- 不能开两个数组,因为每个数组是$5000x5000$这么大,就是$5000x5000x4bytes,5000x5000x4/1024/1024=95MB$,这题的空间是$168MB$,所以两个数组会$MLE$。
一个数组就行了,在自己身上求前缀和。
- $xy$坐标是从$0$开始的,二维前缀和需要坐标从$(1,1)$开始,需要$x++,y++$
- 炸弹的范围会超过$r>M$,会导致计算二维前缀和的两层循环失效,造成结果错误。正确的作法是时刻小心观察,循环什么情况下不会执行,然后加上特判。
- 只枚举右下角即可完成所有边长为$r$的正方形枚举
### 蓝桥杯第13届省赛中级组第6题
![](http://dsideal.obs.cn-north-1.myhuaweicloud.com/HuangHai/BlogImages/2023/02/b15ecc654c62371bfd8433381b1a3110.png)
![](http://dsideal.obs.cn-north-1.myhuaweicloud.com/HuangHai/BlogImages/2023/02/7d8e8d0f52943660628d42fa572d70ea.png)
```cpp {.line-numbers}
#include <bits/stdc++.h>
/*
测试用例I:
5 6
1 0 1 0 0 0
0 1 0 1 0 0
1 0 0 0 1 0
0 1 0 0 0 1
1 0 1 0 0 0
答案
4
测试用例II:
5 6
1 0 1 0 0 0
0 1 0 1 1 0
1 0 0 0 1 0
0 1 0 0 0 1
1 0 1 0 0 0
答案
2
*/
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 110;
int a[N][N];
int s[N][N];
int res;
int main() {
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) {
cin >> a[i][j];
s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + a[i][j];
}
for (int i = 1; i <= n; i++) // 100
for (int j = 1; j <= m; j++) { // 100
for (int k = 0;; k++) {
if (i + k > n || j + k > m) break; // 越界
if (a[i + k][j + k] == 0) break;
int x1 = i, y1 = j, x2 = i + k, y2 = j + k;
int cnt = s[x2][y2] - s[x1 - 1][y2] - s[x2][y1 - 1] + s[x1 - 1][y1 - 1];
if (cnt != k + 1) break;
res = max(res, cnt);
}
}
printf("%d\n", res);
return 0;
}
```

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 45 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

View File

@@ -0,0 +1,25 @@
### 裴蜀定理(贝祖定理)
**定理**
$ax+by=c,x∈Z^+,y∈Z^+$成立的<font color='red'>充要条件</font>是$gcd(a,b)|c$。
**证明**
* 充分性
设$s=gcd(a,b)$,显然$s|a$,并且$s|b$
因为$x,y∈Z^+$
所以$s|ax,s|by$
显然要使得之前的式子成立,则必须满足$c$是$a$和$b$的公约数的倍数。
* 必要性
又因为$x$和$y$是正整数
所以$c$必然是$a,b$最大公约数的倍数。
因此,证得该定理成立
说明
该定理完全可以推广到若干数的线性组合
例题的话,请看这里:[$Luogu$ $4549$ 裴蜀定理/Min](https://www.luogu.com.cn/problem/P4549)

Binary file not shown.

After

Width:  |  Height:  |  Size: 238 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 253 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 260 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 238 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 274 KiB