diff --git a/.gitignore b/.gitignore index 6c13913..a7c0d4e 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,4 @@ .vscode/* template/* *.zip -*/datas/* \ No newline at end of file +*/datas/* 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/2/main.c b/2/main.c new file mode 100644 index 0000000..97e9e75 --- /dev/null +++ b/2/main.c @@ -0,0 +1,106 @@ +#include +#include + +int state = 0; +int v[16]; +char labels[4][16] = {"农夫", "狼", "羊", "菜"}; +int re[16]; +int xx[16]; +int k = 0; + +void pt(int state) { + for (int i = 0; i < 4; i++) { + printf("%d ", (state >> i) & 1); + } + printf("\n"); +} + +int validate_state(int state) { + int *f = malloc(sizeof(int) * 4); + for (int i = 0; i < 4; i++) { + f[i] = (state >> i) & 1; + // printf("%d ", f[i]); + } + // printf("\n"); + if (!f[1] ^ f[2] && f[0] ^ f[1]) { + return 0; + } else if (!f[2] ^ f[3] && f[0] ^ f[2]) { + return 0; + } else { + return 1; + } +} + +int trans(int x, int undo) { + // 0 表示农夫自己过河 + // 1 表示带狼过河 + // 2 表示带羊过河 + // 3 表示带菜过河 + int tmp_state = state; + if (x == 1) { + tmp_state = state ^ 3; + } else if (x == 2) { + tmp_state = state ^ 5; + } else if (x == 3) { + tmp_state = state ^ 9; + } else { + tmp_state = state ^ 1; + } + // pt(state); + // printf("%d > ", x); + // pt(tmp_state); + if (undo) { + v[tmp_state] = 0; + state = tmp_state; + re[--k] = 0; + xx[k] = 0; + return 1; + } + if (validate_state(tmp_state) == 0) { + return 0; + } + if (v[tmp_state] == 0) { + v[tmp_state] = 1; + state = tmp_state; + xx[k] = x; + re[k++] = state; + return 1; + } + return 0; +} + +void dfs() { + // printf(">> %d\n", state); + if (state == 15) { + for(int i = 0; i < k; i++) { + printf("%d > ", xx[i]); + pt(re[i]); + } + printf("\n"); + return; + } + if (trans(0, 0)) { + dfs(); + trans(0, 1); + } + if (trans(1, 0)) { + dfs(); + trans(1, 1); + } + if (trans(2, 0)) { + dfs(); + trans(2, 1); + } + if (trans(3, 0)) { + dfs(); + trans(3, 1); + } +} + +int main() { + // freopen("data.in", "r", stdin); + // freopen("data.out", "w", stdout); + v[0] = 1; + dfs(); + return 0; +} \ 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