From 34375a645783abebeb429b67b18ae11e0e913b87 Mon Sep 17 00:00:00 2001 From: Luthics Date: Tue, 28 Nov 2023 15:40:34 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E9=83=A8=E5=88=86=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 ++- 13/main.c | 1 + 3/key.h | 2 ++ 3/main.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4/main.c | 42 ++++++++++++++++++++++++++++++++ 5/main.c | 34 ++++++++++++++++++++++++++ 6/main.c | 0 7 files changed, 151 insertions(+), 1 deletion(-) create mode 100644 13/main.c create mode 100644 3/key.h create mode 100644 3/main.c create mode 100644 4/main.c create mode 100644 5/main.c create mode 100644 6/main.c diff --git a/.gitignore b/.gitignore index adb36c8..0cfb526 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -*.exe \ No newline at end of file +*.exe +.vscode/* \ No newline at end of file diff --git a/13/main.c b/13/main.c new file mode 100644 index 0000000..60ac95e --- /dev/null +++ b/13/main.c @@ -0,0 +1 @@ +// Ref: P1605 迷宫 \ No newline at end of file diff --git a/3/key.h b/3/key.h new file mode 100644 index 0000000..ef30be2 --- /dev/null +++ b/3/key.h @@ -0,0 +1,2 @@ +#define LEFT_ARROW 0x50 +#define RIGHT_ARROW 0x4F diff --git a/3/main.c b/3/main.c new file mode 100644 index 0000000..bb3fc5a --- /dev/null +++ b/3/main.c @@ -0,0 +1,70 @@ +#include +#include +#include + +#define MAX_COLUMN 20 +#define MAX_ROW 20 + +typedef struct { + int current_width; + int current_height; + int column_width[MAX_COLUMN]; + int row_height[MAX_ROW]; + +} TableInfo; + +void init_table(int width, int height, TableInfo *table) { + table->current_width = width; + table->current_height = height; + for (int i = 0; i < width; i++) { + table->column_width[i] = 5; + } + for (int i = 0; i < height; i++) { + table->row_height[i] = 5; + } +} + +void drawGUI(int currentSelection) { + system("cls"); // 清除控制台屏幕 + + printf("======== GUI ========\n"); + printf("| |\n"); + printf("| [ ] [ ] |\n"); + printf("| |\n"); + printf("=====================\n"); + + if (currentSelection == 0) { + printf(" ^ \n"); // 显示指向第一个方块被选中 + } else { + printf(" \n"); + } + + if (currentSelection == 1) { + printf(" ^ \n"); // 显示指向第二个方块被选中 + } else { + printf(" \n"); + } +} + +int main() { + int currentSelection = 0; + int keyPressed; + + while (1) { + drawGUI(currentSelection); + + keyPressed = getch(); // 获取键盘输入 + + if (keyPressed == 224) { // 特殊键 + keyPressed = getch(); // 获取特殊键码 + + if (keyPressed == 75) { // ←键 + currentSelection = (currentSelection - 1) % 2; // 向左选择方块 + } else if (keyPressed == 77) { // →键 + currentSelection = (currentSelection + 1) % 2; // 向右选择方块 + } + } + } + + return 0; +} diff --git a/4/main.c b/4/main.c new file mode 100644 index 0000000..5f3b99f --- /dev/null +++ b/4/main.c @@ -0,0 +1,42 @@ +#include +#include + +int ans, a[10005]; +int n; +int cx[100], zx[100], col[100]; + +void dfs(int x) { + if (x > n) { + ans++; + if (ans <= 3) { + for (int i = 1; i <= n; i++) { + printf("%d ", a[i]); + } + printf("\n"); + } + return; + } + for (int i = 1; i <= n; i++) { + int l = x + i, r = x - i + 15; + if (cx[r] == 0 && zx[l] == 0 && col[i] == 0) { + a[x] = i; + cx[r] = 1; + zx[l] = 1; + col[i] = 1; + dfs(x + 1); + cx[r] = 0; + zx[l] = 0; + col[i] = 0; + } + } +} + +int main() { + scanf("%d", &n); + dfs(1); + printf("%d", ans); + return 0; +} + +// Ref: P1219 [USACO1.5] 八皇后 Checker Challenge +// https://www.luogu.com.cn/record/40132197 \ No newline at end of file diff --git a/5/main.c b/5/main.c new file mode 100644 index 0000000..37dd83d --- /dev/null +++ b/5/main.c @@ -0,0 +1,34 @@ +#include +#include + +int rs[105],n,m,xcz; + +int zj(int a){ + a++; + if(a>n) a-=n; + while(rs[a]==0&&xcz>0){ + a++; + if(a>n) a-=n; + } + return a; +} + +int main(){ + //freopen("title.txt","r",stdin); + scanf("%d%d",&n,&m); + xcz=n; + for(int i=1;i<=n;i++) rs[i]=1; + for(int i=m;xcz>0;){ + if(rs[i]==1){ + rs[i]=0; + xcz--; + printf("%d ",i); + } + int ls=m; + while(ls--) i=zj(i); + } + return 0; +} + +// 尚未修改到课程版本 +// Ref: P1996 约瑟夫问题 \ No newline at end of file diff --git a/6/main.c b/6/main.c new file mode 100644 index 0000000..e69de29