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,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"
]
}

28
TangDou/KaoShi/.vscode/launch.json vendored Normal file
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相对应
}
]
}

112
TangDou/KaoShi/.vscode/settings.json vendored Normal file
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的顺序(按字母排序)
}

40
TangDou/KaoShi/.vscode/tasks.json vendored Normal file
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,24 @@
#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
int n, m;
int v[N], w[N];
int f[N];
int main() {
//优化输入
ios::sync_with_stdio(false);
//物品个数n
cin >> n >> m;
//读入体积和重量
for (int i = 1; i <= n; i++) cin >> v[i] >> w[i];
// 01背包模板
for (int i = 1; i <= n; i++)
for (int j = m; j >= v[i]; j--)
f[j] = max(f[j], f[j - v[i]] + w[i]);
cout << f[m] << endl;
return 0;
}

69
TangDou/KaoShi/24点.cpp Normal file
View File

@@ -0,0 +1,69 @@
#include <bits/stdc++.h>
using namespace std;
/*
10 2 4 8
答案:2
*/
// 24点
int main() {
int a, b, c, d;
cin >> a >> b >> c >> d;
int res = 0, x;
x = a + b + c + d;
if (x == 24) res++;
x = a + b + c - d;
if (x == 24) res++;
x = a + b + c * d;
if (x == 24) res++;
x = a + b - c + d;
if (x == 24) res++;
x = a + b - c - d;
if (x == 24) res++;
x = a + b - c * d;
if (x == 24) res++;
x = a + b * c + d;
if (x == 24) res++;
x = a + b * c - d;
if (x == 24) res++;
x = a + b * c * d;
if (x == 24) res++;
x = a - b + c + d;
if (x == 24) res++;
x = a - b + c - d;
if (x == 24) res++;
x = a - b + c * d;
if (x == 24) res++;
x = a - b - c + d;
if (x == 24) res++;
x = a - b - c - d;
if (x == 24) res++;
x = a - b - c * d;
if (x == 24) res++;
x = a - b * c + d;
if (x == 24) res++;
x = a - b * c - d;
if (x == 24) res++;
x = a - b * c * d;
if (x == 24) res++;
x = a * b + c + d;
if (x == 24) res++;
x = a * b + c - d;
if (x == 24) res++;
x = a * b + c * d;
if (x == 24) res++;
x = a * b - c + d;
if (x == 24) res++;
x = a * b - c - d;
if (x == 24) res++;
x = a * b - c * d;
if (x == 24) res++;
x = a * b * c + d;
if (x == 24) res++;
x = a * b * c - d;
if (x == 24) res++;
x = a * b * c * d;
if (x == 24) res++;
cout << res;
return 0;
}

4
TangDou/KaoShi/3056.in Normal file
View File

@@ -0,0 +1,4 @@
2 2
1001 3357
D 0
Z 4388 852

View File

11
TangDou/KaoShi/BABA_2.cpp Normal file
View File

@@ -0,0 +1,11 @@
#include <bits/stdc++.h>
using namespace std;
int main() {
int cnt = 0;
for (int i = 1; i < 100; i += 5)
cnt += i;
cout << cnt << endl;
return 0;
}

47
TangDou/KaoShi/BABA_3.cpp Normal file
View File

@@ -0,0 +1,47 @@
#include <bits/stdc++.h>
using namespace std;
const int INF=0x3f3f3f3f;
const int N=1510;
int n;
int h[N],e[N],ne[N],idx;
int w[N];
int f[N][3];
int in[N];
void add(int a,int b){
e[idx]=b,ne[idx]=h[a],h[a]=idx++;
}
void dfs(int u){
f[u][0]=0;
f[u][1]=INF ;
f[u][2]=w[u];
for(int i=h[u];~i;i=ne[i]){
int v=e[i];
dfs(v);
f[u][0]+=min(f[v][1],f[v][2]);
f[u][2]+=min({f[v][0],f[v][1],f[v][2]});
}
for(int i=h[u];~i;i=ne[i]){
int v=e[i];
f[u][1]=min(f[u][1],f[v][2]+f[u][0]-min(f[v][1],f[v][2]));
}
}
int main() {
memset(h,-1,sizeof h);
cin>>n;
for (int i = 1; i <= n; i++){
int x,m;
cin>>x>>w[x]>>m;
while(m--){
int y;
cin>>y;
}
}
int root=1;
while(in[root])root++;
dfs(root);
printf("%d\n",min(f[root][1],f[root][2]));
return 0;
}

25
TangDou/KaoShi/BABA_4.cpp Normal file
View File

@@ -0,0 +1,25 @@
#include <bits/stdc++.h>
using namespace std;
const int N=1010;
int a[N][N];
int main() {
int n,m,q;
cin>>n>>m;
for (int i = 1; i <= n; i++){
for (int j = 1; j <= m; j++){
int x;
cin>>x;
a[i][j]=a[i-1][j]+a[i][j-1]-a[i-1][j-1]+x;
}
}
cin>>q;
while(q--){
int x1,x2,y1,y2;
cin>>x1>>x2>>y1>>y2;
printf("%d\n",a[x2][y2]-a[x1-1][y2]-a[x2][y1-1]+a[x1-1][y1-1]);
}
return 0;
}

32
TangDou/KaoShi/BABA_5.cpp Normal file
View File

@@ -0,0 +1,32 @@
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> count(81, 0);
for (int i = 0; i < n; ++i) {
int num;
cin >> num;
count[num]++;
}
for (int i = 1; i <= 80; ++i) {
if (count[i] >= 2) {
count[i + 1] += count[i] / 2;
count[i] %= 2;
}
}
int max_num = 0;
for (int i = 1; i <= 80; ++i) {
if (count[i] > 0) {
max_num = i;
}
}
cout << max_num << endl;
return 0;
}

View File

@@ -0,0 +1,69 @@
#include <bits/stdc++.h>
using namespace std;
/*
2015 1 4
*/
int months_1[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int months_2[13] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
bool LeapYear(int year) {
return ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0);
}
/*
2023 1 1 --> 7
2023 7 1 --> 6
2023 7 7
2023 5 7 --->1?
*/
int main() {
// 1、是不是需要判断闰年?
int year, month;
int ydxq, month_1_xq;
// 2、year年1月1日 是星期xq
cin >> year >> month >> ydxq;
cout << "S M T W T F S" << endl;
int days = 0;
if (LeapYear(year)) {
// 比如month=5,要的是5月1号的,应该是1~4月份相加的和
for (int i = 1; i < month; i++) days += months_2[i];
} else {
for (int i = 1; i < month; i++) days += months_1[i];
}
// days含义:days就是当前年份的第几天-1
month_1_xq = (ydxq + days) % 7;
// 是指定月份的第1天是星期几0~6
// cout << month_1_xq << endl;
// 打空格
for (int i = 1; i <= month_1_xq; i++) cout << " ";
// 打第一行的剩余日期
// 1~ 6
// 2~ 5
// 3~ 4
// 4~ 3
// 5~ 2
// 6~ 1
// 0~ 7
for (int i = 1; i <= 7 - month_1_xq; i++) printf("%-4d", i);
cout << endl;
int this_month_days = 0;
if (LeapYear(year)) {
this_month_days = months_2[month];
} else {
this_month_days = months_1[month];
}
int cnt = 0;
for (int i = 7 - month_1_xq + 1; i <= this_month_days; i++) {
cnt++;
printf("%-4d", i);
if (cnt % 7 == 0) cout << endl;
}
return 0;
}

View File

@@ -0,0 +1,25 @@
#include <bits/stdc++.h>
using namespace std;
const int N = 110;
int x[N], y[N];
int n;
int maxv, maxp;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) cin >> x[i] >> y[i];
for (int i = 1; i <= n; i++){
int cnt = 0;
for (int j = 1; j <= n; j++)
if (x[i] > x[j] && y[i] > y[j]) cnt++;
if(cnt>=maxv){
maxv = cnt;
maxp = i;
}
cout << cnt;
}
cout << endl;
cout << maxp << endl;
return 0;
}

View File

@@ -0,0 +1,22 @@
#include <bits/stdc++.h>
using namespace std;
int n;
int main() {
cin >> n;
while (1) {
if (n == 1) break;
if (n % 2 == 0) {
n /= 2;
printf("%d\n", n);
}
else if (n % 2 == 1) {
n = n * 3 + 1;
printf("%d\n", n);
}
}
return 0;
}

View File

View File

@@ -0,0 +1,35 @@
#include <bits/stdc++.h>
using namespace std;
// 给出一个数字,比如(11),将其转为2进制,计算出它的十进制是多少,答案应该是3
//1234
int convert(string s, int k) {
int res = 0;
for (int i = 0; i < s.size(); i++) {
int x = s[i] - '0';
if (x >= k) return -1;
res += x * pow(k, s.size() - 1 - i); // 105
}
return res;
}
int main() {
string a, b, c;
cin >> a >> b >> c;
bool flag = false;
for (int k = 2; k <= 16; k++) {
int x = convert(a, k);
int y = convert(b, k);
int z = convert(c, k);
if (x * y == z) {
cout << k << endl;
flag = true;
break;
}
}
if (!flag) cout << 0 << endl;
return 0;
}

23
TangDou/KaoShi/Test.cpp Normal file
View File

@@ -0,0 +1,23 @@
#include <bits/stdc++.h>
using namespace std;
int n = 9;
const int INF = 0x3f3f3f3f;
int res = INF, a1, b1, c1;
int main() {
int a, b, c;
for (int a = 1; a * a * a <= n; a++) {
for (int b = a; a * b * b <= n; b++) {
int c = n / a / b;
if(a*b*c==n){
if(2*c-2*a<res){
res = 2 * c - 2 * a;
a1 = a, b1 = b, c1 = c;
}
}
}
}
int ans = (a1 * b1 + a1 * c1 + b1 * c1) * 2;
cout << ans << endl;
return 0;
}

View File

@@ -0,0 +1,27 @@
#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
int n, m;
int v[N], w[N];
int f[N];
/**
测试用例:
80 2
18 10
30 20
*/
//完全背包问题
int main() {
cin >> m >> n;
for (int i = 1; i <= n; i++) cin >> v[i] >> w[i];
for (int i = 1; i <= n; i++)
for (int j = v[i]; j <= m; j++)
f[j] = max(f[j], f[j - v[i]] + w[i]);
cout << f[m] << endl;
return 0;
}

View File

@@ -0,0 +1,20 @@
#include <bits/stdc++.h>
using namespace std;
int main() {
string a;
//问题1:错误的使用了getline
//getline(cin,a);
//完全没有必要使用getline,因为题目没有可能包含空格,使用cin即可
//问题2:错误的使用for循环重复读取a,因为a是string,是一次性cin读取。
//问题3:a的界限是 a.size()-1 ,0 而不是a.size(),1
cin >> a;
for (int i = a.size() - 1; i >= 0; i--) printf("%c", a[i]);
return 0;
}

View File

@@ -0,0 +1,33 @@
#include <iostream>
using namespace std;
const int N = 15;
const int INF = 0x3f3f3f3f;
int a[N];
int n;
int cha = INF;
int res1, res2;
/*
3
200 300 110
*/
void dfs(int u, int s1, int s2) {
if (u == n) {
if (s1 < s2) swap(s1, s2);
if (s1 - s2 < cha) {
res1 = s1, res2 = s2;
cha = s1 - s2;
}
return;
}
dfs(u + 1, s1 + a[u], s2);
dfs(u + 1, s1, s2 + a[u]);
}
int main() {
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
dfs(0, 0, 0);
printf("%d %d\n", res1, res2);
return 0;
}

View File

@@ -0,0 +1,33 @@
#include <bits/stdc++.h>
using namespace std;
const int N = 110;
int n; // n类物品
int m; //背包上限为m
int v[N][N]; //价值
int w[N][N]; //体积
int s[N]; //个数
int f[N]; // dp数组,最大值
//分组背包
int main() {
//优化输入
ios::sync_with_stdio(false);
cin >> n >> m;
for (int i = 1; i <= n; i++) { //枚举每类物品,比如:水果,蔬菜,肉类...
cin >> s[i]; //此类物品中物品的个数,比如2,可能是苹果、香蕉
for (int j = 1; j <= s[i]; j++) //读入苹果、香蕉的价值和体积
cin >> v[i][j] >> w[i][j];
}
for (int i = 1; i <= n; i++) //遍历每类物品
for (int j = m; j >= 0; j--) //遍历每个可能的体积
for (int k = 1; k <= s[i]; k++) //遍历第k个物品
if (v[i][k] <= j)
f[j] = max(f[j], f[j - v[i][k]] + w[i][k]);
cout << f[m] << endl;
return 0;
}

View File

@@ -0,0 +1,31 @@
#include <iostream>
#include <cmath>
using namespace std;
// 欧拉筛
const int N = 1e5 + 10;
int primes[N], cnt; // primes[]存储所有素数
bool st[N]; // st[x]存储x是否被筛掉
void get_primes(int n) {
for (int i = 2; i <= n; i++) {
if (!st[i]) primes[cnt++] = i;
for (int j = 0; primes[j] * i <= n; j++) {
st[primes[j] * i] = true;
if (i % primes[j] == 0) break;
}
}
}
int main() {
int n;
cin >> n;
get_primes(sqrt(n));
for (int i = 0; i < cnt; i++) {
while (n % primes[i] == 0) {
cout << primes[i] << endl;
n /= primes[i];
}
}
if (n > 1) cout << n << endl;
return 0;
}

View File

@@ -0,0 +1,13 @@
#include <bits/stdc++.h>
using namespace std;
const int N = 10;
int main() {
string s;
cin >> s;
if (s[0] == s[3] && s[1] == s[2])
cout << "YES";
else
cout << "NO";
return 0;
}

View File

@@ -0,0 +1,13 @@
#include <bits/stdc++.h>
using namespace std;
const int N = 30;
int a[N] = {2};
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) a[i] = a[i - 1] + pow(2, i - 1);
printf("%d", a[n]);
return 0;
}

10
TangDou/KaoShi/加密.cpp Normal file
View File

@@ -0,0 +1,10 @@
#include <bits/stdc++.h>
using namespace std;
int main() {
string a;
cin >> a;
for (int i = 0; i < a.size(); i++) cout << char(a[i] + 3);
return 0;
}

View File

@@ -0,0 +1,39 @@
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int primes[N], cnt; // primes[]存储所有素数
bool st[N]; // st[x]存储x是否被筛掉
int factor[N]; // 存储每一个数的质因子个数
void get_primes(int n) {
memset(st, 0, sizeof st);
for (int i = 2; i <= n; i++) {
if (!st[i]) {
primes[cnt++] = i;
factor[i] = 1; // 质数的质因子个数是1
}
for (int j = 0; primes[j] * i <= n; j++) {
st[primes[j] * i] = true; // 标识primes[j] * i是个合数
factor[primes[j] * i] = factor[i] + 1; // t=primes[j]*i,那么t的质因子个数=i的质因子个数+1
if (i % primes[j] == 0) break; // 只被最小的质数因子筛掉
}
}
}
int main() {
int n, m;
cin >> n >> m;
get_primes(m);
int res = 0;
for (int i = n; i <= m; i++) {
res = max(res, factor[i]);
// printf("The count of prime factor(s) of %d is: %d\n", i, factor[i]);
}
cout << res << endl;
return 0;
}

View File

@@ -0,0 +1,37 @@
#include <bits/stdc++.h>
using namespace std;
// OJ地址
// https://www.acwing.com/problem/content/150/
// 黄海题解
// https://www.cnblogs.com/littlehb/p/15488791.html
//小顶堆
priority_queue<int, vector<int>, greater<int>> q;
int res;
int main() {
int n;
cin >> n;
while (n--) {
int x;
cin >> x;
q.push(x);
}
while (q.size() > 1) {
int a = q.top();
q.pop();
int b = q.top();
q.pop();
res += a + b;
q.push(a + b);
}
printf("%d\n", res);
return 0;
}

View File

@@ -0,0 +1,18 @@
#include <bits/stdc++.h>
using namespace std;
bool isPrime(int n) {
for (int i = 2; i <= n / i; i++)
if (n % i == 0) return false;
return true;
}
int main() {
int n, s = 0;
cin >> n;
for (int i = 4; i <= n; i++)
if (!isPrime(i))s += i;
cout << s << endl;
return 0;
}

View File

@@ -0,0 +1,21 @@
#include <bits/stdc++.h>
using namespace std;
int n;
bool check(int x) {
int cnt = 0;
for (int i = 1; i <= x; i++)
if (x % i == 0) cnt++;
return cnt == n;
}
int main() {
cin >> n;
for (int i = 3; i <= 100; i++) {
if (check(i)) {
printf("%d", i);
return 0;
}
}
return 0;
}

View File

@@ -0,0 +1,25 @@
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 1e5 + 10;
int primes[N], cnt; // primes[]存储所有素数
bool st[N]; // st[x]存储x是否被筛掉
//埃拉筛
void get_primes(int n) {
for (int i = 2; i <= n; i++)
if (!st[i]) {
primes[cnt++] = i; //记录素数
for (int j = 2 * i; j <= n; j += i) //成倍数的标识
st[j] = true;
}
}
/*
get_primes(200);
for (int i = 0; i < cnt; i++)
if (primes[i] > 100)
cout << primes[i] << " ";
*/
int main() {
return 0;
}

View File

@@ -0,0 +1,28 @@
#include <bits/stdc++.h>
using namespace std;
//多重背包问题,每件物品的数量是有限制的,不是无穷,也不是只有1个。
// 状态表示 集合,属性
// 状态计算
const int N = 110;
int n, m;
int v[N], w[N], s[N];
int f[N];
int main() {
//优化输入
ios::sync_with_stdio(false);
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> v[i] >> w[i] >> s[i];
for (int i = 1; i <= n; i++)
for (int j = m; j >= 0; j--)
for (int k = 0; k <= s[i] && k * v[i] <= j; k++) //穷举所有可能性,尝试拿到最大的合理值
f[j] = max(f[j], f[j - v[i] * k] + w[i] * k);
cout << f[m] << endl;
return 0;
}

View File

@@ -0,0 +1,44 @@
#include <bits/stdc++.h>
using namespace std;
const int N = 12010, M = 2010;
int n, m;
int v[N], w[N];
int f[M];
//多重背包的二进制优化
int main() {
//优化输入
ios::sync_with_stdio(false);
cin >> n >> m;
int cnt = 0;
for (int i = 1; i <= n; i++) {
int a, b, s;
cin >> a >> b >> s;
//二进制优化,能打包则打包之,1,2,4,8,16,...
int k = 1;
while (k <= s) {
cnt++;
v[cnt] = a * k;
w[cnt] = b * k;
s -= k;
k *= 2;
}
//剩下的
if (s > 0) {
cnt++;
v[cnt] = a * s;
w[cnt] = b * s;
}
}
n = cnt; //数量减少啦
// 01背包
for (int i = 1; i <= n; i++)
for (int j = m; j >= v[i]; j--)
f[j] = max(f[j], f[j - v[i]] + w[i]);
cout << f[m] << endl;
return 0;
}

View File

@@ -0,0 +1,14 @@
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
for (int i = s.size() - 1; i >= 0; i--)
if (s[i] >= 'A' && s[i] <= 'Z')
cout << s[i] + 32;
else
cout << s[i];
return 0;
}

View File

@@ -0,0 +1,26 @@
#include <bits/stdc++.h>
using namespace std;
string a, b;
bool check(string a, string b) {
for (int i = 0; i < a.size(); i++) {
if (a[i] >= 'A' && a[i] <= 'Z') a[i] = a[i] + 32;
if (b[i] >= 'A' && b[i] <= 'Z') b[i] = b[i] + 32;
if (a[i] != b[i]) return false;
}
return true;
}
int main() {
cin >> a >> b;
if (a.size() != b.size())
cout << 1 << endl;
else if (a == b)
cout << 2 << endl;
else if (a.size() == b.size() && check(a, b))
cout << 3 << endl;
else
cout << 4 << endl;
return 0;
}

View File

@@ -0,0 +1,16 @@
#include <bits/stdc++.h>
using namespace std;
//完数
int isWMS(int n) {
int s = 0;
for (int i = 1; i <= n / 2; i++)
if (n % i == 0) s += i;
return s == n ? 1 : 0;
}
int main() {
for (int i = 1; i <= 1000; i++)
if (isWMS(i)) cout << i << " ";
return 0;
}

View File

@@ -0,0 +1,25 @@
#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
int n, m;
int v[N];
int w[N];
int f[N];
// 完全背包问题
int main() {
//优化输入
ios::sync_with_stdio(false);
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> v[i] >> w[i];
for (int i = 1; i <= n; i++)
for (int j = v[i]; j <= m; j++) //一个一个加上来,求一个最大值
f[j] = max(f[j], f[j - v[i]] + w[i]);
cout << f[m] << endl;
return 0;
}

View File

@@ -0,0 +1,34 @@
#include <bits/stdc++.h>
using namespace std;
const int N = 110;
int a[N];
int n, m;
int cnt;
/**
测试数据:
5 1
答案:
3
*/
void dfs(int u, int s1, int s2) {
//收集答案
if (u == n + 1) {
if (s1 - s2 == m) cnt++;
return;
}
//选择了当前的数字
dfs(u + 1, s1 + a[u], s2);
//放弃了当前的数字
dfs(u + 1, s1, s2 + a[u]);
}
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++) a[i] = i;
dfs(1, 0, 0);
cout << cnt << endl;
return 0;
}

View File

@@ -0,0 +1,38 @@
#include <bits/stdc++.h>
using namespace std;
int n, m;
int cnt;
vector<int> p1, p2;
/**
测试数据:
5 1
答案:
3
*/
void dfs(int u) {
//收集答案
if (u == n + 1) {
int s1 = 0, s2 = 0;
for (int i = 0; i < p1.size(); i++)
s1 += p1[i];
for (int i = 0; i < p2.size(); i++)
s2 += p2[i];
if (s1 - s2 == m)
cnt++;
return;
}
p1.push_back(u);
dfs(u + 1);
p1.pop_back();
p2.push_back(u);
dfs(u + 1);
p2.pop_back();
}
int main() {
cin >> n >> m;
dfs(1);
cout << cnt << endl;
return 0;
}

View File

@@ -0,0 +1,18 @@
#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
int a[N];
int n, cnt;
int main() {
cin >> n;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= 2 * n; j++)
if (j % i == 0)a[j] = !a[j];
for (int i = 1; i <= 2 * n; ++i)
if (a[i]) cnt++;
printf("%d", cnt);
return 0;
}

View File

@@ -0,0 +1,21 @@
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
for (int i = 1; i < n; i++) {
for (int j = 1; j < 2 * n; j++) {
if (i == j || i + j == 2 * n)
cout << "*";
else
cout << " ";
}
cout << endl;
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j < n; j++) cout << " ";
cout << "*" << endl;
}
return 0;
}

View File

@@ -0,0 +1,26 @@
#include <bits/stdc++.h>
using namespace std;
const int N = 2000;
/*
4
-1 3 5 3
3
*/
int a[N];
int k, n, x;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
cin >> x;
for (int i = 1; i <= n; i++) {
if (a[i] == x) {
k = i;
printf("%d", k);
break;
}
}
if (k == 0)
printf("-1");
return 0;
}

View File

@@ -0,0 +1,35 @@
#include<iostream>
using namespace std;
string a, b;
int cnt, p = -1;
/**
* to tomato不能匹配!
* @return
*/
int main() {
//读入带空格的字符串
getline(cin, a);
getline(cin, b);
//a字符串转小写
a = ' ' + a + ' ';
for (int i = 0; i < a.size(); i++)
if (a[i] >= 'A' && a[i] <= 'Z') a[i] = a[i] + 32;
//b字符串转小写
b = ' ' + b+' ';
for (int i = 0; i < b.size(); i++)
if (b[i] >= 'A' && b[i] <= 'Z') b[i] = b[i] + 32;
//在b字符串查找
for (int i = 0; i < b.size(); i++)
if (b.substr(i, a.size()) == a) {
cnt++;
//记录第一个位置
if (p == -1)p = i;
}
//输出
if (cnt > 0) cout << cnt << " " << p << endl;
else cout << -1 << endl;
return 0;
}

View File

@@ -0,0 +1,50 @@
#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
int a[N];
int n;
//最大值
int Max;
/**
测试用例:
3
130 200 55
最多投进球的个数
答案:2
*/
/**
* 功能:深度优先搜索
* @param step 选择了哪个篮筐
* @param last 前面最后一个数字是多少
* @param cnt 已经投中了多少个球
*/
void dfs(int u, int last, int cnt) {
//如果越界
if (u == n + 1) {
//更新最大长度
Max = max(Max, cnt);
return;
}
//如果可以选择当前篮筐,并且选择了当前篮筐
if (a[u] < last)
dfs(u + 1, a[u], cnt + 1);
//放弃当前篮筐
dfs(u + 1, last, cnt);
}
int main() {
//输入
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
//深度优先
dfs(1, INT_MAX, 0);
//输出最大值
cout << Max << endl;
return 0;
}

View File

@@ -0,0 +1,52 @@
#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
int a[N];
int n;
//最大值
int cnt;
//路径
vector<int> path;
/**
测试用例:
3
130 200 55
最多投进球的个数
答案:2
*/
/**
* 功能:深度优先搜索
* @param step 选择了哪个篮筐
*/
void dfs(int step) {
//如果越界
if (step == n + 1) {
//更新最大长度
cnt = max(cnt, (int) path.size());
return;
}
//如果选择了当前篮筐
//是不是可以选择这个位置
if (path.empty() || a[step] < a[path.back()]) {
path.push_back(step);//选择了第几个篮筐
dfs(step + 1);
path.pop_back();//回溯
}
//不选择当前篮筐
dfs(step + 1);
}
int main() {
//输入
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
//深度优先
dfs(1);
//输出最大值
cout << cnt << endl;
return 0;
}

View File

@@ -0,0 +1,25 @@
#include <bits/stdc++.h>
using namespace std;
const int N = 15;
double a[N], c[N], d[N];
int b[N], cl, dl;
int main() {
int n = 10;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) cin >> b[i];
for (int i = 1; i <= n; i++)
if (b[i] == 1)
c[++cl] = a[i];
else
d[++dl] = a[i];
sort(c + 1, c + 1 + 5);
sort(d + 1, d + 1 + 5, greater<double>());
for (int i = 1; i <= 5; i++)
printf("%d %.2f\n", 1, c[i]);
for (int i = 1; i <= 5; i++)
printf("%d %.2f\n", 1, c[i]);
return 0;
}

View File

@@ -0,0 +1,53 @@
/*
果园里有两种水果,苹果(1)和梨子(2),起点(6)也是苹果。
从起点开始,不能碰到梨子,求最多能摘到多少个苹果。
输入:
3 4
2 1 2 1
1 6 1 2
1 1 1 2
输出:
7
*/
#include <bits/stdc++.h>
using namespace std;
const int N = 110;
typedef pair<int, int> PII;
int a[N][N];
int n, m;
int x, y;
int dx[] = {-1, 0, 1, 0}; //上右下左
int dy[] = {0, 1, 0, -1}; //上右下左
int bfs(int x, int y) {
queue<PII> q;
int cnt = 1;
q.push({x, y});
a[x][y] = 2;
while (q.size()) {
auto t = q.front();
q.pop();
for (int i = 0; i < 4; i++) {
int tx = t.first + dx[i], ty = t.second + dy[i];
if (tx == 0 || tx > n || ty == 0 || ty > m) continue;
if (a[tx][ty] == 1) {
q.push({tx, ty});
a[tx][ty] = 2;
cnt++;
}
}
}
return cnt;
}
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) {
cin >> a[i][j];
if (a[i][j] == 6) x = i, y = j;
}
cout << bfs(x, y) << endl;
return 0;
}

View File

@@ -0,0 +1,28 @@
#include <bits/stdc++.h>
/*
一个正整数如果任何一个数位不大于右边相邻的数位,则称为一个数位递增的数,
例如1135是一个数位递增的数,而1024不是一个数位递增的数。
给定正整数 n,请问在整数 11 至 n 中有多少个数位递增的数?
*/
using namespace std;
int n, cnt;
bool iSDiZeng(int t) {
//哨兵
int x = 10; //这里定义x为10,是为了便于将个位数的大小与t作比较,
//个位数永远小于10
while (t) {
if (t % 10 > x) return false;
x = t % 10; // x一直在更新
t /= 10; // n分解出一个数便舍去一个数
}
return true;
}
int main() {
cin >> n;
for (int i = 11; i <= n; i++)
if (iSDiZeng(i)) cnt++;
cout << cnt << endl;
return 0;
}

View File

@@ -0,0 +1,25 @@
#include <bits/stdc++.h>
using namespace std;
/*
输入:8
答案:3
*/
int n;
int res;
// r:待分拆的数字
// last:记录上一个分拆的数字是什么
void dfs(int u, int r, int last) {
if (u == 4) {
if (r == 0) res++; //如果完成分拆的数字恰好等于n,说明是成功的分拆,否则就是没用完有剩余
return;
}
for (int i = last + 1; i <= r; i++) //必须大于上一个,才能保证唯一不重复
if (i != 3 && i != 7) dfs(u + 1, r - i, i); //当前位置不能分配3和7
}
int main() {
cin >> n;
dfs(1, n, 0); //站在第1个箱子面前,待分拆的数是n,上一个分拆完的数字是0,
printf("%d\n", res);
return 0;
}

View File

@@ -0,0 +1,25 @@
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
//欧拉筛
const int N = 1e5 + 10;
int primes[N], cnt; // primes[]存储所有素数
bool st[N]; // st[x]存储x是否被筛掉
void get_primes(int n) {
for (int i = 2; i <= n; i++) {
if (!st[i]) primes[cnt++] = i;
for (int j = 0; primes[j] * i <= n; j++) {
st[primes[j] * i] = true;
if (i % primes[j] == 0) break;
}
}
}
int main() {
get_primes(200);
for (int i = 0; i < cnt; i++)
if (primes[i] > 100)
cout << primes[i] << " ";
return 0;
}

View File

@@ -0,0 +1,45 @@
#include <iostream>
using namespace std;
/**
3 0
165 175 163
155 165 157
答案:4
*/
int n, k;
const int N = 110;
int a[N], b[N];
int cnt;
int st[N];
void dfs(int u, int s) {
if (u == n + 1) {
cnt++;
return;
}
for (int i = 1; i <= n; i++) {
if (!st[i]) {
if (a[u] >= b[i]) {
st[i] = 1;
dfs(u + 1, s);
st[i] = 0;
}
if (a[u] < b[i] && s < k) {
st[i] = 1;
dfs(u + 1, s + 1);
st[i] = 0;
}
}
}
}
int main() {
cin >> n >> k;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) cin >> b[i];
dfs(1, 0);
printf("%d\n", cnt);
return 0;
}

View File

@@ -0,0 +1,30 @@
#include <bits/stdc++.h>
using namespace std;
//是不是水仙花数
bool isSXH(int n) {
int s = 0, m;
m = n;
while (m) {
int a = m % 10;
s += a * a * a;
m /= 10;
}
return s == n;
}
/**
* 测试用例:1000
输出:
153
370
371
407
*/
int main() {
int n;
cin >> n;
for (int i = 2; i <= n; i++)
if (isSXH(i)) cout << i << endl;
return 0;
}

View File

@@ -0,0 +1,79 @@
#include <bits/stdc++.h>
/*油漆面积
X星球的一批考古机器人正在一片废墟上考古。该区域的地面坚硬如石、平整如镜。
管理人员为方便,建立了标准的直角坐标系。每个机器人都各有特长、身怀绝技。它们感兴趣的内容也不相同。
经过各种测量,每个机器人都会报告一个或多个矩形区域,作为优先考古的区域。
矩形的表示格式为(x1,y1,x2,y2),代表矩形的两个对角点坐标。
为了醒目,总部要求对所有机器人选中的矩形区域涂黄色油漆。
小明并不需要当油漆工,只是他需要计算一下,一共要耗费多少油漆。
其实这也不难,只要算出所有矩形覆盖的区域一共有多大面积就可以了。
注意,各个矩形间可能重叠。
本题的输入为若干矩形,要求输出其覆盖的总面积。
输入格式:
第一行,一个整数n,表示有多少个矩形(1<=n<10000)
接下来的n行,每行有4个整数x1 y1 x2 y2,空格分开,表示矩形的两个对角顶点坐标。
(0<= x1,y1,x2,y2 <=10000)
输出格式:
一行一个整数,表示矩形覆盖的总面积面积。
例如,
测试用例:
2
2 2 9 5
6 1 12 9
答案:
60
输入:
3
1 5 10 10
3 1 20 20
2 7 15 17
程序应该输出:
340
再例如,
输入:
3
5 2 10 6
2 7 12 10
8 1 15 15
程序应该输出:
128
I 暴力解法
https://www.bilibili.com/video/BV1VV411z7S2?p=11
II 高端解法
https://www.bilibili.com/video/BV1VV411z7S2?p=12
线段树+扫描线 模板题 (百度一下线段树+扫描线,可以看到还有很多求周长的东西~)
*/
using namespace std;
const int N = 1e4 + 10; //矩形的数量
int n, sum;
// 65536kb /1024 =64mb
// int p[N][N]; //10000*10000*4 byte =4 0000 0000 byte /1024/1024=381MB
// 0 1
bool p[N][N]; //这里需要估算一下空间,因为int是8个bit,bool是1个bit。
//模拟,对于(x1,y1)->(x2,y2)内的所有单元格,都标识为已被刷过油漆
//注意一下这里坐标与单元格的映射关系,就把每个单元格的左下角坐标认为是单元格的编号
void paint(int x1, int y1, int x2, int y2) {
for (int i = x1; i < x2; i++)
for (int j = y1; j < y2; j++)
p[i][j] = 1;
}
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
paint(x1, y1, x2, y2);
}
for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++)
if (p[i][j]) sum++;
cout << sum << endl;
return 0;
}

View File

@@ -0,0 +1,54 @@
#include <bits/stdc++.h>
using namespace std;
int n;
const int N = 110;
const int INF = 0x3f3f3f3f;
int st[N];
int a[N];
int res = -INF;
/*
测试用例:
5 
答案:
6 
*/
void dfs(int u, int r, int last) {
//递归出口
if (r == 0) {
if (u >= 2) {
// 输出每个拆分办法
// for (int i = 0; i < u - 1; i++) cout << a[i] << " * ";
// cout << a[u - 1];
//计算累乘积
int t = 1;
for (int i = 0; i < u; i++) t *= a[i];
// cout << " = " << t << endl;
//猴子选大王
res = max(res, t);
}
return;
}
for (int i = last + 1; i <= r; i++) {
if (!st[i]) {
st[i] = true;
a[u] = i;
dfs(u + 1, r - i, i);
a[u] = 0;
st[i] = false;
}
}
}
int main() {
cin >> n;
dfs(0, n, 0);
printf("%d\n", res);
return 0;
}

View File

@@ -0,0 +1,16 @@
#include <bits/stdc++.h>
using namespace std;
const int N = 10;
int a[N];
/*
3 2 5 5 4
*/
int main() {
int n = 5;
for (int i = 1; i <= n; i++) cin >> a[i];
sort(a + 1, a + 1 + n, greater<int>());
for (int i = 1; i < n; i++) printf("%d,", a[i]);
printf("%d", a[n]);
return 0;
}

View File

@@ -0,0 +1,25 @@
#include <bits/stdc++.h>
using namespace std;
/*
测试用例:
10
数量:
10
示例:1 1 1 1 2 3 4 5 7 10
*/
const int N = 110;
int a[N] = {0, 1, 1, 1, 1};
int main() {
int n;
cin >> n;
for (int i = 5; i <= n; i++)
a[i] = a[i - 1] + a[i - 4];
// for (int i = 1; i <= n; i++) printf("%d ", a[i]);
// puts("");
printf("%d\n", a[n]);
return 0;
}

View File

@@ -0,0 +1,14 @@
#include <bits/stdc++.h>
using namespace std;
// 7259
int main() {
int n;
cin >> n;
int h = n / 3600;
int m = (n - h * 3600) / 60;
int s = n - h * 3600 - m * 60;
printf("%02d:%02d:%02d\n", h, m, s);
return 0;
}

View File

@@ -0,0 +1,23 @@
#include <iostream>
using namespace std;
int n; // 换回来的饮料数量
int sum; // 喝到总数
int t; // 空瓶数量
int main() {
cin >> n;
while (n) {
//① 统计上轮结果
sum += n; // 上轮换回来的可以喝到
t += n; // 当前手中酒瓶 = 原空瓶数量+上轮换回
//② 本轮换取开始
n = t / 3; // 换回来的饮料数量
t %= 3; // 剩余空瓶
}
//输出
printf("%d", sum);
return 0;
}

View File

@@ -0,0 +1,43 @@
#include <bits/stdc++.h>
using namespace std;
struct Node {
int num;
int step;
};
const int N = 1010;
int n, m;
queue<Node> q;
int st[N];
void bfs() {
q.push({n, 0});
while (q.size()) {
auto x = q.front();
q.pop();
if (x.num == m) {
printf("%d\n", x.step);
break;
}
if (!st[x.num + 1]) {
q.push({x.num + 1, x.step + 1});
st[x.num + 1] = 1;
}
if (!st[x.num - 1]) {
q.push({x.num - 1, x.step + 1});
st[x.num - 1] = 1;
}
if (!st[x.num * 2]) {
q.push({x.num * 2, x.step + 1});
st[x.num * 2] = 1;
}
}
}
int main() {
cin >> n >> m;
bfs();
return 0;
}

View File

@@ -0,0 +1,12 @@
#include <bits/stdc++.h>
using namespace std;
int main() {
char c;
int n;
scanf("%c %d", &c, &n);
if (c + n > 'z') printf("*");
else printf("%c", c + n);
return 0;
}

View File

@@ -0,0 +1,25 @@
#include <bits/stdc++.h>
using namespace std;
int n;
queue<int> q;
int cnt; //当前轮次第几个
int main() {
cin >> n;
//为啥这里把所有人员都入队列呢?当面要解释清楚
for (int i = 1; i <= n; i++) q.push(i);
//如果还剩余大于1个
while (q.size() > 1) {
//取出一个
int t = q.front();
q.pop();
cnt++;//点了一个数
if (cnt == 3) cnt = 0;
else q.push(t);
}
//输出最后一个
cout << q.front();
return 0;
}

View File

@@ -0,0 +1,44 @@
#include <bits/stdc++.h>
/*
测试用例I:
5 3 3
答案:
2 4 5 7 8
测试用例II:
5 4 3
5 7 8 1 2
这个测试用例可以看出由小到大排序的意义。
*/
using namespace std;
const int N = 1010;
int a[N], al;
int main() {
int x, y, k;
cin >> x >> y >> k;
queue<int> q;
int cnt = 0;
for (int i = 1; i <= x + y; i++) q.push(i);
while (q.size() > x) {
auto t = q.front();
q.pop();
cnt++;
if (cnt % k > 0)
q.push(t);
else
cnt = 0;
}
while (q.size()) {
auto t = q.front();
q.pop();
a[al++] = t;
}
sort(a, a + al);
for (int i = 0; i < al; i++) cout << a[i] << " ";
return 0;
}

View File

@@ -0,0 +1,33 @@
#include <bits/stdc++.h>
using namespace std;
/*
3
3 84
1 87
2 84
输出样例
1 87
2 84
3 84
*/
const int N = 1010;
struct Node {
int id;
int score;
const bool operator<(const Node &b) const {
if (score == b.score) return id < b.id;
return score > b.score;
}
} a[N];
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i].id >> a[i].score;
sort(a + 1, a + 1 + n);
for (int i = 1; i <= n; i++) printf("%d %d\n", a[i].id, a[i].score);
return 0;
}

View File

@@ -0,0 +1,16 @@
#include <bits/stdc++.h>
using namespace std;
string s;
int main() {
cin >> s;
for (int i = 0; i < s.size(); i++)
if (s[i] >= 'A' && s[i] <= 'Z') s[i] += 32;
int cnt = 0;
for (int i = 0; i < s.size(); i++)
if (s.substr(i, 4) == "lqbs") cnt++;
cout << cnt << endl;
return 0;
}

19
TangDou/KaoShi/质数.cpp Normal file
View File

@@ -0,0 +1,19 @@
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
//判断一个数是不是质数
bool isPrime(int n) {
if (n < 2) return false;
for (int i = 2; i <= n / i; i++)
if (n % i == 0) return false;
return true;
}
/*
for (int i = 100; i <= 200; i++)
if (isPrime(i)) cout << i << " ";
*/
int main() {
return 0;
}

View File

@@ -0,0 +1,23 @@
#include <iostream>
using namespace std;
const int N = 110;
int a[N];
/*
9 4 3 8 8 9 11 9 8 5
10
*/
int n;
int res = -1;
int main() {
for (int i = 1; i <= 10; i++) cin >> a[i];
cin >> n;
for (int i = 1; i <= 10; i++)
for (int j = i + 1; j <= 10; j++)
if (a[i] + a[j] <= n)
res = max(res, a[i] + a[j]);
printf("%d", res);
return 0;
}

View File

@@ -0,0 +1,15 @@
#include <bits/stdc++.h>
using namespace std;
int main() {
string ans = "DCBAD";
int s = 0;
string c;
cin >> c;
for (int i = 0; i < 5; i++)
if (c[i] == ans[i]) s += 30;
cout << s << endl;
return 0;
}