From 6c71fe22b92a3576a27887f3c67d188e38a7459c Mon Sep 17 00:00:00 2001 From: zhangzc Date: Tue, 19 Oct 2021 21:15:06 +0800 Subject: [PATCH] add exercises --- .../desc.md" | 35 + .../solution.java" | 49 + .../REPEAT \347\250\213\345\272\217/desc.md" | 1020 +++++++++++++++++ .../solution.cpp" | 56 + .../RSA \350\247\243\345\257\206/desc.md" | 10 + .../solution.cpp" | 109 ++ .../desc.md" | 22 + .../solution.cpp" | 22 + .../config.json" | 6 - .../desc.md" | 0 .../solution.cpp" | 0 .../solution.java" | 0 .../desc.md" | 41 + .../solution.cpp" | 98 ++ .../desc.md" | 6 + .../solution.cpp" | 25 + .../desc.md" | 7 + .../solution.cpp" | 23 + .../desc.md" | 9 + .../solution.cpp" | 41 + .../desc.md" | 11 + .../solution.cpp" | 16 + .../desc.md" | 6 + .../solution.java" | 34 + .../desc.md" | 1 + .../solution.cpp" | 43 + .../desc.md" | 7 + .../solution.cpp" | 31 + .../desc.md" | 34 + .../solution.cpp" | 42 + .../desc.md" | 34 + .../solution.cpp" | 27 + .../desc.md" | 39 + .../solution.cpp" | 51 + .../desc.md" | 54 + .../solution.cpp" | 39 + .../desc.md" | 24 + .../solution.cpp" | 28 + .../desc.md" | 75 ++ .../solution.cpp" | 66 ++ .../desc.md" | 4 + .../solution.cpp" | 22 + .../desc.md" | 46 + .../solution.cpp" | 73 ++ .../config.json" | 6 - .../desc.md" | 0 .../solution.cpp" | 0 .../solution.java" | 0 .../desc.md" | 38 + .../solution.java" | 49 + .../desc.md" | 25 + .../solution.cpp" | 42 + .../\345\210\206\346\225\260/desc.md" | 3 + .../\345\210\206\346\225\260/solution.cpp" | 26 + .../desc.md" | 22 + .../solution.cpp" | 28 + .../solution.java" | 27 + .../desc.md" | 23 + .../solution.cpp" | 43 + .../desc.md" | 10 + .../solution.cpp" | 26 + .../desc.md" | 4 + .../solution.cpp" | 12 + .../desc.md" | 2 + .../solution.cpp" | 25 + .../desc.md" | 50 + .../solution.cpp" | 88 ++ .../desc.md" | 9 + .../solution.cpp" | 57 + .../desc.md" | 10 + .../solution.cpp" | 13 + .../desc.md" | 27 + .../solution.cpp" | 31 + .../solution.java" | 23 + .../desc.md" | 39 + .../solution.cpp" | 67 ++ .../desc.md" | 4 + .../solution.cpp" | 20 + .../desc.md" | 44 + .../solution.cpp" | 72 ++ .../desc.md" | 30 + .../solution.cpp" | 43 + .../desc.md" | 7 + .../solution.cpp" | 38 + .../desc.md" | 16 + .../solution.cpp" | 76 ++ .../desc.md" | 3 + .../solution.cpp" | 27 + .../desc.md" | 27 + .../solution.cpp" | 52 + .../desc.md" | 5 + .../solution.cpp" | 19 + .../desc.md" | 2 + .../solution.cpp" | 18 + .../desc.md" | 45 + .../solution.cpp" | 37 + .../desc.md" | 23 + .../solution.cpp" | 55 + .../desc.md" | 10 + .../solution.java" | 12 + .../desc.md" | 41 + .../solution.cpp" | 48 + .../desc.md" | 38 + .../solution.cpp" | 78 ++ .../desc.md" | 52 + .../solution.cpp" | 52 + .../desc.md" | 6 + .../solution.java" | 30 + .../desc.md" | 31 + .../solution.cpp" | 44 + .../desc.md" | 17 + .../solution.cpp" | 74 ++ .../desc.md" | 2 + .../solution.cpp" | 35 + .../desc.md" | 12 + .../solution.cpp" | 21 + .../desc.md" | 7 + .../solution.cpp" | 31 + .../desc.md" | 2 + .../solution.cpp" | 28 + .../desc.md" | 48 + .../solution.cpp" | 39 + .../config.json" | 6 - .../desc.md" | 0 .../solution.cpp" | 0 .../solution.java" | 0 .../desc.md" | 35 + .../solution.cpp" | 45 + .../desc.md" | 3 + .../solution.cpp" | 16 + .../desc.md" | 122 ++ .../solution.cpp" | 51 + .../desc.md" | 32 + .../solution.cpp" | 36 + .../desc.md" | 24 + .../solution.cpp" | 28 + .../desc.md" | 4 + .../solution.cpp" | 84 ++ .../desc.md" | 41 + .../solution.cpp" | 71 ++ .../desc.md" | 27 + .../solution.cpp" | 37 + .../desc.md" | 25 + .../solution.cpp" | 53 + .../\345\257\273\346\211\2762020/desc.md" | 21 + .../solution.cpp" | 69 ++ .../desc.md" | 40 + .../solution.cpp" | 34 + .../desc.md" | 39 + .../solution.cpp" | 45 + .../desc.md" | 33 + .../solution.cpp" | 83 ++ .../desc.md" | 2 + .../solution.cpp" | 22 + .../desc.md" | 1 + .../solution.cpp" | 14 + .../desc.md" | 24 + .../solution.cpp" | 40 + .../desc.md" | 2 + .../solution.cpp" | 18 + .../desc.md" | 35 + .../solution.cpp" | 40 + .../desc.md" | 3 + .../solution.cpp" | 28 + .../desc.md" | 6 + .../solution.cpp" | 16 + .../desc.md" | 15 + .../solution.cpp" | 58 + .../desc.md" | 3 + .../solution.cpp" | 30 + .../desc.md" | 7 + .../solution.cpp" | 44 + .../desc.md" | 15 + .../solution.cpp" | 28 + .../desc.md" | 7 + .../solution.cpp" | 41 + .../\346\216\222\345\272\217/desc.md" | 13 + .../\346\216\222\345\272\217/solution.cpp" | 28 + .../desc.md" | 2 + .../solution.cpp" | 115 ++ .../desc.md" | 1 + .../solution.cpp" | 14 + .../desc.md" | 39 + .../solution.cpp" | 25 + .../desc.md" | 3 + .../solution.cpp" | 33 + .../config.json" | 6 - .../desc.md" | 0 .../solution.cpp" | 0 .../solution.java" | 0 .../desc.md" | 32 + .../solution.cpp" | 50 + .../desc.md" | 18 + .../solution.cpp" | 13 + .../desc.md" | 27 + .../solution.cpp" | 20 + .../desc.md" | 2 + .../solution.java" | 24 + .../desc.md" | 12 + .../solution.cpp" | 38 + .../desc.md" | 6 + .../solution.cpp" | 41 + .../desc.md" | 4 + .../solution.java" | 18 + .../desc.md" | 22 + .../solution.cpp" | 32 + .../desc.md" | 22 + .../solution.cpp" | 27 + .../desc.md" | 3 + .../solution.cpp" | 23 + .../desc.md" | 47 + .../solution.cpp" | 35 + .../desc.md" | 24 + .../solution.cpp" | 80 ++ .../\346\230\216\347\240\201/desc.md" | 32 + .../\346\230\216\347\240\201/solution.cpp" | 47 + .../desc.md" | 1 + .../solution.cpp" | 47 + .../desc.md" | 4 + .../solution.cpp" | 32 + .../desc.md" | 9 + .../solution.cpp" | 33 + .../desc.md" | 55 + .../solution.cpp" | 53 + .../config.json" | 6 - .../desc.md" | 0 .../solution.cpp" | 0 .../solution.java" | 0 .../desc.md" | 4 + .../solution.java" | 39 + .../desc.md" | 6 + .../solution.cpp" | 19 + .../desc.md" | 4 + .../solution.cpp" | 41 + .../desc.md" | 21 + .../solution.cpp" | 34 + .../desc.md" | 16 + .../solution.cpp" | 39 + .../desc.md" | 2 + .../solution.cpp" | 15 + .../desc.md" | 41 + .../solution.cpp" | 38 + .../desc.md" | 18 + .../solution.cpp" | 22 + .../desc.md" | 53 + .../solution.cpp" | 67 ++ .../desc.md" | 44 + .../solution.cpp" | 114 ++ .../desc.md" | 7 + .../solution.cpp" | 17 + .../desc.md" | 3 + .../solution.cpp" | 19 + .../desc.md" | 6 + .../solution.cpp" | 33 + .../desc.md" | 23 + .../solution.cpp" | 32 + .../desc.md" | 8 + .../solution.cpp" | 32 + .../desc.md" | 48 + .../solution.cpp" | 42 + .../desc.md" | 2 + .../solution.cpp" | 16 + .../\347\237\251\351\230\265/desc.md" | 5 + .../\347\237\251\351\230\265/solution.cpp" | 21 + .../desc.md" | 25 + .../solution.cpp" | 117 ++ .../desc.md" | 9 + .../solution.cpp" | 106 ++ .../desc.md" | 32 + .../solution.cpp" | 21 + .../desc.md" | 8 + .../solution.cpp" | 23 + .../desc.md" | 7 + .../solution.cpp" | 20 + .../desc.md" | 12 + .../solution.cpp" | 35 + .../desc.md" | 19 + .../solution.cpp" | 32 + .../desc.md" | 37 + .../solution.cpp" | 32 + .../desc.md" | 11 + .../solution.cpp" | 66 ++ .../desc.md" | 30 + .../solution.cpp" | 62 + .../\347\263\226\346\236\234/desc.md" | 25 + .../\347\263\226\346\236\234/solution.cpp" | 37 + .../desc.md" | 1 + .../solution.cpp" | 23 + .../desc.md" | 12 + .../solution.cpp" | 20 + .../desc.md" | 46 + .../solution.cpp" | 50 + .../\347\273\204\351\230\237/desc.md" | 3 + .../\347\273\204\351\230\237/solution.cpp" | 38 + .../\347\273\263\345\234\210/desc.md" | 3 + .../\347\273\263\345\234\210/solution.cpp" | 36 + .../desc.md" | 3 + .../solution.cpp" | 19 + .../desc.md" | 40 + .../solution.cpp" | 52 + .../desc.md" | 37 + .../solution.cpp" | 30 + .../desc.md" | 43 + .../solution.cpp" | 14 + .../desc.md" | 77 ++ .../solution.cpp" | 30 + .../desc.md" | 39 + .../solution.cpp" | 108 ++ .../desc.md" | 50 + .../solution.cpp" | 51 + .../desc.md" | 3 + .../solution.cpp" | 26 + .../desc.md" | 27 + .../solution.cpp" | 24 + .../desc.md" | 46 + .../solution.cpp" | 68 ++ .../\350\247\243\345\257\206/desc.md" | 10 + .../\350\247\243\345\257\206/solution.cpp" | 82 ++ .../\350\247\243\347\240\201/desc.md" | 28 + .../\350\247\243\347\240\201/solution.cpp" | 29 + .../desc.md" | 61 + .../solution.cpp" | 12 + .../desc.md" | 27 + .../solution.cpp" | 43 + .../desc.md" | 4 + .../solution.cpp" | 44 + .../desc.md" | 3 + .../solution.cpp" | 30 + .../desc.md" | 11 + .../solution.cpp" | 44 + .../desc.md" | 31 + .../solution.cpp" | 33 + .../\350\277\267\345\256\253/desc.md" | 44 + .../\350\277\267\345\256\253/solution.cpp" | 76 ++ .../desc.md" | 14 + .../solution.cpp" | 46 + .../desc.md" | 31 + .../solution.cpp" | 42 + .../desc.md" | 13 + .../solution.cpp" | 100 ++ .../desc.md" | 4 + .../solution.cpp" | 24 + .../desc.md" | 10 + .../solution.cpp" | 84 ++ .../desc.md" | 24 + .../solution.cpp" | 15 + .../desc.md" | 19 + .../solution.cpp" | 48 + .../desc.md" | 53 + .../solution.cpp" | 108 ++ .../desc.md" | 20 + .../solution.cpp" | 160 +++ .../desc.md" | 27 + .../solution.cpp" | 25 + 354 files changed, 11638 insertions(+), 30 deletions(-) delete mode 100644 "data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\270\203\346\256\265\347\240\201/config.json" delete mode 100644 "data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\270\203\346\256\265\347\240\201/desc.md" delete mode 100644 "data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\270\203\346\256\265\347\240\201/solution.cpp" delete mode 100644 "data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\270\203\346\256\265\347\240\201/solution.java" delete mode 100644 "data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\206\231\346\227\245\345\277\227/config.json" delete mode 100644 "data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\206\231\346\227\245\345\277\227/desc.md" delete mode 100644 "data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\206\231\346\227\245\345\277\227/solution.cpp" delete mode 100644 "data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\206\231\346\227\245\345\277\227/solution.java" delete mode 100644 "data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\255\220\344\270\262\345\210\206\345\200\274\345\222\214/config.json" delete mode 100644 "data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\255\220\344\270\262\345\210\206\345\200\274\345\222\214/desc.md" delete mode 100644 "data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\255\220\344\270\262\345\210\206\345\200\274\345\222\214/solution.cpp" delete mode 100644 "data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\255\220\344\270\262\345\210\206\345\200\274\345\222\214/solution.java" delete mode 100644 "data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\225\264\346\225\260\345\260\217\346\213\274\346\216\245/config.json" delete mode 100644 "data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\225\264\346\225\260\345\260\217\346\213\274\346\216\245/desc.md" delete mode 100644 "data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\225\264\346\225\260\345\260\217\346\213\274\346\216\245/solution.cpp" delete mode 100644 "data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\225\264\346\225\260\345\260\217\346\213\274\346\216\245/solution.java" delete mode 100644 "data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\234\200\345\244\247\351\231\215\351\233\250\351\207\217/config.json" delete mode 100644 "data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\234\200\345\244\247\351\231\215\351\233\250\351\207\217/desc.md" delete mode 100644 "data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\234\200\345\244\247\351\231\215\351\233\250\351\207\217/solution.cpp" delete mode 100644 "data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\234\200\345\244\247\351\231\215\351\233\250\351\207\217/solution.java" diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/BST \346\217\222\345\205\245\350\212\202\347\202\271\351\227\256\351\242\230/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/BST \346\217\222\345\205\245\350\212\202\347\202\271\351\227\256\351\242\230/desc.md" index e69de29bb..e280c8a9c 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/BST \346\217\222\345\205\245\350\212\202\347\202\271\351\227\256\351\242\230/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/BST \346\217\222\345\205\245\350\212\202\347\202\271\351\227\256\351\242\230/desc.md" @@ -0,0 +1,35 @@ +#### 问题描述 +给定一棵包含 N 个节点的二叉树,节点编号是 1 ∼ N。其中 i 号节点具有权值 W i ,并且这些节点的权值恰好形成了一棵排序二叉树 (BST)。 +现在给定一个节点编号 K,小明想知道,在这 N 个权值以外,有多少个整数 X (即 X 不等于任何 W i ) 满足:给编号为 K 的节点增加一个权值为 X 的子节点,仍可以得到一棵 BST。 +例如在下图中,括号外的数字表示编号、括号内的数字表示权值。即编号1 ∼ 4 的节点权值依次是 0、10、20、30。 + +![](https://img-blog.csdnimg.cn/20201010210318917.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L01pbGtMZW9uZw==,size_16,color_FFFFFF,t_70#pic_center) + +如果 K = 1,那么答案为 0。因为 1 号节点已经有左右子节点,不能再增加子节点了。 +如果 K = 2,那么答案为无穷多。因为任何一个负数都可以作为 2 的左子节点。 +如果 K = 3,那么答案为 9。因为 X = 11,12,··· ,19 都可以作为 3 的左子节点。 + +#### 输入格式 +第一行包含 2 个整数 N 和 K。 +以下 N 行每行包含 2 个整数,其中第 i 行是编号为 i 的节点的父节点编号P i 和权值 W i 。注意 P i = 0 表示 i 是根节点。 +输入保证是一棵 BST。 + +#### 输出格式 +一个整数代表答案。如果答案是无穷多,输出 −1。 + +#### 样例输入 +``` +4 3 +0 10 +1 0 +1 20 +3 30 +``` +#### 样例输出 +``` +9 +``` +#### 评测用例规模与约定 +对于 60% 的评测用例,1 ≤ K ≤ N ≤ 100,0 ≤ W i ≤ 200,且 W i 各不相同。 +对于所有评测用例,1 ≤ K ≤ N ≤ 10000,0 ≤ W i ≤ 100000000,且 W i 各不相同。 + diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/BST \346\217\222\345\205\245\350\212\202\347\202\271\351\227\256\351\242\230/solution.java" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/BST \346\217\222\345\205\245\350\212\202\347\202\271\351\227\256\351\242\230/solution.java" index e69de29bb..083e2574b 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/BST \346\217\222\345\205\245\350\212\202\347\202\271\351\227\256\351\242\230/solution.java" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/BST \346\217\222\345\205\245\350\212\202\347\202\271\351\227\256\351\242\230/solution.java" @@ -0,0 +1,49 @@ +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Scanner; + +public class _09BST插入节点问题 { + + public static void main(String[] args) { + + Scanner sc = new Scanner(System.in); + int n = sc.nextInt(); + int k = sc.nextInt(); + int[] parent = new int[n]; + HashMap map = new HashMap(); + for (int i = 0; i < n; i++) { + parent[i] = sc.nextInt(); + map.put(i + 1, sc.nextInt()); + } + ArrayList childs = new ArrayList(); + int rootWeight = map.get(1); + int kWeight = map.get(k); + for (int i = 0; i < parent.length; i++) { + if (k == parent[i]) + childs.add(map.get(i + 1)); + } + // 1.parents不存在的节点就是叶子节点,叶子节点的答案是无穷大 + if (childs.size() == 0) { + System.out.println("叶子节点"); + System.out.println(-1); + return; + } + // 2. 已经有左右孩子,答案是0 + else if (childs.size() == 2) { + System.out.println("已经有左右孩子了"); + System.out.println(0); + return; + } + // 3. 在右子树:k节点有左无右时为-1; 在左子树:k几点有右无左为-1 + else if (childs.size() == 1 && (kWeight > rootWeight && childs.get(0) < kWeight) + || (kWeight < rootWeight && childs.get(0) > kWeight)) { + System.out.println(-1); + return; + } else { + int fatherWeight = map.get(parent[k - 1]); + System.out.println(Math.abs(kWeight - fatherWeight) - 1); + return; + } + } + +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/REPEAT \347\250\213\345\272\217/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/REPEAT \347\250\213\345\272\217/desc.md" index e69de29bb..0fd1f1059 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/REPEAT \347\250\213\345\272\217/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/REPEAT \347\250\213\345\272\217/desc.md" @@ -0,0 +1,1020 @@ +附件 prog.txt 中是一个用某种语言写的程序。附件在本文的末尾。 + +其中 REPEAT k 表示一个次数为 k 的循环。循环控制的范围由缩进表达,从次行开始连续的缩进比该行多的(前面的空白更长的)为循环包含的内容。 + +![](https://img-blog.csdnimg.cn/20210320200704647.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM0MDEzMjQ3,size_16,color_FFFFFF,t_70) + +该片段中从 A = A + 4 所在的行到 A = A + 8 所在的行都在第一行的循环两次中。 + +REPEAT 6: 所在的行到 A = A + 7 所在的行都在 REPEAT 5: 循环中。 + +A = A + 5 实际总共的循环次数是 2 × 5 × 6 = 60 次。 + +请问该程序执行完毕之后,A 的值是多少? + + + +题目给出的 prog.txt 文件: +``` +A = 0 +REPEAT 2: + A = A + 4 + REPEAT 5: + REPEAT 6: + A = A + 5 + A = A + 7 + REPEAT 6: + A = A + 7 + REPEAT 4: + A = A + 2 + A = A + 7 + A = A + 2 + REPEAT 7: + REPEAT 4: + A = A + 8 + A = A + 7 + A = A + 4 + A = A + 5 + A = A + 8 + REPEAT 8: + A = A + 5 + REPEAT 1: + A = A + 2 + REPEAT 7: + A = A + 5 + A = A + 5 + REPEAT 2: + REPEAT 3: + A = A + 1 + A = A + 1 + REPEAT 5: + A = A + 1 + REPEAT 9: + REPEAT 6: + A = A + 5 + A = A + 1 + REPEAT 6: + A = A + 2 + A = A + 8 + A = A + 3 + REPEAT 2: + A = A + 5 + REPEAT 3: + A = A + 9 + REPEAT 1: + A = A + 4 + REPEAT 2: + A = A + 9 + REPEAT 1: + A = A + 6 + A = A + 6 + A = A + 4 + REPEAT 3: + A = A + 7 + A = A + 1 + REPEAT 2: + A = A + 3 + REPEAT 5: + A = A + 2 + A = A + 5 + A = A + 2 + A = A + 4 + A = A + 3 +REPEAT 4: + A = A + 4 + A = A + 3 + A = A + 7 + REPEAT 5: + REPEAT 4: + A = A + 5 + A = A + 7 + REPEAT 5: + A = A + 3 + REPEAT 3: + A = A + 3 + A = A + 1 + A = A + 8 + A = A + 2 + REPEAT 9: + A = A + 5 + REPEAT 1: + A = A + 5 + A = A + 2 + A = A + 8 +A = A + 6 +REPEAT 3: + REPEAT 4: + A = A + 9 + REPEAT 5: + A = A + 2 + A = A + 1 + REPEAT 9: + A = A + 9 + A = A + 2 + REPEAT 1: + A = A + 6 + A = A + 8 + REPEAT 2: + A = A + 9 + A = A + 4 + A = A + 7 + REPEAT 2: + REPEAT 7: + A = A + 3 + A = A + 5 + REPEAT 3: + A = A + 5 + A = A + 3 + A = A + 6 + A = A + 4 + REPEAT 9: + A = A + 2 + A = A + 8 + A = A + 2 + A = A + 3 + REPEAT 2: + REPEAT 8: + A = A + 5 + A = A + 1 + A = A + 6 + A = A + 1 + A = A + 2 + REPEAT 6: + REPEAT 1: + A = A + 3 + REPEAT 1: + A = A + 2 + REPEAT 4: + A = A + 7 + A = A + 1 + A = A + 8 + REPEAT 6: + A = A + 5 + REPEAT 6: + A = A + 3 + REPEAT 2: + A = A + 2 + A = A + 9 + A = A + 7 + REPEAT 9: + A = A + 8 + REPEAT 9: + A = A + 8 + A = A + 9 + A = A + 3 + A = A + 2 + REPEAT 6: + A = A + 3 + REPEAT 9: + A = A + 1 + A = A + 9 + A = A + 5 + REPEAT 2: + A = A + 4 + A = A + 9 + A = A + 8 + REPEAT 5: + A = A + 6 + A = A + 9 + A = A + 1 + REPEAT 1: + A = A + 4 + A = A + 2 + REPEAT 9: + REPEAT 3: + A = A + 4 + REPEAT 7: + A = A + 8 + A = A + 3 + REPEAT 5: + A = A + 9 + REPEAT 8: + A = A + 9 + A = A + 8 + REPEAT 4: + A = A + 7 + A = A + 7 + A = A + 3 +A = A + 5 +REPEAT 6: + A = A + 7 +REPEAT 7: + A = A + 2 + A = A + 2 +A = A + 1 +REPEAT 8: + REPEAT 1: + REPEAT 4: + A = A + 6 + A = A + 6 + A = A + 2 + REPEAT 5: + A = A + 4 + A = A + 8 + A = A + 4 + REPEAT 1: + A = A + 5 + REPEAT 7: + A = A + 8 + REPEAT 6: + A = A + 4 + A = A + 4 + A = A + 8 + REPEAT 4: + A = A + 2 + REPEAT 2: + A = A + 4 + REPEAT 2: + A = A + 3 + REPEAT 1: + A = A + 2 + A = A + 8 + REPEAT 2: + A = A + 7 + REPEAT 8: + A = A + 6 + A = A + 1 + A = A + 7 + REPEAT 8: + A = A + 2 + REPEAT 8: + REPEAT 6: + A = A + 1 + A = A + 6 + REPEAT 2: + A = A + 4 + A = A + 1 + A = A + 7 + A = A + 4 +REPEAT 4: + REPEAT 9: + A = A + 2 + REPEAT 1: + A = A + 2 + A = A + 5 +REPEAT 8: + REPEAT 6: + A = A + 3 + REPEAT 4: + A = A + 1 + A = A + 6 + A = A + 1 + REPEAT 7: + A = A + 7 + REPEAT 7: + A = A + 3 + A = A + 9 + A = A + 1 + A = A + 9 + REPEAT 3: + A = A + 5 + A = A + 5 + A = A + 6 + A = A + 2 + REPEAT 1: + A = A + 4 + REPEAT 2: + A = A + 7 + REPEAT 1: + A = A + 7 + REPEAT 4: + A = A + 7 + A = A + 2 + REPEAT 5: + A = A + 9 + A = A + 1 + A = A + 9 + A = A + 5 + A = A + 9 + REPEAT 5: + A = A + 5 + REPEAT 1: + A = A + 6 + REPEAT 2: + A = A + 3 + A = A + 2 + A = A + 6 + A = A + 8 + A = A + 8 + A = A + 7 + A = A + 5 + A = A + 5 +REPEAT 2: + A = A + 1 + A = A + 7 +A = A + 3 +REPEAT 2: + A = A + 7 +A = A + 1 +A = A + 4 +REPEAT 1: + REPEAT 7: + REPEAT 2: + A = A + 3 + A = A + 5 + A = A + 2 + A = A + 6 + A = A + 1 +A = A + 2 +A = A + 4 +A = A + 9 +REPEAT 1: + A = A + 8 +REPEAT 8: + REPEAT 4: + REPEAT 8: + A = A + 4 + REPEAT 3: + A = A + 1 + A = A + 8 + REPEAT 7: + A = A + 8 + REPEAT 7: + A = A + 7 + A = A + 7 + REPEAT 7: + A = A + 6 + REPEAT 5: + A = A + 9 + A = A + 3 + REPEAT 4: + A = A + 5 + A = A + 5 + A = A + 4 + REPEAT 9: + REPEAT 3: + A = A + 4 + A = A + 3 + A = A + 6 + REPEAT 1: + A = A + 3 + A = A + 3 + A = A + 6 + REPEAT 6: + A = A + 7 + A = A + 7 + A = A + 5 + A = A + 5 + A = A + 1 + A = A + 2 + A = A + 6 + A = A + 6 + REPEAT 9: + A = A + 6 + REPEAT 1: + REPEAT 2: + A = A + 4 + A = A + 7 + REPEAT 3: + A = A + 6 + REPEAT 5: + A = A + 3 + A = A + 6 + REPEAT 9: + A = A + 3 + A = A + 6 + REPEAT 5: + A = A + 8 + A = A + 8 + REPEAT 3: + A = A + 7 + A = A + 9 + A = A + 8 + A = A + 3 + A = A + 3 + A = A + 9 +REPEAT 6: + A = A + 9 +A = A + 1 +REPEAT 4: + REPEAT 1: + A = A + 7 + REPEAT 9: + A = A + 2 + A = A + 9 + A = A + 1 +A = A + 2 +A = A + 8 +A = A + 7 +A = A + 9 +A = A + 6 +REPEAT 4: + REPEAT 2: + A = A + 3 + REPEAT 3: + A = A + 4 + A = A + 4 +REPEAT 6: + A = A + 6 +A = A + 1 +A = A + 5 +A = A + 8 +REPEAT 2: + A = A + 6 + REPEAT 1: + REPEAT 2: + A = A + 2 + REPEAT 3: + A = A + 1 + REPEAT 1: + A = A + 8 + A = A + 7 + A = A + 4 + A = A + 2 + A = A + 8 + A = A + 4 + REPEAT 5: + REPEAT 6: + A = A + 8 + REPEAT 9: + A = A + 5 + A = A + 5 + REPEAT 5: + A = A + 5 + REPEAT 3: + REPEAT 5: + A = A + 4 + REPEAT 4: + A = A + 6 + A = A + 3 + REPEAT 7: + A = A + 3 + A = A + 3 + A = A + 1 + A = A + 7 + A = A + 7 + A = A + 6 + A = A + 5 + A = A + 5 + A = A + 6 + REPEAT 1: + A = A + 9 + A = A + 3 + REPEAT 1: + REPEAT 1: + A = A + 1 + REPEAT 8: + A = A + 5 + REPEAT 8: + A = A + 6 + REPEAT 4: + A = A + 9 + A = A + 4 + REPEAT 2: + A = A + 3 + A = A + 7 + REPEAT 5: + A = A + 7 + A = A + 5 + A = A + 8 + A = A + 7 + A = A + 8 + A = A + 5 + REPEAT 2: + A = A + 5 + A = A + 7 + A = A + 8 +A = A + 5 +A = A + 9 +REPEAT 2: + REPEAT 6: + A = A + 9 + A = A + 1 + A = A + 8 + A = A + 7 + A = A + 1 + A = A + 5 + REPEAT 3: + A = A + 3 + A = A + 9 + A = A + 7 + REPEAT 3: + A = A + 9 + A = A + 1 + REPEAT 6: + A = A + 1 + REPEAT 9: + REPEAT 7: + A = A + 3 + REPEAT 5: + A = A + 5 + A = A + 8 + A = A + 8 + A = A + 1 + A = A + 2 + REPEAT 4: + A = A + 6 + REPEAT 3: + A = A + 3 + A = A + 7 + REPEAT 8: + REPEAT 1: + A = A + 7 + A = A + 8 + A = A + 3 + A = A + 1 +A = A + 2 +A = A + 4 +A = A + 7 +REPEAT 1: + REPEAT 1: + REPEAT 1: + A = A + 4 + A = A + 6 + REPEAT 1: + A = A + 3 + A = A + 9 + A = A + 6 + REPEAT 9: + A = A + 1 + A = A + 6 + REPEAT 5: + A = A + 3 + A = A + 9 + A = A + 5 + A = A + 5 + A = A + 7 + A = A + 2 + REPEAT 2: + A = A + 7 + A = A + 7 + REPEAT 7: + REPEAT 4: + A = A + 6 + A = A + 8 + REPEAT 6: + A = A + 6 + REPEAT 2: + A = A + 1 + A = A + 7 + A = A + 6 + A = A + 7 + REPEAT 4: + REPEAT 7: + A = A + 1 + REPEAT 2: + A = A + 2 + A = A + 5 + A = A + 8 + A = A + 2 +A = A + 1 +A = A + 4 +REPEAT 8: + A = A + 5 +A = A + 6 +REPEAT 7: + REPEAT 6: + REPEAT 9: + A = A + 7 + A = A + 8 + REPEAT 4: + A = A + 6 + A = A + 4 + A = A + 3 + A = A + 6 + REPEAT 9: + A = A + 3 + REPEAT 9: + A = A + 2 + A = A + 7 + A = A + 5 + A = A + 2 +REPEAT 7: + REPEAT 8: + REPEAT 6: + A = A + 4 + A = A + 9 + A = A + 5 + A = A + 3 + A = A + 9 + REPEAT 4: + REPEAT 1: + A = A + 6 + A = A + 8 + REPEAT 1: + A = A + 6 + A = A + 4 + A = A + 6 + REPEAT 3: + A = A + 7 + REPEAT 3: + A = A + 4 + A = A + 4 + A = A + 2 + A = A + 3 + A = A + 7 + REPEAT 5: + A = A + 6 + A = A + 5 + REPEAT 1: + REPEAT 8: + A = A + 5 + REPEAT 3: + A = A + 6 + REPEAT 9: + A = A + 4 + A = A + 3 + REPEAT 6: + REPEAT 2: + A = A + 1 + A = A + 5 + A = A + 2 +A = A + 2 +A = A + 7 +REPEAT 4: + A = A + 7 +A = A + 9 +A = A + 2 +REPEAT 8: + A = A + 9 + REPEAT 9: + REPEAT 2: + A = A + 3 + A = A + 2 + A = A + 1 + A = A + 5 + REPEAT 9: + A = A + 1 + A = A + 3 + A = A + 9 + REPEAT 7: + A = A + 2 + REPEAT 5: + A = A + 9 + A = A + 3 + REPEAT 2: + A = A + 4 + REPEAT 8: + A = A + 9 + REPEAT 5: + A = A + 5 + A = A + 4 + A = A + 2 + A = A + 4 + REPEAT 6: + A = A + 2 + REPEAT 5: + A = A + 7 + A = A + 7 + A = A + 8 + A = A + 3 + REPEAT 8: + A = A + 2 + A = A + 5 + REPEAT 1: + A = A + 8 + A = A + 5 + A = A + 1 + A = A + 1 + A = A + 5 + REPEAT 2: + A = A + 6 + REPEAT 6: + A = A + 9 + A = A + 2 + A = A + 5 + REPEAT 4: + A = A + 7 + A = A + 1 + REPEAT 6: + A = A + 8 + A = A + 4 + REPEAT 3: + REPEAT 2: + A = A + 1 + A = A + 5 + REPEAT 2: + A = A + 7 + REPEAT 9: + A = A + 6 + A = A + 8 + A = A + 9 + A = A + 5 + REPEAT 9: + REPEAT 3: + A = A + 7 + A = A + 7 + A = A + 9 + A = A + 7 + REPEAT 5: + A = A + 7 + A = A + 2 + A = A + 1 + A = A + 8 + A = A + 3 + A = A + 5 +A = A + 1 +REPEAT 8: + A = A + 4 +A = A + 2 +A = A + 2 +A = A + 8 +REPEAT 4: + REPEAT 4: + A = A + 8 + REPEAT 7: + A = A + 5 + A = A + 2 + REPEAT 2: + A = A + 6 + REPEAT 4: + A = A + 8 + A = A + 6 + A = A + 1 + A = A + 3 +A = A + 2 +A = A + 7 +A = A + 4 +REPEAT 8: + A = A + 2 + A = A + 4 +REPEAT 5: + REPEAT 3: + REPEAT 6: + A = A + 8 + A = A + 1 + A = A + 6 + A = A + 5 + A = A + 9 +REPEAT 8: + A = A + 7 +REPEAT 6: + A = A + 4 +A = A + 5 +REPEAT 3: + A = A + 1 + REPEAT 1: + REPEAT 5: + A = A + 6 + A = A + 2 + REPEAT 9: + REPEAT 5: + A = A + 9 + A = A + 3 + REPEAT 9: + A = A + 9 + A = A + 8 + REPEAT 8: + REPEAT 5: + A = A + 9 + A = A + 4 + REPEAT 9: + A = A + 3 + A = A + 4 + A = A + 5 +REPEAT 9: + REPEAT 7: + A = A + 5 + REPEAT 3: + A = A + 7 + REPEAT 9: + REPEAT 6: + A = A + 4 + A = A + 6 + REPEAT 5: + REPEAT 6: + A = A + 5 + A = A + 3 + A = A + 3 + A = A + 3 + A = A + 5 + REPEAT 7: + A = A + 5 + REPEAT 2: + A = A + 5 + A = A + 6 + REPEAT 2: + A = A + 2 + A = A + 5 + A = A + 3 +A = A + 5 +A = A + 5 +REPEAT 4: + A = A + 2 + A = A + 1 + REPEAT 9: + A = A + 9 + A = A + 5 + A = A + 6 + A = A + 2 + A = A + 2 + A = A + 5 + REPEAT 9: + A = A + 5 + A = A + 4 + REPEAT 4: + REPEAT 4: + A = A + 1 + A = A + 2 + REPEAT 6: + A = A + 9 + A = A + 3 + REPEAT 2: + A = A + 5 + A = A + 1 + A = A + 1 + A = A + 3 + A = A + 8 + REPEAT 7: + A = A + 4 + REPEAT 6: + A = A + 9 + REPEAT 5: + A = A + 9 + A = A + 8 + A = A + 3 + A = A + 9 + A = A + 4 + A = A + 6 +REPEAT 7: + A = A + 9 +REPEAT 9: + A = A + 4 + A = A + 9 + A = A + 1 + A = A + 3 + REPEAT 5: + REPEAT 1: + A = A + 4 + A = A + 4 + REPEAT 8: + A = A + 9 + A = A + 6 + A = A + 2 + REPEAT 3: + A = A + 4 + A = A + 4 + REPEAT 3: + A = A + 5 + A = A + 2 + A = A + 8 + A = A + 3 + A = A + 6 + A = A + 4 + A = A + 9 + A = A + 1 + A = A + 9 + A = A + 5 + A = A + 3 + REPEAT 3: + A = A + 2 + A = A + 5 + A = A + 8 + A = A + 2 + A = A + 5 + REPEAT 8: + REPEAT 2: + A = A + 6 + A = A + 7 + A = A + 6 + A = A + 9 + A = A + 2 +REPEAT 2: + A = A + 3 + REPEAT 8: + A = A + 7 + A = A + 2 + A = A + 1 + A = A + 4 + A = A + 1 + A = A + 5 + A = A + 2 + A = A + 1 + REPEAT 1: + A = A + 1 + REPEAT 6: + A = A + 4 + A = A + 3 + A = A + 3 + REPEAT 5: + A = A + 3 + REPEAT 6: + REPEAT 1: + A = A + 5 + A = A + 7 + A = A + 7 + A = A + 7 + REPEAT 5: + A = A + 9 + A = A + 7 + REPEAT 5: + A = A + 9 + A = A + 1 + A = A + 9 + A = A + 8 + REPEAT 1: + A = A + 2 + REPEAT 5: + A = A + 8 + REPEAT 3: + A = A + 2 + A = A + 9 + A = A + 6 + A = A + 3 + REPEAT 5: + REPEAT 6: + A = A + 5 + A = A + 5 + REPEAT 4: + A = A + 5 + A = A + 4 + REPEAT 8: + A = A + 9 + A = A + 1 + REPEAT 8: + A = A + 8 + A = A + 1 + A = A + 4 + REPEAT 6: + A = A + 6 + REPEAT 2: + A = A + 3 + A = A + 9 + A = A + 6 + A = A + 9 + REPEAT 1: + A = A + 4 + REPEAT 3: + A = A + 3 + A = A + 4 + A = A + 2 + A = A + 8 + REPEAT 2: + A = A + 4 + A = A + 1 + REPEAT 9: + A = A + 2 + A = A + 9 + A = A + 7 +REPEAT 7: + REPEAT 7: + REPEAT 5: + A = A + 7 + REPEAT 5: + A = A + 1 + A = A + 1 + REPEAT 5: + A = A + 6 + REPEAT 1: + A = A + 4 + REPEAT 9: + A = A + 4 + A = A + 1 + REPEAT 6: + A = A + 8 + A = A + 5 + REPEAT 1: + A = A + 4 + REPEAT 5: + A = A + 8 + A = A + 7 + A = A + 2 + REPEAT 3: + A = A + 3 + REPEAT 8: + REPEAT 8: + A = A + 4 + A = A + 7 + REPEAT 5: + A = A + 1 + REPEAT 8: + A = A + 7 + A = A + 8 + A = A + 4 + A = A + 7 + A = A + 6 + A = A + 9 + A = A + 5 +REPEAT 3: + A = A + 5 + REPEAT 9: + A = A + 1 + A = A + 7 +REPEAT 1: + A = A + 8 +A = A + 4 +REPEAT 8: + REPEAT 7: + A = A + 2 + REPEAT 4: + A = A + 6 + A = A + 6 + REPEAT 1: + A = A + 7 + A = A + 1 +REPEAT 9: + REPEAT 5: + A = A + 6 + A = A + 5 + REPEAT 7: + A = A + 3 + A = A + 6 + A = A + 8 + REPEAT 2: + A = A + 7 + A = A + 1 + A = A + 9 + REPEAT 3: + REPEAT 3: + A = A + 5 +``` \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/REPEAT \347\250\213\345\272\217/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/REPEAT \347\250\213\345\272\217/solution.cpp" index e69de29bb..73900e9d9 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/REPEAT \347\250\213\345\272\217/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/REPEAT \347\250\213\345\272\217/solution.cpp" @@ -0,0 +1,56 @@ +#include +using namespace std; +const int N = 1e3 + 10; +char mp[N][N]; +int s[N], t[N], top; +int main() +{ + FILE *fp; + fp = fopen("prog.txt", "r"); ///文件读操作 + char ch; + int tot = 0; + int i = 0; + while ((ch = fgetc(fp)) != EOF) ///一个字符一个字符的读入 + { + + if (ch == '\n') + { + mp[tot][i] = '\0'; + tot++; + i = 0; + continue; + } + mp[tot][i++] = ch; + } + /* + for(int i=0;i= p) ///开始新的循环,上一层的循环不包括 + w /= t[top--]; + if (mp[i][len - 1] == ':') ///当前是循环语句 + { + int num = mp[i][len - 2] - '0'; + top++; + w *= num; ///累计循环了几次 + s[top] = p, t[top] = num; ///第top层循环语句的缩进量和循环次数 + } + else + { + int num = mp[i][len - 1] - '0'; + sum += w * num; + } + } + printf("%d\n", sum); + + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/RSA \350\247\243\345\257\206/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/RSA \350\247\243\345\257\206/desc.md" index e69de29bb..d6de86cfb 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/RSA \350\247\243\345\257\206/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/RSA \350\247\243\345\257\206/desc.md" @@ -0,0 +1,10 @@ +RSA是一种经典的加密算法。它的基本加密过程如下。 + +首先生成两个质数p,q, 令$n = p \cdot q$,设d与$(p-1) \cdot (q-1)$互质,则可以找到e,使得$d \cdot e$除以$(p-1) \cdot (q-1)$的余数为1 +n,d,e组成了私钥,n,d构成了公钥。 +当使用公钥加密一个整数X时(X<=n-1),计算$C = X^d$ mod n,则C是加密后的密文。 +当收到密文C时,可以使用私钥解开,计算公式为:$X = C^e$ mod n。 +例如:当p = 5, q = 11, n = 55, e = 27。 +若加密数字24,得$24^3$ % 55 = 19。 +解密数字19,得$19^{27}$ % 55 = 24。 +现在你知道公钥中n = 1001733993063167141,d = 212353,同时,你截获了别人发送的密文C = 20190324,请问,原文是多少? diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/RSA \350\247\243\345\257\206/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/RSA \350\247\243\345\257\206/solution.cpp" index e69de29bb..dae4bfea1 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/RSA \350\247\243\345\257\206/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/RSA \350\247\243\345\257\206/solution.cpp" @@ -0,0 +1,109 @@ +#include +#define LL long long +using namespace std; +const int maxn = 1e8 + 10; +const LL n = 1001733993063167141ll; +const LL p = 891234941ll; +const LL q = 1123984201ll; +const LL d = 212353; +const LL c = 20190324; +int a[maxn]; +int sushu[maxn / 10]; +bool notPrime[maxn]; ///筛素数分解不出来,目测是9位数*10位数 +int cnt; +void getPrime(int n) +{ + for (int i = 2; i <= n; ++i) + { + if (!notPrime[i]) + sushu[cnt++] = i; + for (int j = 0; j < cnt && 1ll * i * sushu[j] <= n; ++j) + { + notPrime[i * sushu[j]] = true; + if (i % sushu[j] == 0) + break; + } + } + for (int i = 0; i < 20; ++i) + cout << sushu[i] << " "; + cout << endl; +} +void fenjie(LL x) +{ + cout << x << " = 1"; + for (int i = 0; i < cnt && sushu[i] <= x / sushu[i]; ++i) + { + while (x % sushu[i] == 0) + { + cout << " * " << sushu[i]; + x /= sushu[i]; + } + } + if (x > 1) + cout << " * " << x; + cout << endl; +} +void BF(LL x) +{ + cout << x << " = "; + for (LL i = 1e8 + 1; i < x; i += 2) + { + if (x % i == 0) + cout << i << " * ", x /= i; + } + cout << x << endl; +} +void exgcd(LL a, LL b, LL &d, LL &x, LL &y) +{ + if (b == 0) + { + d = a; + x = 1; + y = 0; + return; + } + exgcd(b, a % b, d, y, x); + y -= (a / b) * x; +} +LL rev(LL t, LL m) +{ + LL d, x, y; + exgcd(t, m, d, x, y); + return (x % m + m) % m; +} +LL fast_product(LL a, LL b, LL mod) +{ + LL ans = 0; + while (b) + { + if (b & 1) + ans = (ans + a) % mod; + a = (a + a) % mod; + b >>= 1; + } + return ans; +} +LL fast_pow(LL a, LL b, LL mod) +{ + LL ans = 1; + while (b) + { + if (b & 1) + ans = fast_product(ans, a, mod); + a = fast_product(a, a, mod); + b >>= 1; + } + return ans; +} +int main() +{ + //getPrime(maxn-5); + //fenjie(n); + BF(n); + LL y = (p - 1) * (q - 1); + LL e = rev(d, y); + LL answer = fast_pow(c, e, n); + cout << answer << endl; + + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/k\345\200\215\345\214\272\351\227\264/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/k\345\200\215\345\214\272\351\227\264/desc.md" index e69de29bb..7c93b5c0b 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/k\345\200\215\345\214\272\351\227\264/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/k\345\200\215\345\214\272\351\227\264/desc.md" @@ -0,0 +1,22 @@ +#### 问题描述 +给定一个长度为N的数列,$A_1, A_2, … A_N,$如果其中一段连续的子序列$A_i, A_{i+1}, … A_j(i <= j)$之和是K的倍数,我们就称这个区间[i, j]是K倍区间。 + +你能求出数列中总共有多少个K倍区间吗? +#### 输入格式 +第一行包含两个整数N和K。(1 <= N, K <= 100000) +以下N行每行包含一个整数$A_i$。(1 <= $A_i$ <= 100000) +#### 输出格式 +输出一个整数,代表K倍区间的数目。 +#### 样例输入 +``` +5 2 +1 +2 +3 +4 +5 +``` +#### 样例输出 +``` +6 +``` \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/k\345\200\215\345\214\272\351\227\264/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/k\345\200\215\345\214\272\351\227\264/solution.cpp" index e69de29bb..ae7993ed5 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/k\345\200\215\345\214\272\351\227\264/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/k\345\200\215\345\214\272\351\227\264/solution.cpp" @@ -0,0 +1,22 @@ +#include +using namespace std; + +int main() +{ + long long n, k, ans = 0, son[100000], sum[100000], b[100000] = {0}; + cin >> n >> k; + for (int i = 0; i < n; i++) + { + cin >> son[i]; + if (i != 0) + sum[i] = (sum[i - 1] + son[i]) % k; + else + sum[i] = son[i] % k; + b[sum[i]]++; + ans += b[sum[i]] - 1; + if (sum[i] == 0) + ans++; + } + cout << ans; + return 0; +} \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\270\203\346\256\265\347\240\201/config.json" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\270\203\346\256\265\347\240\201/config.json" deleted file mode 100644 index f6416a1a5..000000000 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\270\203\346\256\265\347\240\201/config.json" +++ /dev/null @@ -1,6 +0,0 @@ -{ - "node_id": "569d5e11c4fc5de7844053d9a733c5e8", - "keywords": [], - "children": [], - "export": [] -} \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\270\203\346\256\265\347\240\201/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\270\203\346\256\265\347\240\201/desc.md" deleted file mode 100644 index e69de29bb..000000000 diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\270\203\346\256\265\347\240\201/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\270\203\346\256\265\347\240\201/solution.cpp" deleted file mode 100644 index e69de29bb..000000000 diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\270\203\346\256\265\347\240\201/solution.java" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\270\203\346\256\265\347\240\201/solution.java" deleted file mode 100644 index e69de29bb..000000000 diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\270\211\344\275\223\346\224\273\345\207\273/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\270\211\344\275\223\346\224\273\345\207\273/desc.md" index e69de29bb..eb89f2d40 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\270\211\344\275\223\346\224\273\345\207\273/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\270\211\344\275\223\346\224\273\345\207\273/desc.md" @@ -0,0 +1,41 @@ +#### 题目描述 +三体人将对地球发起攻击。为了抵御攻击,地球人派出了 A × B × C 艘战舰,在太空中排成一个 A 层 B 行 C 列的立方体。其中,第 i 层第 j 行第 k 列的战舰(记为战舰 (i, j, k))的生命值为 d(i, j, k)。 + +三体人将会对地球发起 m 轮“立方体攻击”,每次攻击会对一个小立方体中的所有战舰都造成相同的伤害。具体地,第 t 轮攻击用 7 个参数 $la_t, ra_t, lb_t, rb_t, lc_t, rc_t, h_t $描述; +所有满足$ i ∈ [la_t, ra_t],j ∈ [lb_t, rb_t],k ∈ [lc_t, rc_t] $的战舰 (i, j, k) 会受到 $h_t$ 的伤害。如果一个战舰累计受到的总伤害超过其防御力,那么这个战舰会爆炸。 + +地球指挥官希望你能告诉他,第一艘爆炸的战舰是在哪一轮攻击后爆炸的。 + +#### 输入格式 +从标准输入读入数据。 +第一行包括 4 个正整数 A, B, C, m; +第二行包含 A × B × C 个整数,其中第 ((i − 1)×B + (j − 1)) × C + (k − 1)+1 个数为 d(i, j, k); +第 3 到第 m + 2 行中,第 (t − 2) 行包含 7 个正整数 $la_t, ra_t, lb_t, rb_t, lc_t, rc_t, h_t$。 + +#### 输出格式 +输出到标准输出。 +输出第一个爆炸的战舰是在哪一轮攻击后爆炸的。保证一定存在这样的战舰。 + +#### 样例输入 +``` +2 2 2 3 +1 1 1 1 1 1 1 1 +1 2 1 2 1 1 1 +1 1 1 2 1 2 1 +1 1 1 1 1 1 2 +``` +#### 样例输出 +``` +2 +``` +#### 样例解释 +在第 2 轮攻击后,战舰 (1,1,1) 总共受到了 2 点伤害,超出其防御力导致爆炸。 + +#### 数据约定 +``` +对于 10% 的数据,B = C = 1; +对于 20% 的数据,C = 1; +对于 40% 的数据,A × B × C, m ≤ 10, 000; +对于 70% 的数据,A, B, C ≤ 200; +对于所有数据,A × B × C ≤ 10^6, m ≤ 10^6, 0 ≤ d(i, j, k), ht ≤ 10^9。 +``` \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\270\211\344\275\223\346\224\273\345\207\273/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\270\211\344\275\223\346\224\273\345\207\273/solution.cpp" index e69de29bb..9994ddb3e 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\270\211\344\275\223\346\224\273\345\207\273/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\270\211\344\275\223\346\224\273\345\207\273/solution.cpp" @@ -0,0 +1,98 @@ +#include +#include +#include +using namespace std; + +const int N = 2000010; + +typedef long long LL; +int A, B, C, m; +LL s[N], b[N], bp[N]; +int op[N / 2][7]; + +const int d[8][4] = { + {0, 0, 0, 1}, + {0, 0, 1, -1}, + {0, 1, 0, -1}, + {0, 1, 1, 1}, + {1, 0, 0, -1}, + {1, 0, 1, 1}, + {1, 1, 0, 1}, + {1, 1, 1, -1}}; + +int get(int i, int j, int k) +{ + + return (i * B + j) * C + k; +} + +bool check(int mid) +{ + memcpy(b, bp, sizeof bp); + for (int i = 1; i <= mid; i++) + { + int x1 = op[i][0], x2 = op[i][1], y1 = op[i][2], y2 = op[i][3], z1 = op[i][4], z2 = op[i][5], h = op[i][6]; + b[get(x1, y1, z1)] -= h; + b[get(x1, y1, z2 + 1)] += h; + b[get(x1, y2 + 1, z1)] += h; + b[get(x1, y2 + 1, z2 + 1)] -= h; + b[get(x2 + 1, y1, z1)] += h; + b[get(x2 + 1, y1, z2 + 1)] -= h; + b[get(x2 + 1, y2 + 1, z1)] -= h; + b[get(x2 + 1, y2 + 1, z2 + 1)] += h; + } + + memset(s, 0, sizeof s); + for (int i = 1; i <= A; i++) + for (int j = 1; j <= B; j++) + for (int k = 1; k <= C; k++) + { + s[get(i, j, k)] = b[get(i, j, k)]; + for (int u = 1; u < 8; u++) + { + int x = i - d[u][0], y = j - d[u][1], z = k - d[u][2], t = d[u][3]; + s[get(i, j, k)] -= s[get(x, y, z)] * t; + } + + if (s[get(i, j, k)] < 0) + return true; + } + + return false; +} + +int main() +{ + scanf("%d%d%d%d", &A, &B, &C, &m); + + for (int i = 1; i <= A; i++) + for (int j = 1; j <= B; j++) + for (int k = 1; k <= C; k++) + scanf("%lld", &s[get(i, j, k)]); + + for (int i = 1; i <= A; i++) + for (int j = 1; j <= B; j++) + for (int k = 1; k <= C; k++) + for (int u = 0; u < 8; u++) + { + int x = i - d[u][0], y = j - d[u][1], z = k - d[u][2], t = d[u][3]; + bp[get(i, j, k)] += s[get(x, y, z)] * t; + } + + for (int i = 1; i <= m; i++) + for (int j = 0; j < 7; j++) + scanf("%d", &op[i][j]); + + int l = 1, r = m; + while (l < r) + { + int mid = l + r >> 1; + if (check(mid)) + r = mid; + else + l = mid + 1; + } + + printf("%d\n", r); + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\270\211\347\276\212\347\214\256\347\221\236/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\270\211\347\276\212\347\214\256\347\221\236/desc.md" index e69de29bb..f8b59bae4 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\270\211\347\276\212\347\214\256\347\221\236/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\270\211\347\276\212\347\214\256\347\221\236/desc.md" @@ -0,0 +1,6 @@ +观察下面的加法算式: + +![](https://img-blog.csdnimg.cn/20200323231451860.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MzkxMDMyMA==,size_16,color_FFFFFF,t_70#pic_center) + +其中,相同的汉字代表相同的数字,不同的汉字代表不同的数字。 +请你填写“三羊献瑞”所代表的4位数字(答案唯一) \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\270\211\347\276\212\347\214\256\347\221\236/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\270\211\347\276\212\347\214\256\347\221\236/solution.cpp" index e69de29bb..695acef8f 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\270\211\347\276\212\347\214\256\347\221\236/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\270\211\347\276\212\347\214\256\347\221\236/solution.cpp" @@ -0,0 +1,25 @@ +#include +#include + +using namespace std; +int a[10]; + +int main() +{ + for (int i = 0; i < 10; i++) + a[i] = i; + do + { + if (!a[0] || !a[4]) + continue; //祥、三不能为0 + int t1 = a[0] * 1000 + a[1] * 100 + a[2] * 10 + a[3]; //祥瑞生辉 + int t2 = a[4] * 1000 + a[5] * 100 + a[6] * 10 + a[1]; //三羊献瑞 + int t3 = a[4] * 10000 + a[5] * 1000 + a[2] * 100 + a[1] * 10 + a[7]; //三羊生瑞气 + if (t1 + t2 == t3) + { + cout << t2; + break; + } + } while (next_permutation(a, a + 10)); + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\270\211\350\247\222\345\275\242\351\235\242\347\247\257/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\270\211\350\247\222\345\275\242\351\235\242\347\247\257/desc.md" index e69de29bb..e441291e7 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\270\211\350\247\222\345\275\242\351\235\242\347\247\257/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\270\211\350\247\222\345\275\242\351\235\242\347\247\257/desc.md" @@ -0,0 +1,7 @@ +已知三角形三个顶点在直角坐标系下的坐标分别为: +``` +(2.3,2.5) +(6.4,3.1) +(5.1,7.2) +``` +求该三角形的面积。 \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\270\211\350\247\222\345\275\242\351\235\242\347\247\257/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\270\211\350\247\222\345\275\242\351\235\242\347\247\257/solution.cpp" index e69de29bb..9e482abb3 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\270\211\350\247\222\345\275\242\351\235\242\347\247\257/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\270\211\350\247\222\345\275\242\351\235\242\347\247\257/solution.cpp" @@ -0,0 +1,23 @@ +#include +#include +#include +using namespace std; + +typedef pair PDD; +#define x first +#define y second + +double cross(double x1, double y1, double x2, double y2) +{ + return x1 * y2 - x2 * y1; +} +int main() +{ + PDD pts[3]; + for (int i = 0; i < 3; i++) + { + scanf("%lf%lf", &pts[i].first, &pts[i].second); + } + cout << 0.5 * cross(pts[1].x - pts[0].x, pts[1].y - pts[0].y, pts[2].x - pts[0].x, pts[2].y - pts[0].y) << endl; + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\270\211\351\203\250\346\216\222\345\272\217/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\270\211\351\203\250\346\216\222\345\272\217/desc.md" index e69de29bb..74b1d44fa 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\270\211\351\203\250\346\216\222\345\272\217/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\270\211\351\203\250\346\216\222\345\272\217/desc.md" @@ -0,0 +1,9 @@ +一般的排序有许多经典算法,如快速排序、希尔排序等。但实际应用时,经常会或多或少有一些特殊的要求。我们没必要套用那些经典算法,可以根据实际情况建立更好的解法。 + +比如,对一个整型数组中的数字进行分类排序: + +使得负数都靠左端,正数都靠右端,0在中部。注意问题的特点是:负数区域和正数区域内并不要求有序。可以利用这个特点通过1次线性扫描就结束战斗!! + +以下的程序实现了该目标。 + +其中x指向待排序的整型数组,len是数组的长度。 diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\270\211\351\203\250\346\216\222\345\272\217/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\270\211\351\203\250\346\216\222\345\272\217/solution.cpp" index e69de29bb..9d0ed2564 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\270\211\351\203\250\346\216\222\345\272\217/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\270\211\351\203\250\346\216\222\345\272\217/solution.cpp" @@ -0,0 +1,41 @@ +#include +using namespace std; +void sort3p(int *x, int len) +{ + int p = 0; + int left = 0; + int right = len - 1; + + while (p <= right) + { + if (x[p] < 0) + { + int t = x[left]; + x[left] = x[p]; + x[p] = t; + left++; + p++; + } + else if (x[p] > 0) + { + int t = x[right]; + x[right] = x[p]; + x[p] = t; + right--; + } + else + { + p++; //填空位置 + } + } +} +int main() +{ + int a[10] = {0, -1, 0, 0, -2, 5, 3, 1, 0, 7}; + sort3p(a, 10); + for (int i = 0; i < 10; i++) + { + printf("%d ", a[i]); + } + return 0; +} \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\270\226\347\272\252\346\234\253\347\232\204\346\230\237\346\234\237/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\270\226\347\272\252\346\234\253\347\232\204\346\230\237\346\234\237/desc.md" index e69de29bb..448f9591d 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\270\226\347\272\252\346\234\253\347\232\204\346\230\237\346\234\237/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\270\226\347\272\252\346\234\253\347\232\204\346\230\237\346\234\237/desc.md" @@ -0,0 +1,11 @@ +曾有邪教称1999年12月31日是世界末日。当然该谣言已经不攻自破。 + +还有人称今后的某个世纪末的12月31日,如果是星期一则会.... + +有趣的是,任何一个世纪末的年份的12月31日都不可能是星期一!! + +于是,“谣言制造商”又修改为星期日...... + +1999年的12月31日是星期五,请问:未来哪一个离我们最近的一个世纪末年(即xx99年)的12月31日正好是星期天(即星期日)? + +请回答该年份(只写这个4位整数,不要写12月31等多余信息) diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\270\226\347\272\252\346\234\253\347\232\204\346\230\237\346\234\237/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\270\226\347\272\252\346\234\253\347\232\204\346\230\237\346\234\237/solution.cpp" index e69de29bb..0d40e901d 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\270\226\347\272\252\346\234\253\347\232\204\346\230\237\346\234\237/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\270\226\347\272\252\346\234\253\347\232\204\346\230\237\346\234\237/solution.cpp" @@ -0,0 +1,16 @@ +#include +using namespace std; +int main() +{ + long long sum = 0; + for (int i = 2000;; i++) + { + sum += (i % 4 == 0 && i % 100 != 0 || i % 400 == 0) ? 366 : 365; + if (i % 100 == 99 && sum % 7 == 2) + { + cout << i << endl; + break; + } + } + return 0; +} \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\271\235\346\225\260\345\210\206\344\270\211\347\273\204/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\271\235\346\225\260\345\210\206\344\270\211\347\273\204/desc.md" index e69de29bb..00dce8f8c 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\271\235\346\225\260\345\210\206\344\270\211\347\273\204/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\271\235\346\225\260\345\210\206\344\270\211\347\273\204/desc.md" @@ -0,0 +1,6 @@ +1~9的数字可以组成3个3位数,设为:A,B,C, 现在要求满足如下关系: +``` +B = 2 * A +C = 3 * A +``` +请你写出A的所有可能答案,数字间用空格分开,数字按升序排列。 \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\271\235\346\225\260\345\210\206\344\270\211\347\273\204/solution.java" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\271\235\346\225\260\345\210\206\344\270\211\347\273\204/solution.java" index e69de29bb..7dc4a642e 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\271\235\346\225\260\345\210\206\344\270\211\347\273\204/solution.java" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\271\235\346\225\260\345\210\206\344\270\211\347\273\204/solution.java" @@ -0,0 +1,34 @@ +public class Test004 { + + public static void main(String[] args) { + + for (int a = 111; a <= 333; a++) { + if (hasZero(a)) { + continue; + } else { + int b = 2 * a; + int c = 3 * a; + if (hasZero(b) || hasZero(c)) { + continue; + } + + String s = "" + a + b + c; + if (isFind(s)) { + System.out.print(a + " "); + } + } + } + + } + + private static boolean hasZero(int n) { + return String.valueOf(n).contains("0"); + } + + private static boolean isFind(String x) { + char[] arr = x.toCharArray(); + Arrays.sort(arr); + return "123456789".equals(String.valueOf(arr)); + + } +} \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\271\235\346\225\260\347\273\204\345\210\206\346\225\260/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\271\235\346\225\260\347\273\204\345\210\206\346\225\260/desc.md" index e69de29bb..bc6efd7ac 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\271\235\346\225\260\347\273\204\345\210\206\346\225\260/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\271\235\346\225\260\347\273\204\345\210\206\346\225\260/desc.md" @@ -0,0 +1 @@ +1,2,3…9 这九个数字组成一个分数,其值恰好为1/3,如何组法? \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\271\235\346\225\260\347\273\204\345\210\206\346\225\260/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\271\235\346\225\260\347\273\204\345\210\206\346\225\260/solution.cpp" index e69de29bb..37e98b989 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\271\235\346\225\260\347\273\204\345\210\206\346\225\260/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\271\235\346\225\260\347\273\204\345\210\206\346\225\260/solution.cpp" @@ -0,0 +1,43 @@ +// 九数组分数 +#include + +void test(int x[]) +{ + int a = x[0] * 1000 + x[1] * 100 + x[2] * 10 + x[3]; + int b = x[4] * 10000 + x[5] * 1000 + x[6] * 100 + x[7] * 10 + x[8]; + + if (a * 3 == b) + printf("%d / %d\n", a, b); +} + +void f(int x[], int k) +{ + int i, t; + if (k >= 9) + { + test(x); + return; + } + + for (i = k; i < 9; i++) + { + { + t = x[k]; + x[k] = x[i]; + x[i] = t; + } + f(x, k + 1); + { + t = x[i]; + x[i] = x[k]; + x[k] = t; + } + } +} + +int main() +{ + int x[] = {1, 2, 3, 4, 5, 6, 7, 8, 9}; + f(x, 0); + return 0; +} \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\271\246\345\217\267\351\252\214\350\257\201/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\271\246\345\217\267\351\252\214\350\257\201/desc.md" index e69de29bb..07d5dc475 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\271\246\345\217\267\351\252\214\350\257\201/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\271\246\345\217\267\351\252\214\350\257\201/desc.md" @@ -0,0 +1,7 @@ +2004年起,国际ISBN中心出版了《13位国际标准书号指南》。 +原有10位书号前加978作为商品分类标识;校验规则也改变。 +校验位的加权算法与10位ISBN的算法不同,具体算法是: +1. 用1分别乘ISBN的前12位中的奇数位(从左边开始数起),用3乘以偶数位,乘积之和以10为模, +2. 10与模值的差值再对10取模(即取个位的数字)即可得到校验位的值,其值范围应该为0~9。 + +下面的程序实现了该算法,请仔细阅读源码,填写缺失的部分。 diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\271\246\345\217\267\351\252\214\350\257\201/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\271\246\345\217\267\351\252\214\350\257\201/solution.cpp" index e69de29bb..69f456fd8 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\271\246\345\217\267\351\252\214\350\257\201/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\271\246\345\217\267\351\252\214\350\257\201/solution.cpp" @@ -0,0 +1,31 @@ +#include + +// 验证成功返回 1,否则返回 0 +int f(const char *s) +{ + int k = 1; + int sum = 0; + int i; + for (i = 0; s[i] != '\0'; i++) + { + char c = s[i]; + if (c == '-' || c == ' ') + continue; + sum += k % 2 == 1 ? (c - '0') * 3 : (c - '0'); + k++; + if (k > 12) + break; + } + + while (s[i] != '\0') + i++; + + return (s[i - 1] - '0') == (10 - sum % 10) % 10; +} + +int main() +{ + printf("%d\n", f("978-7-301-04815-3")); + printf("%d\n", f("978-7-115-38821-6")); + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\271\260\344\270\215\345\210\260\347\232\204\346\225\260\347\233\256/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\271\260\344\270\215\345\210\260\347\232\204\346\225\260\347\233\256/desc.md" index e69de29bb..8a879c071 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\271\260\344\270\215\345\210\260\347\232\204\346\225\260\347\233\256/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\271\260\344\270\215\345\210\260\347\232\204\346\225\260\347\233\256/desc.md" @@ -0,0 +1,34 @@ +#### 问题描述 + +小明开了一家糖果店。他别出心裁:把水果糖包成4颗一包和7颗一包的两种。糖果不能拆包卖。 + +小朋友来买糖的时候,他就用这两种包装来组合。当然有些糖果数目是无法组合出来的,比如要买 10 颗糖。 + +你可以用计算机测试一下,在这种包装情况下,最大不能买到的数量是17。大于17的任何数字都可以用4和7组合出来。 + +本题的要求就是在已知两个包装的数量时,求最大不能组合出的数字。 + +#### 输入格式 + +两个正整数,表示每种包装中糖的颗数(都不多于1000) + +#### 输出格式 + +一个正整数,表示最大不能买到的糖数 + +#### 样例输入1 +``` +4 7 +``` +#### 样例输出1 +``` +17 +``` +#### 样例输入2 +``` +3 5 +``` +#### 样例输出2 +``` +7 +``` \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\271\260\344\270\215\345\210\260\347\232\204\346\225\260\347\233\256/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\271\260\344\270\215\345\210\260\347\232\204\346\225\260\347\233\256/solution.cpp" index e69de29bb..2a4fc4fc9 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\271\260\344\270\215\345\210\260\347\232\204\346\225\260\347\233\256/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\271\260\344\270\215\345\210\260\347\232\204\346\225\260\347\233\256/solution.cpp" @@ -0,0 +1,42 @@ +#include +bool b[100000]; +int min(int a, int b) +{ + if (a < b) + { + return a; + } + else + { + return b; + } +} +int main() +{ + int n, m, j = 0, max = 0; + scanf("%d%d", &n, &m); + for (int i = 0; i <= m; i++) + for (int j = 0; j <= n; j++) + { + if (i * n + j * m >= 100000) + break; + b[i * n + j * m] = true; + } + for (int i = min(m, n); i <= n * m; i++) + { + if (b[i]) + { + j++; + if (j == min(m, n)) + { + printf("%d", max); + break; + } + } + else + { + max = i; + j = 0; + } + } +} \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\272\244\346\215\242\347\223\266\345\255\220/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\272\244\346\215\242\347\223\266\345\255\220/desc.md" index e69de29bb..df3025163 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\272\244\346\215\242\347\223\266\345\255\220/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\272\244\346\215\242\347\223\266\345\255\220/desc.md" @@ -0,0 +1,34 @@ +有N个瓶子,编号 1 ~ N,放在架子上。 +比如有5个瓶子: +2 1 3 5 4 +要求每次拿起2个瓶子,交换它们的位置。 +经过若干次后,使得瓶子的序号为: +1 2 3 4 5 +对于这么简单的情况,显然,至少需要交换2次就可以复位。 +如果瓶子更多呢?你可以通过编程来解决。 + +输入格式为两行: +第一行: 一个正整数N(N<10000), 表示瓶子的数目 +第二行:N个正整数,用空格分开,表示瓶子目前的排列情况。 + +输出数据为一行一个正整数,表示至少交换多少次,才能完成排序。 + +例如,输入: +``` +5 +3 1 2 5 4 +``` +程序应该输出: +``` +3 +``` +再例如,输入: +``` +5 +5 4 3 2 1 +``` +程序应该输出: +``` +2 +``` + diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\272\244\346\215\242\347\223\266\345\255\220/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\272\244\346\215\242\347\223\266\345\255\220/solution.cpp" index e69de29bb..8445ec733 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\272\244\346\215\242\347\223\266\345\255\220/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\272\244\346\215\242\347\223\266\345\255\220/solution.cpp" @@ -0,0 +1,27 @@ +#include +#include + +using namespace std; + +const int N = 1e4 + 10; +bool st[N]; +int a[N], n, k; + +int main() +{ + cin >> n; + for (int i = 1; i <= n; i++) + cin >> a[i]; //瓶子初始序号 + + for (int i = 1; i <= n; i++) //从每个正确序号出发 + if (!st[i]) //如果没有走过 + { + k++; //环数量加一 + for (int j = i; !st[j]; j = a[j]) //走完这个环 每次变更指向a[j] 即瓶子初始序号的第j个 + st[j] = true; + } + + cout << n - k; //环最简情况为自指 则最多有n个环 当前有k个环 从K达到n则需要n-k次 + + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\272\272\347\211\251\347\233\270\345\205\263\346\200\247\345\210\206\346\236\220/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\272\272\347\211\251\347\233\270\345\205\263\346\200\247\345\210\206\346\236\220/desc.md" index e69de29bb..68f7bbef8 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\272\272\347\211\251\347\233\270\345\205\263\346\200\247\345\210\206\346\236\220/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\272\272\347\211\251\347\233\270\345\205\263\346\200\247\345\210\206\346\236\220/desc.md" @@ -0,0 +1,39 @@ +小明正在分析一本小说中的人物相关性。 + +他想知道在小说中 Alice 和 Bob 有多少次同时出现。 + +更准确的说,小明定义 Alice 和 Bob “同时出现”的意思是:在小说文本中 Alice 和 Bob 之间不超过 K 个字符。 + +例如以下文本: +``` +This is a story about Alice and Bob. Alice wants to send a private message to Bob. +``` +假设 K=20,则 Alice 和 Bob 同时出现了 2 次,分别是 Alice and Bob 和 Bob. Alice。 + +前者 Alice 和 Bob 之间有 5 个字符,后者有 2 个字符。 + +注意: + +1. Alice 和 Bob 是大小写敏感的,alice 或 bob 等并不计算在内。 +2. Alice 和 Bob 应为单独的单词,前后可以有标点符号和空格,但是不能有字母。例如 Bobbi 並不算出现了 Bob。 +#### 输入格式 +第一行包含一个整数 K。 + +第二行包含一行字符串,只包含大小写字母、标点符号和空格。长度不超过 1000000。 + +#### 输出格式 +输出一个整数,表示 Alice 和 Bob 同时出现的次数。 + +#### 数据范围 +``` +1≤K≤1000000 +``` +#### 输入样例: +``` +20 +This is a story about Alice and Bob. Alice wants to send a private message to Bob. +``` +输出样例: +``` +2 +``` \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\272\272\347\211\251\347\233\270\345\205\263\346\200\247\345\210\206\346\236\220/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\272\272\347\211\251\347\233\270\345\205\263\346\200\247\345\210\206\346\236\220/solution.cpp" index e69de29bb..680e35fc6 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\272\272\347\211\251\347\233\270\345\205\263\346\200\247\345\210\206\346\236\220/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\272\272\347\211\251\347\233\270\345\205\263\346\200\247\345\210\206\346\236\220/solution.cpp" @@ -0,0 +1,51 @@ +#include +using namespace std; +int len; +string s; +bool check(int i) +{ + if (len - i < 5) + return false; + return s[i + 1] == 'l' && s[i + 2] == 'i' && s[i + 3] == 'c' && s[i + 4] == 'e'; +} +bool check2(int i) +{ + if (len - i < 3) + return false; + return s[i + 1] == 'o' && s[i + 2] == 'b'; +} +int main() +{ + int k; //这里绝对不能加关闭流读入,如果这加了getline会直接读不到 + cin >> k; + getchar(); + getline(cin, s); + len = s.length(); + vector Alice, Bob; + for (int i = 0; i < len; i++) + { + if (s[i] == 'A' && check(i)) + { + Alice.push_back(i); + i += 5; + } + else if (s[i] == 'B' && check2(i)) + { + Bob.push_back(i); + i += 3; + } + } + int As = Alice.size(), Bs = Bob.size(); + int i = 0, j = 0; + long long ans = 0; + for (int q = 0; q < As; q++) + { + while (i < Bs && Bob[i] < Alice[q] - k - 3) + i++; //左边界已经有些被排除的 + while (j < Bs && Bob[j] <= Alice[q] + k + 5) + j++; //右边界 + ans += j - i; + } + cout << ans << "\n"; + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\273\230\350\264\246\351\227\256\351\242\230/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\273\230\350\264\246\351\227\256\351\242\230/desc.md" index e69de29bb..22a33a855 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\273\230\350\264\246\351\227\256\351\242\230/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\273\230\350\264\246\351\227\256\351\242\230/desc.md" @@ -0,0 +1,54 @@ +#### 题目描述 +几个人一起出去吃饭是常有的事。但在结帐的时候,常常会出现一些争执。 + +现在有 n 个人出去吃饭,他们总共消费了 S 元。其中第 i 个人带了 ai 元。幸运的是,所有人带的钱的总数是足够付账的,但现在问题来了:每个人分别要出多少钱呢? + +为了公平起见,我们希望在总付钱量恰好为 S 的前提下,最后每个人付的钱的标准差最小。这里我们约定,每个人支付的钱数可以是任意非负实数,即可以不是1分钱的整数倍。你需要输出最小的标准差是多少。 + +标准差的介绍:标准差是多个数与它们平均数差值的平方平均数,一般用于刻画这些数之间的“偏差有多大”。形式化地说,设第 i 个人付的钱为 bi 元,那么标准差为 : + ![参见p1.png](https://img-blog.csdnimg.cn/20201015164915888.png#pic_center) + + +#### 输入格式 +从标准输入读入数据。 + +第一行包含两个整数 n、S; +第二行包含 n 个非负整数 a1, …, an。 + +#### 输出格式 +输出到标准输出。 + +输出最小的标准差,四舍五入保留 4 位小数。 +保证正确答案在加上或减去 10^−9 后不会导致四舍五入的结果发生变化。 + +#### 样例1输入 +``` +5 2333 +666 666 666 666 666 +``` +#### 样例输出 +``` +0.0000 +``` +#### 样例解释 +每个人都出 2333/5 元,标准差为 0。 + +#### 样例输入 +``` +10 30 +2 1 4 7 4 8 3 6 4 7 +``` +#### 样例输出 +``` +0.7928 +``` +#### 数据说明 +对于 10% 的数据,所有 ai 相等; +对于 30% 的数据,所有非 0 的 ai 相等; +对于 60% 的数据,n ≤ 1000; +对于 80% 的数据,n ≤ 10^5; +对于所有数据,n ≤ 5 × 10^5, 0 ≤ ai ≤ 10^9。 + +#### 资源约定: +峰值内存消耗(含虚拟机) < 256M +CPU消耗 < 1000ms diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\273\230\350\264\246\351\227\256\351\242\230/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\273\230\350\264\246\351\227\256\351\242\230/solution.cpp" index e69de29bb..0f4b51901 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\273\230\350\264\246\351\227\256\351\242\230/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\273\230\350\264\246\351\227\256\351\242\230/solution.cpp" @@ -0,0 +1,39 @@ +#include +#include +#include +using namespace std; +int main() +{ + int num_of_people; //人数 + int total_money; //总需要付款 + int each_afford[500001]; //每个人余款 + cin >> num_of_people; + cin >> total_money; + for (int i = 0; i < num_of_people; i++) + { + cin >> each_afford[i]; + } + sort(each_afford, each_afford + num_of_people); //将每个人余款升序排序 + double avg = total_money * 1.0 / num_of_people; //计算初始平摊要给的钱 + double newavg = avg; //新的平均值 + double ans = 0; //方差 + + for (int i = 0; i < num_of_people; i++) + { + if (each_afford[i] < newavg) //有的人连AA都给不起,让他们把现有的钱全给了 + { + ans = ans + pow((each_afford[i] - avg), 2); //此时的方差 + total_money = total_money - each_afford[i]; //减掉给不起平摊的人的所有余款 + newavg = total_money * 1.0 / (num_of_people - i - 1); //减掉给不起平摊的钱之后算的平均值 + } + else + { + ans += (num_of_people - i) * pow(newavg - avg, 2); + break; + } + } + + ans = sqrt(ans / num_of_people); + printf("%.4lf\n", ans); + return 0; +} \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\277\256\346\224\271\346\225\260\347\273\204/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\277\256\346\224\271\346\225\260\347\273\204/desc.md" index e69de29bb..dc6735ec0 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\277\256\346\224\271\346\225\260\347\273\204/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\277\256\346\224\271\346\225\260\347\273\204/desc.md" @@ -0,0 +1,24 @@ +#### 问题描述 +给定一个长度为 N 的数组$ A = [A_1; A_2; · · · A_N]$,数组中有可能有重复出现的整数。 +现在小明要按以下方法将其修改为没有重复整数的数组。小明会依次修改$A_2, A_3, · · · , A_N$。 +当修改 $A_i$时,小明会检查 $A_i$ 是否在$ A_1 ∼ A_{i−1} $中出现过。如果出现过,则小明会给$ A_i $加上 1 ;如果新的$ A_i $仍在之前出现过,小明会持续给$ A_i $加 1 ,直到$ A_i $没有在$ A_1 ∼ A_{i−1}$ 中出现过。 +当$ A_N $也经过上述修改之后,显然 A 数组中就没有重复的整数了。 +现在给定初始的 A 数组,请你计算出最终的 A 数组。 + +#### 输入格式 +第一行包含一个整数 N。 +第二行包含 N 个整数$ A_1; A_2; · · · ; A_N $。 + +#### 输出格式 +输出 N 个整数,依次是最终的$ A_1; A_2; · · · ; A_N $。 + +#### 样例输入 +``` +5 +2 1 1 3 4 +``` +#### 样例输出 +``` +2 1 3 4 5 +``` + diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\277\256\346\224\271\346\225\260\347\273\204/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\277\256\346\224\271\346\225\260\347\273\204/solution.cpp" index e69de29bb..75ca0bef5 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\277\256\346\224\271\346\225\260\347\273\204/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\277\256\346\224\271\346\225\260\347\273\204/solution.cpp" @@ -0,0 +1,28 @@ +#include +using namespace std; +const int N = 1000010; +int a[N]; + +int find(int x) +{ + if (a[x] != x) + a[x] = find(a[x]); + return a[x]; +} + +int main() +{ + int n; + cin >> n; + for (int i = 1; i <= N; i++) + a[i] = i; + for (int i = 1; i <= n; i++) + { + int x; + cin >> x; + x = find(x); + cout << a[x] << " "; + a[x] = x + 1; + } + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\205\250\347\220\203\345\217\230\346\232\226/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\205\250\347\220\203\345\217\230\346\232\226/desc.md" index e69de29bb..3fe5d2a48 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\205\250\347\220\203\345\217\230\346\232\226/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\205\250\347\220\203\345\217\230\346\232\226/desc.md" @@ -0,0 +1,75 @@ +你有一张某海域 N×N 像素的照片,”.”表示海洋、”#”表示陆地,如下所示: +``` +....... +.##.... +.##.... +....##. +..####. +...###. +....... +``` +其中”上下左右”四个方向上连在一起的一片陆地组成一座岛屿,例如上图就有 2 座岛屿。 + +由于全球变暖导致了海面上升,科学家预测未来几十年,岛屿边缘一个像素的范围会被海水淹没。 + +具体来说如果一块陆地像素与海洋相邻(上下左右四个相邻像素中有海洋),它就会被淹没。 + +例如上图中的海域未来会变成如下样子: +``` +....... +....... +....... +....... +....#.. +....... +....... +``` +请你计算:依照科学家的预测,照片中有多少岛屿会被完全淹没。 + +#### 输入格式 +第一行包含一个整数N。 + +以下 N 行 N 列,包含一个由字符”#”和”.”构成的 N×N 字符矩阵,代表一张海域照片,”#”表示陆地,”.”表示海洋。 + +照片保证第 1 行、第 1 列、第 N 行、第 N 列的像素都是海洋。 + +#### 输出格式 +一个整数表示答案。 + +#### 数据范围 +``` +1≤N≤1000 +``` +#### 输入样例1: +``` +7 +....... +.##.... +.##.... +....##. +..####. +...###. +....... +``` +#### 输出样例1: +``` +1 +``` +#### 输入样例2: +``` +9 +......... +.##.##... +.#####... +.##.##... +......... +.##.#.... +.#.###... +.#..#.... +......... +``` +#### 输出样例2: +``` +1 +``` + diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\205\250\347\220\203\345\217\230\346\232\226/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\205\250\347\220\203\345\217\230\346\232\226/solution.cpp" index e69de29bb..4c5e66f5d 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\205\250\347\220\203\345\217\230\346\232\226/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\205\250\347\220\203\345\217\230\346\232\226/solution.cpp" @@ -0,0 +1,66 @@ +#include +#include + +using namespace std; +int n; +const int N = 1e3 + 10; +char g[N][N]; +bool st[N][N]; //状态 判断是否走过 + +typedef pair PII; //需要长款两个变量定位 +#define x first +#define y second + +int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1}; //移动的偏移量 + +void bfs(int x, int y, int &sum, int &bound) //土地量与淹没量,后续需要使用 所以& +{ + st[x][y] = true; + queue q; + q.push({x, y}); + + while (q.size()) //BFS必然遍历完整个岛屿 + { + auto t = q.front(); + q.pop(); + bool is_bound = false; + sum++; + for (int i = 0; i < 4; i++) + { + int tmpx = t.x + dx[i], tmpy = t.y + dy[i]; + if (tmpx < 0 || tmpx >= n || tmpy < 0 || tmpy >= n) + continue; //边界 + else if (st[tmpx][tmpy]) + continue; //走过 + else if (g[tmpx][tmpy] == '.') //说明上一个地点临海 + { + is_bound = true; + continue; + } + st[tmpx][tmpy] = true; + q.push({tmpx, tmpy}); + } + if (is_bound) + bound++; //四个方向有一个临海 则该地区沉没 + } + return; +} +int main() +{ + cin >> n; + for (int i = 0; i < n; i++) + cin >> g[i]; //读入地图 + + int cnt = 0; //未被完全淹没的岛屿数量 + for (int i = 0; i < n; i++) + for (int j = 0; j < n; j++) + if (g[i][j] == '#' && !st[i][j]) //当遍历到土地 且 未走过时 遍历能走到的整个岛屿 + { + int sum = 0, bound = 0; + bfs(i, j, sum, bound); + if (sum == bound) + cnt++; //沉没量与土地量相等,证明该岛屿全部沉没 + } + cout << cnt; + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\205\255\350\247\222\345\241\253\346\225\260/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\205\255\350\247\222\345\241\253\346\225\260/desc.md" index e69de29bb..7f98051ce 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\205\255\350\247\222\345\241\253\346\225\260/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\205\255\350\247\222\345\241\253\346\225\260/desc.md" @@ -0,0 +1,4 @@ +如图所示六角形中,填入1~12的数字。 +使得每条直线上的数字之和都相同。 +图中,已经替你填好了3个数字,请你计算星号位置所代表的数字是多少? +![](https://img-blog.csdn.net/20160124154420856) \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\205\255\350\247\222\345\241\253\346\225\260/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\205\255\350\247\222\345\241\253\346\225\260/solution.cpp" index e69de29bb..75f95931b 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\205\255\350\247\222\345\241\253\346\225\260/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\205\255\350\247\222\345\241\253\346\225\260/solution.cpp" @@ -0,0 +1,22 @@ +#include +#include + +using namespace std; +int n[12] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; +int main() +{ + do + { + int line1 = n[0] + n[2] + n[5] + n[7]; + int line2 = n[0] + n[3] + n[6] + n[10]; + int line3 = n[7] + n[8] + n[9] + n[10]; + int line4 = n[1] + n[2] + n[3] + n[4]; + int line5 = n[1] + n[5] + n[8] + n[11]; + int line6 = n[4] + n[6] + n[9] + n[11]; + if (line1 == line2 && line2 == line3 && line3 == line4 && line4 == line5 && line5 == line6 && n[0] == 1 && n[1] == 8 && n[11] == 3) + cout << n[5]; + + } while (next_permutation(n, n + 12)); + + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\205\260\351\241\277\350\232\202\350\232\201/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\205\260\351\241\277\350\232\202\350\232\201/desc.md" index e69de29bb..f3f859a83 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\205\260\351\241\277\350\232\202\350\232\201/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\205\260\351\241\277\350\232\202\350\232\201/desc.md" @@ -0,0 +1,46 @@ +问题描述 +![](https://img-blog.csdnimg.cn/20200526100857208.PNG?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2xsX3dhbmc=,size_16,color_FFFFFF,t_70) + +兰顿蚂蚁,是于1986年,由克里斯·兰顿提出来的,属于细胞自动机的一种。 +平面上的正方形格子被填上黑色或白色。在其中一格正方形内有一只“蚂蚁”。 +蚂蚁的头部朝向为:上下左右其中一方。 +蚂蚁的移动规则十分简单: +若蚂蚁在黑格,右转90度,将该格改为白格,并向前移一格; +若蚂蚁在白格,左转90度,将该格改为黑格,并向前移一格。 + +规则虽然简单,蚂蚁的行为却十分复杂。刚刚开始时留下的路线都会有接近对称,像是会重复,但不论起始状态如何,蚂蚁经过漫长的混乱活动后,会开辟出一条规则的“高速公路”。 +蚂蚁的路线是很难事先预测的。 +你的任务是根据初始状态,用计算机模拟兰顿蚂蚁在第n步行走后所处的位置。 +#### 输入格式 +输入数据的第一行是 m n 两个整数(3 < m, n < 100),表示正方形格子的行数和列数。 +接下来是 m 行数据。 +每行数据为 n 个被空格分开的数字。0 表示白格,1 表示黑格。 +接下来是一行数据:x y s k, 其中x y为整数,表示蚂蚁所在行号和列号(行号从上到下增长,列号从左到右增长,都是从0开始编号)。s 是一个大写字母,表示蚂蚁头的朝向,我们约定:上下左右分别用:UDLR表示。k 表示蚂蚁走的步数。 +#### 输出格式 +输出数据为两个空格分开的整数 p q, 分别表示蚂蚁在k步后,所处格子的行号和列号。 +#### 样例输入 +``` +5 6 +0 0 0 0 0 0 +0 0 0 0 0 0 +0 0 1 0 0 0 +0 0 0 0 0 0 +0 0 0 0 0 0 +2 3 L 5 +``` +#### 样例输出 +``` +1 3 +``` +#### 样例输入 +``` +3 3 +0 0 0 +1 1 1 +1 1 1 +1 1 U 6 +``` +#### 样例输出 +``` +0 0 +``` diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\205\260\351\241\277\350\232\202\350\232\201/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\205\260\351\241\277\350\232\202\350\232\201/solution.cpp" index e69de29bb..7c51d900d 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\205\260\351\241\277\350\232\202\350\232\201/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\205\260\351\241\277\350\232\202\350\232\201/solution.cpp" @@ -0,0 +1,73 @@ +#include +#include +using namespace std; +int a[105][105]; //定义一个二维数组存储格子颜色 + +int main() +{ + int m, n; + int x, y, k; + char s; + cin >> m >> n; + for (int i = 0; i < m; i++) + { + for (int j = 0; j < n; j++) + { + cin >> a[i][j]; + } + } + scanf("%d %d %c %d", &x, &y, &s, &k); + while (k--) + { + if (a[x][y] == 1) //蚂蚁在黑格 + { + a[x][y] = 0; + if (s == 'U') + { + y++; + s = 'R'; + } + else if (s == 'D') + { + y--; + s = 'L'; + } + else if (s == 'L') + { + x--; + s = 'U'; + } + else if (s == 'R') + { + x++; + s = 'D'; + } + } + else //蚂蚁在白格 + { + a[x][y] = 1; + if (s == 'U') + { + y--; + s = 'L'; + } + else if (s == 'D') + { + y++; + s = 'R'; + } + else if (s == 'L') + { + x++; + s = 'D'; + } + else if (s == 'R') + { + x--; + s = 'U'; + } + } + } + printf("%d %d\n", x, y); + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\206\231\346\227\245\345\277\227/config.json" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\206\231\346\227\245\345\277\227/config.json" deleted file mode 100644 index f6416a1a5..000000000 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\206\231\346\227\245\345\277\227/config.json" +++ /dev/null @@ -1,6 +0,0 @@ -{ - "node_id": "569d5e11c4fc5de7844053d9a733c5e8", - "keywords": [], - "children": [], - "export": [] -} \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\206\231\346\227\245\345\277\227/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\206\231\346\227\245\345\277\227/desc.md" deleted file mode 100644 index e69de29bb..000000000 diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\206\231\346\227\245\345\277\227/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\206\231\346\227\245\345\277\227/solution.cpp" deleted file mode 100644 index e69de29bb..000000000 diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\206\231\346\227\245\345\277\227/solution.java" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\206\231\346\227\245\345\277\227/solution.java" deleted file mode 100644 index e69de29bb..000000000 diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\210\206\345\260\217\347\273\204/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\210\206\345\260\217\347\273\204/desc.md" index e69de29bb..4bec4f26b 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\210\206\345\260\217\347\273\204/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\210\206\345\260\217\347\273\204/desc.md" @@ -0,0 +1,38 @@ +9名运动员参加比赛,需要分3组进行预赛。有哪些分组的方案呢? +我们标记运动员为 A,B,C,... I +下面的程序列出了所有的分组方法。 +该程序的正常输出为: +``` +ABC DEF GHI +ABC DEG FHI +ABC DEH FGI +ABC DEI FGH +ABC DFG EHI +ABC DFH EGI +ABC DFI EGH +ABC DGH EFI +ABC DGI EFH +ABC DHI EFG +ABC EFG DHI +ABC EFH DGI +ABC EFI DGH +ABC EGH DFI +ABC EGI DFH +ABC EHI DFG +ABC FGH DEI +ABC FGI DEH +ABC FHI DEG +ABC GHI DEF +ABD CEF GHI +ABD CEG FHI +ABD CEH FGI +ABD CEI FGH +ABD CFG EHI +ABD CFH EGI +ABD CFI EGH +ABD CGH EFI +ABD CGI EFH +ABD CHI EFG +ABD EFG CHI +..... (以下省略,总共560行)。 +``` \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\210\206\345\260\217\347\273\204/solution.java" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\210\206\345\260\217\347\273\204/solution.java" index e69de29bb..127d048f5 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\210\206\345\260\217\347\273\204/solution.java" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\210\206\345\260\217\347\273\204/solution.java" @@ -0,0 +1,49 @@ +public class A { + public static String remain(int[] a) { + String s = ""; + for (int i = 0; i < a.length; i++) { + if (a[i] == 0) + s += (char) (i + 'A'); + } + return s; + } + + public static void f(String s, int[] a) { + for (int i = 0; i < a.length; i++) { + if (a[i] == 1) + continue; + a[i] = 1; + for (int j = i + 1; j < a.length; j++) { + if (a[j] == 1) + continue; + a[j] = 1; + for (int k = j + 1; k < a.length; k++) { + if (a[k] == 1) + continue; + a[k] = 1; + System.out.println( + s + " " + (char) (i + 'A') + (char) (j + 'A') + (char) (k + 'A') + " " + remain(a)); + a[k] = 0; + } + a[j] = 0; + } + a[i] = 0; + } + } + + public static void main(String[] args) { + int[] a = new int[9]; + a[0] = 1; + + for (int b = 1; b < a.length; b++) { + a[b] = 1; + for (int c = b + 1; c < a.length; c++) { + a[c] = 1; + String s = "A" + (char) (b + 'A') + (char) (c + 'A'); + f(s, a); + a[c] = 0; + } + a[b] = 0; + } + } +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\210\206\345\267\247\345\205\213\345\212\233/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\210\206\345\267\247\345\205\213\345\212\233/desc.md" index e69de29bb..f69d8e6d9 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\210\206\345\267\247\345\205\213\345\212\233/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\210\206\345\267\247\345\205\213\345\212\233/desc.md" @@ -0,0 +1,25 @@ +儿童节那天有K位小朋友到小明家做客。小明拿出了珍藏的巧克力招待小朋友们。 +小明一共有N块巧克力,其中第i块是Hi x Wi的方格组成的长方形。 +为了公平起见,小明需要从这 N 块巧克力中切出K块巧克力分给小朋友们。切出的巧克力需要满足: +1. 形状是正方形,边长是整数 +2. 大小相同 + +例如一块6x5的巧克力可以切出6块2x2的巧克力或者2块3x3的巧克力。 +当然小朋友们都希望得到的巧克力尽可能大,你能帮小Hi计算出最大的边长是多少么? +#### 输入 +第一行包含两个整数N和K。(1 <= N, K <= 100000) +以下N行每行包含两个整数Hi和Wi。(1 <= Hi, Wi <= 100000) +输入保证每位小朋友至少能获得一块1x1的巧克力。 +#### 输出 +输出切出的正方形巧克力最大可能的边长。 +#### 样例输入: +``` +2 10 +6 5 +5 6 +``` +#### 样例输出: +``` +2 +``` + diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\210\206\345\267\247\345\205\213\345\212\233/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\210\206\345\267\247\345\205\213\345\212\233/solution.cpp" index e69de29bb..c70a056b7 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\210\206\345\267\247\345\205\213\345\212\233/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\210\206\345\267\247\345\205\213\345\212\233/solution.cpp" @@ -0,0 +1,42 @@ +#include +#include +int co[100100][2]; + +//n块巧克力,分成x*x型的。 +//返回巧克力的块数 +int coun(int n, int x) +{ + int sum = 0; + for (int i = 0; i < n; i++) + { + sum += (co[i][0] / x) * (co[i][1] / x); + } + return sum; +} + +//二分求解 +int binary(int n, int k) +{ + int l = 0, r = 100000; + while (l < r) + { + int mid = (r - l) / 2 + l; + if (coun(n, mid) < k) + r = mid - 1; + else if (coun(n, mid) > k) + l = mid + 1; + else + return mid; + } + return r; +} + +int main() +{ + int n; + int k; + scanf("%d%d", &n, &k); + for (int i = 0; i < n; i++) + scanf("%d%d", &co[i][0], &co[i][1]); + printf("%d\n", binary(n, k)); +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\210\206\346\225\260/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\210\206\346\225\260/desc.md" index e69de29bb..e0bf0db6f 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\210\206\346\225\260/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\210\206\346\225\260/desc.md" @@ -0,0 +1,3 @@ +1/1 + 1/2 + 1/4 + 1/8 + 1/16 + … 每项是前一项的一半,如果一共有20项,求这个和是多少,结果用分数表示出来。 +类似:3/2 +当然,这只是加了前2项而已。分子分母要求互质。 \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\210\206\346\225\260/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\210\206\346\225\260/solution.cpp" index e69de29bb..e00bcf3c3 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\210\206\346\225\260/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\210\206\346\225\260/solution.cpp" @@ -0,0 +1,26 @@ +#include +using namespace std; +long pow_2(int b) //快速幂运算 +{ + long x = 2; + long res = 1; + while (b > 0) + { + if (b & 1) + res *= x; + b >>= 1; //右移一位 + x = x * x; + } + return res; +} +int gcd(long a, long b) //求出最大公约数 +{ + if (b == 0) + return a; + return gcd(b, a % b); +} +int main() +{ + cout << gcd(pow_2(20) - 1, pow_2(19)) << endl; //最大公约数 + cout << pow_2(20) - 1 << "/" << pow_2(19) << endl; //输出分子分母 +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\210\206\347\261\273\350\256\241\346\225\260/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\210\206\347\261\273\350\256\241\346\225\260/desc.md" index e69de29bb..cec965868 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\210\206\347\261\273\350\256\241\346\225\260/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\210\206\347\261\273\350\256\241\346\225\260/desc.md" @@ -0,0 +1,22 @@ + +#### 问题描述 +输入一个字符串,请输出这个字符串包含多少个大写字母,多少个小写字母,多少个数字。 + +#### 输入格式 +输入一行包含一个字符串。 + +#### 输出格式 +输出三行,每行一个整数,分别表示大写字母、小写字母和数字的个数。 + +#### 样例输入 +``` +1+a=Aab +``` +#### 样例输出 +``` +1 +3 +1 +``` +#### 评测用例规模与约定 +对于所有评测用例,字符串由可见字符组成,长度不超过 100。 diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\210\206\347\261\273\350\256\241\346\225\260/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\210\206\347\261\273\350\256\241\346\225\260/solution.cpp" index e69de29bb..c445e2a07 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\210\206\347\261\273\350\256\241\346\225\260/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\210\206\347\261\273\350\256\241\346\225\260/solution.cpp" @@ -0,0 +1,28 @@ +#include +using namespace std; +int main(int argc, char **argv) +{ + string str; + cin >> str; + int A = 0, a = 0, number = 0; + int len = str.length(); + for (int i = 0; i < len; i++) + { + if (str[i] <= '9' && str[i] >= '0') + { + number++; + } + if (str[i] <= 'Z' && str[i] >= 'A') + { + A++; + } + if (str[i] <= 'z' && str[i] >= 'a') + { + a++; + } + } + cout << A << endl; + cout << a << endl; + cout << number << endl; + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\210\206\347\261\273\350\256\241\346\225\260/solution.java" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\210\206\347\261\273\350\256\241\346\225\260/solution.java" index e69de29bb..2c626f861 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\210\206\347\261\273\350\256\241\346\225\260/solution.java" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\210\206\347\261\273\350\256\241\346\225\260/solution.java" @@ -0,0 +1,27 @@ +import java.util.Scanner; + +public class CountAllKind { + public static void main(String[] args) { + Scanner in = new Scanner(System.in); + String str = in.nextLine(); + in.close(); + int Big = 0; + int small = 0; + int digtal = 0; + + for (int x = 0; x < str.length(); x++) { + if (str.charAt(x) >= 'a' && str.charAt(x) <= 'z') { + small++; + } + if (str.charAt(x) >= 'A' && str.charAt(x) <= 'Z') { + Big++; + } + if (str.charAt(x) >= '0' && str.charAt(x) <= '9') { + digtal++; + } + } + System.out.println(Big); + System.out.println(small); + System.out.println(digtal); + } +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\210\206\347\263\226\346\236\234/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\210\206\347\263\226\346\236\234/desc.md" index e69de29bb..1dbbad070 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\210\206\347\263\226\346\236\234/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\210\206\347\263\226\346\236\234/desc.md" @@ -0,0 +1,23 @@ +#### 问题描述 +有n个小朋友围坐成一圈。老师给每个小朋友随机发偶数个糖果,然后进行下面的游戏: +每个小朋友都把自己的糖果分一半给左手边的孩子。 +一轮分糖后,拥有奇数颗糖的孩子由老师补给1个糖果,从而变成偶数。 +反复进行这个游戏,直到所有小朋友的糖果数都相同为止。 +你的任务是预测在已知的初始糖果情形下,老师一共需要补发多少个糖果。 + +#### 输入格式 +程序首先读入一个整数N(2 +using namespace std; +int main() +{ + int n; //小朋友数量 + cin >> n; + int *Candy = new int[n]; //存储每个小朋友的糖果数 + for (int i = 0; i < n; i++) + { + cin >> Candy[i]; + } + int total = 0; //补发的糖果总数 + while (1) + { + bool flag = true; //判断每人糖果数量是否相同 + for (int i = 1; i < n; i++) + { + if (Candy[0] != Candy[i]) + { //不相同 + flag = false; + break; + } + } + if (flag == true) //数量相同,退出循环 + break; + int temp = Candy[n - 1]; //记录最后一个小朋友手中的糖果 + for (int i = n - 1; i >= 0; i--) + { + if (i == 0) + { //如果是第一个小朋友 + Candy[0] = Candy[0] / 2 + temp / 2; //最后一个小朋友获得最初第一个人的一半 + } + else + Candy[i] = Candy[i] / 2 + Candy[i - 1] / 2; // 每个小朋友都把自己的糖果分一半给左手边的孩子 + if (Candy[i] % 2 != 0) + { //如果此时手中为奇数,则补糖果 + Candy[i] += 1; + total += 1; //补发数量加1 + } + } + } + cout << total << endl; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\210\206\351\205\215\345\217\243\347\275\251/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\210\206\351\205\215\345\217\243\347\275\251/desc.md" index e69de29bb..cc3b09439 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\210\206\351\205\215\345\217\243\347\275\251/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\210\206\351\205\215\345\217\243\347\275\251/desc.md" @@ -0,0 +1,10 @@ +某市市长获得了若干批口罩,给定每批口罩的数量,市长要把口罩分配给市内的2所医院。 + +``` +masks = [9090400, 8499400, 5926800, 8547000, 4958200, 4422600, 5751200, 4175600, 6309600, 5865200, 6604400, 4635000, 10663400, 8087200, 4554000] +``` +由于物流限制,每一批口罩只能全部分配给其中一家医院。 + +市长希望2所医院获得的口罩总数之差越小越好。 + +请你计算这个差最小是多少? diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\210\206\351\205\215\345\217\243\347\275\251/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\210\206\351\205\215\345\217\243\347\275\251/solution.cpp" index e69de29bb..f585d9160 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\210\206\351\205\215\345\217\243\347\275\251/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\210\206\351\205\215\345\217\243\347\275\251/solution.cpp" @@ -0,0 +1,26 @@ +#include +#include +#include +using namespace std; +long int masks[15] = {9090400, 8499400, 5926800, 8547000, 4958200, + 4422600, 5751200, 4175600, 6309600, + 5865200, 6604400, 4635000, 10663400, 8087200, 4554000}; + +long ans = 1000000000; + +void dfs(int n, long h1, long h2) +{ + if (n == 15) + { + ans = min(ans, abs(h1 - h2)); + return; + } + dfs(n + 1, h1 + masks[n], h2); + dfs(n + 1, h1, h2 + masks[n]); +} + +int main() +{ + dfs(0, 0, 0); + cout << ans; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\210\207\351\235\242\346\235\241/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\210\207\351\235\242\346\235\241/desc.md" index e69de29bb..ba37a1d8b 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\210\207\351\235\242\346\235\241/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\210\207\351\235\242\346\235\241/desc.md" @@ -0,0 +1,4 @@ +一根高筋拉面,中间切一刀,可以得到2根面条。 +如果先对折1次,中间切一刀,可以得到3根面条。 +如果连续对折2次,中间切一刀,可以得到5根面条。 +那么,连续对折10次,中间切一刀,会得到多少面条呢? \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\210\207\351\235\242\346\235\241/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\210\207\351\235\242\346\235\241/solution.cpp" index e69de29bb..d034f00ce 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\210\207\351\235\242\346\235\241/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\210\207\351\235\242\346\235\241/solution.cpp" @@ -0,0 +1,12 @@ +#include + +using namespace std; + +int main() +{ + int f[10]; + f[1] = 3; + for (int i = 2; i < 11; i++) + f[i] = f[i - 1] * 2 - 1; //等同(f[i-1]-1)*2+1 + cout << f[10]; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\211\215\347\274\200\345\210\244\346\226\255/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\211\215\347\274\200\345\210\244\346\226\255/desc.md" index e69de29bb..3aba306df 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\211\215\347\274\200\345\210\244\346\226\255/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\211\215\347\274\200\345\210\244\346\226\255/desc.md" @@ -0,0 +1,2 @@ +如下的代码判断 needle_start指向的串是否为haystack_start指向的串的前缀,如不是,则返回NULL。 +比如:"abcd1234" 就包含了 "abc" 为前缀 \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\211\215\347\274\200\345\210\244\346\226\255/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\211\215\347\274\200\345\210\244\346\226\255/solution.cpp" index e69de29bb..f13652282 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\211\215\347\274\200\345\210\244\346\226\255/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\211\215\347\274\200\345\210\244\346\226\255/solution.cpp" @@ -0,0 +1,25 @@ +#include +using namespace std; + +char *prefix(char *haystack_start, char *needle_start) +{ + char *haystack = haystack_start; + char *needle = needle_start; + + while (*haystack && *needle) + { //这两个指针都没有越界 + //if() return NULL; //填空位置 + //要移动指针,并判断,if() + if ((*haystack++) != *(needle++)) + return NULL; + } + + if (*needle) + return NULL; //needle没有越界,返回NULL + return haystack_start; +} +int main() +{ + cout << prefix("abcd123", "abd") << endl; + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\211\252\346\240\274\345\255\220/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\211\252\346\240\274\345\255\220/desc.md" index e69de29bb..9a203c51a 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\211\252\346\240\274\345\255\220/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\211\252\346\240\274\345\255\220/desc.md" @@ -0,0 +1,50 @@ +#### 问题描述 +如下图所示,3 x 3 的格子中填写了一些整数。 +``` ++--*--+--+ +|10* 1|52| ++--****--+ +|20|30* 1| +*******--+ +| 1| 2| 3| ++--+--+--+ +``` +我们沿着图中的星号线剪开,得到两个部分,每个部分的数字和都是60。 + +本题的要求就是请你编程判定:对给定的m x n 的格子中的整数,是否可以分割为两个部分,使得这两个区域的数字和相等。 + +如果存在多种解答,请输出包含左上角格子的那个区域包含的格子的最小数目。 + +如果无法分割,则输出 0。 + +#### 输入格式 +程序先读入两个整数 m n 用空格分割 (m,n<10)。 + +表示表格的宽度和高度。 + +接下来是n行,每行m个正整数,用空格分开。每个整数不大于10000。 + +#### 输出格式 +输出一个整数,表示在所有解中,包含左上角的分割区可能包含的最小的格子数目。 +#### 样例输入1 +``` +3 3 +10 1 52 +20 30 1 +1 2 3 +``` +#### 样例输出1 +``` +3 +``` +#### 样例输入2 +``` +4 3 +1 1 1 1 +1 30 80 2 +1 1 1 100 +``` +#### 样例输出2 +``` +10 +``` \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\211\252\346\240\274\345\255\220/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\211\252\346\240\274\345\255\220/solution.cpp" index e69de29bb..4b36789cd 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\211\252\346\240\274\345\255\220/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\211\252\346\240\274\345\255\220/solution.cpp" @@ -0,0 +1,88 @@ +#include + +int m, n, half = 0, sum = 0, minValue = 100, count = 0, select = 0, tnum; +int num[10][10] = {0}, flag[10][10] = {0}; +int xzb[] = {-1, 1, 0, 0}; /*上下左右*/ +int yzb[] = {0, 0, -1, 1}; + +int isok(int x, int y) /*判断传入的坐标值是否能被选入*/ +{ + int yes = 0; /*不越界并且不超出和一半*/ + if ((x >= n || x < 0) || (y >= m || y < 0) || (flag[x][y] == 1) || (sum + num[x][y] > half)) + yes = 1; /*冲突*/ + return yes; +} + +void back(int value, int x, int y) /*执行回退处理*/ +{ + if (x == 0 && y == 0) /*如果将num[0][0]回溯掉,则标记为未选入*/ + select = 0; + --count; + sum -= value; + flag[x][y] = 0; +} + +void dfs(int value, int x, int y) /*dfs搜索*/ +{ + int i, t1, t2; + + if (x == 0 && y == 0) /*主要用于B点开始的搜素,判断num[0][0]有没有被选入*/ + select = 1; + flag[x][y] = 1; /*标记为已走过*/ + ++count; /*已走过点的个数*/ + sum += value; /*已走过的点的和*/ + if (sum == half) + { + if (select == 1) /*如果num[0,0]被选入,主要用于非[0,0]点开始的搜索*/ + tnum = count; + else + tnum = n * m - count; + minValue = minValue > tnum ? tnum : minValue; /*选出剪掉点数最少的方案*/ + } + else + { + for (i = 0; i < 4; ++i) /*按 上下左右 顺序遍历*/ + { + t1 = x + xzb[i]; /*引入t1,t2目的是使传入的x,y值不变,便于下面的回退*/ + t2 = y + yzb[i]; + if (isok(t1, t2) == 1) /*是否可走*/ + continue; + dfs(num[t1][t2], t1, t2); + } + } + back(value, x, y); /*如果上下左右都不可走:回退*/ +} + +int main() +{ + int i, j, maxNum = 0, all = 0; + + scanf("%d%d", &m, &n); + for (i = 0; i < n; ++i) + for (j = 0; j < m; ++j) + { + scanf("%d", &num[i][j]); + all += num[i][j]; /*all为总和*/ + if (num[i][j] > maxNum) /*找出最大值*/ + maxNum = num[i][j]; + } + if (all % 2 != 0 || maxNum > all / 2) /*如果和为基数或者最大值大于总和一半*/ + printf("0\n"); + else + { + half = all / 2; + /*将格子每个点都作为起点搜索一遍,两个for循环*/ + for (i = 0; i < n; ++i) + for (j = 0; j < m; ++j) + { + select = 0; + dfs(num[i][j], i, j); + } + if (minValue != 100) /*找不到*/ + printf("%d\n", minValue); + else + printf("0\n"); + } + + return 0; +} \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\211\252\351\202\256\347\245\250/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\211\252\351\202\256\347\245\250/desc.md" index e69de29bb..5ad5819fd 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\211\252\351\202\256\347\245\250/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\211\252\351\202\256\347\245\250/desc.md" @@ -0,0 +1,9 @@ +如图 +![](https://img-blog.csdnimg.cn/20190313183756434.jpg?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1N5bHZpYV9XdTUx,size_16,color_FFFFFF,t_70) +有12张连在一起的12生肖的邮票。 +现在你要从中剪下5张来,要求必须是连着的。 +(仅仅连接一个角不算相连)比如 +![](https://img-blog.csdnimg.cn/20190313183806622.jpg?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1N5bHZpYV9XdTUx,size_16,color_FFFFFF,t_70), +![](https://img-blog.csdnimg.cn/2019031318382071.jpg?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1N5bHZpYV9XdTUx,size_16,color_FFFFFF,t_70)中,粉红色所示部分就是合格的剪取。 + +请你计算,一共有多少种不同的剪取方法。 \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\211\252\351\202\256\347\245\250/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\211\252\351\202\256\347\245\250/solution.cpp" index e69de29bb..36d9fe5e6 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\211\252\351\202\256\347\245\250/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\211\252\351\202\256\347\245\250/solution.cpp" @@ -0,0 +1,57 @@ +#include +#include +#include + +using namespace std; + +const int row = 3, col = 4; +int a[] = {0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1}; +int map[row][col]; +bool st[row][col]; +int ans; + +int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1}; + +//连通 直接走完连通的部分 +void dfs(int x, int y) +{ + st[x][y] = true; + for (int i = 0; i < 4; i++) + { + int tx = x + dx[i], ty = y + dy[i]; + if (tx < 0 || tx >= row || ty < 0 || ty >= col) + continue; + if (st[tx][ty] || !map[tx][ty]) + continue; + dfs(tx, ty); + } +} + +int main() +{ + do + { + //重置 + memset(map, 0, sizeof map), memset(st, false, sizeof st); + int num = 0, cnt = 0; + + //读入 + for (int i = 0; i < row; i++) + for (int j = 0; j < col; j++) + map[i][j] = a[cnt++]; + + //连通 + for (int i = 0; i < row; i++) + for (int j = 0; j < col; j++) + if (!st[i][j] && map[i][j]) + num++, dfs(i, j); + + //检查 连通块只有一个,正确 + if (num == 1) + ans++; + } while (next_permutation(a, a + 12)); + + cout << ans; + + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\212\240\346\263\225\345\217\230\344\271\230\346\263\225/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\212\240\346\263\225\345\217\230\344\271\230\346\263\225/desc.md" index e69de29bb..52e59caa8 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\212\240\346\263\225\345\217\230\344\271\230\346\263\225/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\212\240\346\263\225\345\217\230\344\271\230\346\263\225/desc.md" @@ -0,0 +1,10 @@ +#### 题目描述: +我们都知道:1+2+3+ … + 49 = 1225 + +现在要求你把其中两个不相邻的加号变成乘号,使得结果为2015 + +比如: + +1+2+3+…+1011+12+…+2728+29+…+49 = 2015 就是符合要求的答案。 + +请你寻找另外一个可能的答案,并把位置靠前的那个乘号左边的数字提交(对于示例,就是提交10)。 diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\212\240\346\263\225\345\217\230\344\271\230\346\263\225/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\212\240\346\263\225\345\217\230\344\271\230\346\263\225/solution.cpp" index e69de29bb..683a6f9a9 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\212\240\346\263\225\345\217\230\344\271\230\346\263\225/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\212\240\346\263\225\345\217\230\344\271\230\346\263\225/solution.cpp" @@ -0,0 +1,13 @@ +#include + +using namespace std; + +int main() +{ //i是左侧X号前一个数,j是右侧X号前一个数 + for (int i = 1; i <= 46; i++) //i,j这里都确定的X的前一个值,则最末X前一个值为48,因为中间必须预留+,所以保留两个X的最末则为46 + for (int j = i + 2; j <= 48; j++) //因为中间必须预留+,所以每次+2,最末X前一个值为48 + if (i * (i + 1) + j * (j + 1) - (i + i + 1) - (j + j + 1) == 2015 - 1225) + if (i != 10) + cout << i << endl; //题目要求判断除了10以外的可能 + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\215\225\350\257\215\345\210\206\346\236\220/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\215\225\350\257\215\345\210\206\346\236\220/desc.md" index e69de29bb..379173852 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\215\225\350\257\215\345\210\206\346\236\220/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\215\225\350\257\215\345\210\206\346\236\220/desc.md" @@ -0,0 +1,27 @@ +#### 问题描述 +小蓝正在学习一门神奇的语言,这门语言中的单词都是由小写英文字母组成,有些单词很长,远远超过正常英文单词的长度。小蓝学了很长时间也记不住一些单词,他准备不再完全记忆这些单词,而是根据单词中哪个字母出现得最多来分辨单词。 +现在,请你帮助小蓝,给了一个单词后,帮助他找到出现最多的字母和这个字母出现的次数。 +#### 输入格式 +输入一行包含一个单词,单词只由小写英文字母组成。 +#### 输出格式 +输出两行,第一行包含一个英文字母,表示单词中出现得最多的字母是哪 +个。如果有多个字母出现的次数相等,输出字典序最小的那个。 +第二行包含一个整数,表示出现得最多的那个字母在单词中出现的次数。 +#### 样例输入 +``` +lanqiao +``` +#### 样例输出 +``` +a 2 +``` +#### 样例输入 +``` +longlonglongistoolong +``` +#### 样例输出 +``` +o 6 +``` +#### 评测用例规模与约定 +对于所有的评测用例,输入的单词长度不超过 1000。 diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\215\225\350\257\215\345\210\206\346\236\220/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\215\225\350\257\215\345\210\206\346\236\220/solution.cpp" index e69de29bb..7030c5f5d 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\215\225\350\257\215\345\210\206\346\236\220/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\215\225\350\257\215\345\210\206\346\236\220/solution.cpp" @@ -0,0 +1,31 @@ +#include "stdio.h" +#include "string.h" +int main() +{ + //定义简单的哈希表并确定表长为128(因为ASCII码只占一个字节8位)并赋初值为0 + int a[128] = {0}; + char s[1000]; + scanf("%s", s); + int len = strlen(s); + //max用于更新最大次数,t用于更新对应的字符 + int max = 0; + char t = 0; + //完成哈希表的建立(即遍历一遍字符串得到值键对) + for (int i = 0; i < len; i++) + { + a[s[i]]++; + if (max < a[s[i]]) + { //完成最大次数的扫描,以及该情况下对应键的记录 + max = a[s[i]]; + t = s[i]; + } //若出现相同次数利用ASCII码来进行判断,小的记录下来 + else if (max == a[s[i]]) + { + if (t > s[i]) + { + t = s[i]; + } + } + } //最后进行字符以及对应次数的输出即可。 + printf("%c\n%d", t, max); +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\215\225\350\257\215\345\210\206\346\236\220/solution.java" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\215\225\350\257\215\345\210\206\346\236\220/solution.java" index e69de29bb..6a62f8504 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\215\225\350\257\215\345\210\206\346\236\220/solution.java" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\215\225\350\257\215\345\210\206\346\236\220/solution.java" @@ -0,0 +1,23 @@ +import java.util.Scanner; + +public class Main { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + String s = sc.nextLine(); + int max = 0; + int index = 0; + String a = "abcdefghijklmnopqrstuvwxyz"; + int b[] = new int[26]; + for (int i = 0; i < s.length(); i++) { + b[a.indexOf(s.charAt(i))]++; + } + for (int j = 0; j < b.length; j++) { + if (b[j] > max) { + max = b[j]; + index = j; + } + } + System.out.println(a.substring(index, index + 1)); + System.out.println(max); + } +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\216\213\347\274\251\345\217\230\346\215\242/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\216\213\347\274\251\345\217\230\346\215\242/desc.md" index e69de29bb..2e5334212 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\216\213\347\274\251\345\217\230\346\215\242/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\216\213\347\274\251\345\217\230\346\215\242/desc.md" @@ -0,0 +1,39 @@ +#### 问题描述 +小明最近在研究压缩算法。 +他知道,压缩的时候如果能够使得数值很小,就能通过熵编码得到较高的压缩比。 +然而,要使数值很小是一个挑战。 +最近,小明需要压缩一些正整数的序列,这些序列的特点是,后面出现的数字很大可能是刚出现过不久的数字。对于这种特殊的序列,小明准备对序列做一个变换来减小数字的值。 +变换的过程如下: +从左到右枚举序列,每枚举到一个数字,如果这个数字没有出现过,刚将数字变换成它的相反数,如果数字出现过,则看它在原序列中最后的一次出现后面(且在当前数前面)出现了几种数字,用这个种类数替换原来的数字。 +比如,序列(a1, a2, a3, a4, a5)=(1, 2, 2, 1, 2)在变换过程为: +a1: 1未出现过,所以a1变为-1; +a2: 2未出现过,所以a2变为-2; +a3: 2出现过,最后一次为原序列的a2,在a2后、a3前有0种数字,所以a3变为0; +a4: 1出现过,最后一次为原序列的a1,在a1后、a4前有1种数字,所以a4变为1; +a5: 2出现过,最后一次为原序列的a3,在a3后、a5前有1种数字,所以a5变为1。 +现在,给出原序列,请问,按这种变换规则变换后的序列是什么。 + +#### 输入 +输入第一行包含一个整数n,表示序列的长度。 +第二行包含n个正整数,表示输入序列。 + +#### 输出 +输出一行,包含n个数,表示变换后的序列。 + +#### 输入例子 1 +``` +5 +1 2 2 1 2 +``` +#### 输出例子 1 +``` +-1 -2 0 1 1 +``` +#### 输入例子 2 +``` +12 +``` +#### 输出例子 2 +``` +-1 0 -2 -3 1 1 2 2 0 0 2 2 +``` \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\216\213\347\274\251\345\217\230\346\215\242/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\216\213\347\274\251\345\217\230\346\215\242/solution.cpp" index e69de29bb..a48a8e50f 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\216\213\347\274\251\345\217\230\346\215\242/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\216\213\347\274\251\345\217\230\346\215\242/solution.cpp" @@ -0,0 +1,67 @@ +#include +using namespace std; + +const int maxn = 1e6 + 5; +int a[maxn], tree[maxn << 2]; // 假设层数 M = log 2 (n - 1), 树节点数就要开2倍了 + // 循环中遍历最后一个结点的的子节点(虽然不存在) 需要 2n * 2的数组大小 +int n, maxpoint; + +void init() +{ + maxpoint = 1; + while (maxpoint < n) + maxpoint <<= 1; //比最后一个结点大的2的倍数个结点 + memset(tree, 0, sizeof(tree)); + memset(a, 0, sizeof(a)); +} + +void update(int k, int addnum) +{ // addnum 在出现前边时更新所有子节点 + 1, 出现后边时 所有子节点都 - 1 + k += maxpoint - 1; // 每个节点都当作根节点一样遍历子节点 + tree[k] += addnum; + while (k) + { + k = (k - 1) >> 1; // 访问父节点直到根结点 + tree[k] += addnum; + } +} + +int query(int a, int b, int k, int l, int r) +{ + if (a == b || (r <= a || l >= b)) + return 0; // 不符合查询条件 返回 0 + if (a <= l && r <= b) + return tree[k]; // 子区域就直接返回 + else + { + int mid = (l + r) >> 1; + return query(a, b, (k << 1) + 1, l, mid) + query(a, b, (k + 1) << 1, mid, r); + } +} + +int main() +{ + int temp; + map mp; + cin >> n; + init(); + for (int i = 0; i < n; i++) + { + cin >> temp; + if (mp.count(temp)) + { + int pre = mp[temp]; + a[i] = query(pre + 1, i, 0, 0, maxpoint); + update(pre, -1); + } + else + { + a[i] = -temp; + } + mp[temp] = i; + update(i, 1); + } + for (int i = 0; i < n; i++) + cout << a[i] << " "; + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\217\226\346\225\260\344\275\215/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\217\226\346\225\260\344\275\215/desc.md" index e69de29bb..80a94c169 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\217\226\346\225\260\344\275\215/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\217\226\346\225\260\344\275\215/desc.md" @@ -0,0 +1,4 @@ +求1个整数的第k位数字有很多种方法。 + +以下的方法就是一种。 + diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\217\226\346\225\260\344\275\215/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\217\226\346\225\260\344\275\215/solution.cpp" index e69de29bb..79d89f2f5 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\217\226\346\225\260\344\275\215/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\217\226\346\225\260\344\275\215/solution.cpp" @@ -0,0 +1,20 @@ +#include +int len(int x) +{ + if (x < 10) + return 1; + return len(x / 10) + 1; +} +// 取x的第k位数字 +int f(int x, int k) +{ + if (len(x) - k == 0) + return x % 10; + return f(x / 10, k); //填空 +} +int main() +{ + int x = 23574; + printf("%d\n", f(x, 3)); + return 0; +} \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\217\226\347\220\203\345\215\232\345\274\210/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\217\226\347\220\203\345\215\232\345\274\210/desc.md" index e69de29bb..44d0f86f2 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\217\226\347\220\203\345\215\232\345\274\210/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\217\226\347\220\203\345\215\232\345\274\210/desc.md" @@ -0,0 +1,44 @@ +#### 问题描述 +两个人玩取球的游戏。 +一共有N个球,每人轮流取球,每次可取集合{n1,n2,n3}中的任何一个数目。 +如果无法继续取球,则游戏结束。此时,持有奇数个球的一方获胜。如果两人都是奇数,则为平局。 +假设双方都采用最聪明的取法,第一个取球的人一定能赢吗? +试编程解决这个问题。 + +#### 输入 +第一行3个正整数n1 n2 n3,空格分开,表示每次可取的数目 (0 +#include +#include +using namespace std; + +const int SIZE = 1e3 + 5; + +int dp[SIZE][2][2]; +int a[3]; + +int dfs(int now, int nowplayer, int otherplayer) +{ + if (dp[now][nowplayer][otherplayer]) + { + return dp[now][nowplayer][otherplayer]; + } + + if (now < a[0]) + { + if ((nowplayer & 1) == (otherplayer & 1)) + return -1; //平 + if (nowplayer & 1) + return 1; //胜 + return 2; //负 + } + + else + { + bool noplayerwin = false; + for (int i = 2; i >= 0; i--) + { + if (a[i] > now) + continue; + else + { + int otherresult = dfs(now - a[i], otherplayer, (nowplayer + a[i]) & 1); + if (otherresult == 2) + return dp[now][nowplayer][otherplayer] = 1; + if (otherresult == -1) + noplayerwin = true; + } + } + if (noplayerwin) + return dp[now][nowplayer][otherplayer] = -1; + return dp[now][nowplayer][otherplayer] = 2; + } +} + +int main() +{ + int maxnum; + memset(dp, 0, sizeof(dp)); + cin >> a[0] >> a[1] >> a[2]; + sort(a, a + 3); + for (int i = 1; i <= 5; i++) + { + cin >> maxnum; + switch (dfs(maxnum, 0, 0)) + { + case 1: + cout << "+ "; + break; + case 2: + cout << "- "; + break; + case -1: + cout << "0 "; + break; + } + } + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\217\226\347\220\203\346\270\270\346\210\217/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\217\226\347\220\203\346\270\270\346\210\217/desc.md" index e69de29bb..c16e21f40 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\217\226\347\220\203\346\270\270\346\210\217/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\217\226\347\220\203\346\270\270\346\210\217/desc.md" @@ -0,0 +1,30 @@ +今盒子里有n个小球,A、B两人轮流从盒中取球,每个人都可以看到另一个人取了多少个,也可以看到盒中还剩下多少个,并且两人都很聪明,不会做出错误的判断。 + +我们约定: +每个人从盒子中取出的球的数目必须是:1,3,7或者8个。轮到某一方取球时不能弃权! +A先取球,然后双方交替取球,直到取完。 +被迫拿到最后一个球的一方为负方(输方) + +请编程确定出在双方都不判断失误的情况下,对于特定的初始球数,A是否能赢? + +程序运行时,从标准输入获得数据,其格式如下: + +先是一个整数n(n<100),表示接下来有n个整数。然后是n个整数,每个占一行(整数<10000),表示初始球数。 + +程序则输出n行,表示A的输赢情况(输为0,赢为1)。 + +例如,用户输入: +``` +4 +1 +2 +10 +18 +``` +则程序应该输出: +``` +0 +1 +1 +0 +``` \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\217\226\347\220\203\346\270\270\346\210\217/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\217\226\347\220\203\346\270\270\346\210\217/solution.cpp" index e69de29bb..5a02d2bd9 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\217\226\347\220\203\346\270\270\346\210\217/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\217\226\347\220\203\346\270\270\346\210\217/solution.cpp" @@ -0,0 +1,43 @@ +#include +#include +#include + +int vis[20000]; +int ff(int x) +{ + if (x > 8) + return vis[x - 8] && vis[x - 7] && vis[x - 3] && vis[x - 1]; + else if (x > 7) + return vis[x - 7] && vis[x - 3] && vis[x - 1]; + else if (x > 3) + return vis[x - 1] && vis[x - 3]; + else if (x > 1) + return vis[x - 1]; + else + return 1; +} +int main() +{ + int l, n, m, i, j; + memset(vis, 0, sizeof(vis)); + vis[2] = 1; + vis[4] = 1; + for (i = 5; i < 10010; i++) + { + if (i > 8) + vis[i] = ff(i - 1) || ff(i - 3) || ff(i - 7) || ff(i - 8); + else if (i > 7) + vis[i] = ff(i - 1) || ff(i - 3) || ff(i - 7); + else if (i > 3) + vis[i] = ff(i - 1) || ff(i - 3); + else if (i > 1) + vis[i] = ff(i - 1); + } + scanf("%d", &l); + while (l--) + { + scanf("%d", &n); + printf("%d\n", vis[n]); + } + return 0; +} \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\217\244\345\240\241\347\256\227\345\274\217/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\217\244\345\240\241\347\256\227\345\274\217/desc.md" index e69de29bb..19468a7cb 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\217\244\345\240\241\347\256\227\345\274\217/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\217\244\345\240\241\347\256\227\345\274\217/desc.md" @@ -0,0 +1,7 @@ +福尔摩斯到某古堡探险,看到门上写着一个奇怪的算式: +ABCDE * ? = EDCBA +他对华生说:“ABCDE应该代表不同的数字,问号也代表某个数字!” +华生:“我猜也是!” +于是,两人沉默了好久,还是没有算出合适的结果来。 +请你利用计算机的优势,找到破解的答案。 +把 ABCDE 所代表的数字写出来。 diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\217\244\345\240\241\347\256\227\345\274\217/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\217\244\345\240\241\347\256\227\345\274\217/solution.cpp" index e69de29bb..6b29ad50a 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\217\244\345\240\241\347\256\227\345\274\217/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\217\244\345\240\241\347\256\227\345\274\217/solution.cpp" @@ -0,0 +1,38 @@ +#include +using namespace std; + +bool isOk(int n, int *v) +{ + int s[10] = {0}; + for (int i = 0; i < 5; i++) + { + if (s[v[i]]) //如果该数重复出现了,就可以直接返回false + return false; + s[v[i]] = 1; // 已出现过的数做标记 + } + return true; +} + +int getNum(int *v) +{ + int s = 0; + for (int i = 0; i < 5; i++) + s = s * 10 + v[i]; //逆序组合该数 + return s; +} + +int main() +{ + int i, j, a, b, v[5] = {0}; + for (i = 12345; i <= 98765; i++) + { + for (a = 0, b = 1; a <= 5; a++, b *= 10) + v[a] = i / b % 10; + if (isOk(i, v)) + for (int j = 2; j < 9; j++) + if (i * j == getNum(v)) + cout << i; + } + + return 0; +} \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\217\262\344\270\260\346\224\266\351\200\237\347\256\227/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\217\262\344\270\260\346\224\266\351\200\237\347\256\227/desc.md" index e69de29bb..09e9672ed 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\217\262\344\270\260\346\224\266\351\200\237\347\256\227/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\217\262\344\270\260\346\224\266\351\200\237\347\256\227/desc.md" @@ -0,0 +1,16 @@ +史丰收速算法的革命性贡献是:从高位算起,预测进位。不需要九九表,彻底颠覆了传统手算! +速算的核心基础是:1位数乘以多位数的乘法。 +其中,乘以7是最复杂的,就以它为例。 +因为,1/7 是个循环小数:0.142857...,如果多位数超过 142857...,就要进1 +同理,2/7, 3/7, ... 6/7 也都是类似的循环小数,多位数超过 n/7,就要进n +下面的程序模拟了史丰收速算法中乘以7的运算过程。 +乘以 7 的个位规律是:偶数乘以2,奇数乘以2再加5,都只取个位。 +乘以 7 的进位规律是: +``` +满 142857... 进1, +满 285714... 进2, +满 428571... 进3, +满 571428... 进4, +满 714285... 进5, +满 857142... 进6 +``` diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\217\262\344\270\260\346\224\266\351\200\237\347\256\227/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\217\262\344\270\260\346\224\266\351\200\237\347\256\227/solution.cpp" index e69de29bb..0a1eb4551 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\217\262\344\270\260\346\224\266\351\200\237\347\256\227/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\217\262\344\270\260\346\224\266\351\200\237\347\256\227/solution.cpp" @@ -0,0 +1,76 @@ +#include +#include +#include +using namespace std; + +//计算个位 +int ge_wei(int a) +{ + if (a % 2 == 0) + return (a * 2) % 10; + else + return (a * 2 + 5) % 10; +} + +//计算进位 +int jin_wei(char *p) +{ + char *level[] = + { + "142857", + "285714", + "428571", + "571428", + "714285", + "857142"}; + + char buf[7]; + buf[6] = '\0'; + strncpy(buf, p, 6); //头文件 + + int i; + for (i = 5; i >= 0; i--) + { + int r = strcmp(level[i], buf); + if (r < 0) + return i + 1; + while (r == 0) + { + p += 6; + strncpy(buf, p, 6); + r = strcmp(level[i], buf); + if (r < 0) + return i + 1; + if (r > 0) + return i; /**填空,填空位置与上一语句相似。在此若填写else return i;,输出结果相同*/ + } + } + + return 0; +} + +//多位数乘以7 +void f(char *s) +{ + int head = jin_wei(s); + if (head > 0) + printf("%d", head); + + char *p = s; + while (*p) + { + int a = (*p - '0'); + int x = (ge_wei(a) + jin_wei(p + 1)) % 10; + printf("%d", x); + p++; + } + + printf("\n"); +} + +int main() +{ + f("428571428571"); + f("34553834937543"); + return 0; +} \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\220\210\345\271\266\346\243\200\346\265\213/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\220\210\345\271\266\346\243\200\346\265\213/desc.md" index e69de29bb..29f417143 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\220\210\345\271\266\346\243\200\346\265\213/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\220\210\345\271\266\346\243\200\346\265\213/desc.md" @@ -0,0 +1,3 @@ +新冠疫情由新冠病毒引起,最近在 A 国蔓延,为了尽快控制疫情,A 国准 备给大量民众进病毒核酸检测。 +然而,用于检测的试剂盒紧缺。为了解决这一困难,科学家想了一个办法:合并检测。即将从多个人(k 个)采集的标本放到同一个试剂盒中进行检测。如果结果为阴性,则说明这 k 个人都是阴性,用一个试剂盒完成了 k 个人的检测。如果结果为阳性,则说明 至少有一个人为阳性,需要将这 k 个人的样本全部重新独立检测(从理论上看, 如果检测前 k−1 个人都是阴性可以推断出第 k 个人是阳性,但是在实际操作中 不会利用此推断,而是将 k 个人独立检测),加上最开始的合并检测,一共使用 了 k + 1 个试剂盒完成了 k 个人的检测。 +A 国估计被测的民众的感染率大概是 1%,呈均匀分布。请问 k 取多少能最节省试剂盒? diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\220\210\345\271\266\346\243\200\346\265\213/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\220\210\345\271\266\346\243\200\346\265\213/solution.cpp" index e69de29bb..5f1e60031 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\220\210\345\271\266\346\243\200\346\265\213/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\220\210\345\271\266\346\243\200\346\265\213/solution.cpp" @@ -0,0 +1,27 @@ +#include +using namespace std; +int main() +{ + int N = 1000; + int ans; + int minn = 9999999; + int sum = 0; //试剂盒的数量 + for (int k = 1; k <= 1000; k++) + { + if (N % k == 0) + { + sum = N / k + 10 * k; + } + else + { + sum = N / k + 10 * k + 1; + } + if (sum < minn) + { + minn = sum; + ans = k; + } + } + cout << ans; + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\220\216\347\274\200\350\241\250\350\276\276\345\274\217/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\220\216\347\274\200\350\241\250\350\276\276\345\274\217/desc.md" index e69de29bb..1eed9782c 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\220\216\347\274\200\350\241\250\350\276\276\345\274\217/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\220\216\347\274\200\350\241\250\350\276\276\345\274\217/desc.md" @@ -0,0 +1,27 @@ +#### 问题描述 + +给定 N 个加号、M 个减号以及 N + M + 1 个整数 A1,A2,··· ,AN+M+1,小明想知道在所有由这 N 个加号、M 个减号以及 N + M +1 个整数凑出的合法的 后缀表达式中,结果最大的是哪一个? + +请你输出这个最大的结果。 例如使用1 2 3 + -,则 “2 3 + 1 -” 这个后缀表达式结果是 4,是最大的。 + +#### 输入格式 + +第一行包含两个整数 N 和 M。 第二行包含 N + M + 1 个整数 A1,A2,··· ,AN+M+1。 + +#### 输出格式 + +输出一个整数,代表答案。 + +#### 样例输入 +``` +1 1 + +1 2 3 +``` +#### 样例输出 +``` +4 +``` +#### 评测用例规模与约定 + +对于所有评测用例,0≤ N,M ≤100000,−10^9 ≤ Ai ≤10^9。 diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\220\216\347\274\200\350\241\250\350\276\276\345\274\217/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\220\216\347\274\200\350\241\250\350\276\276\345\274\217/solution.cpp" index e69de29bb..8c860aa88 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\220\216\347\274\200\350\241\250\350\276\276\345\274\217/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\220\216\347\274\200\350\241\250\350\276\276\345\274\217/solution.cpp" @@ -0,0 +1,52 @@ +#include +#include +using namespace std; + +typedef long long ll; +ll a[200010]; + +int main() +{ + int n, m, sum; + cin >> n >> m; + sum = n + m + 1; + int neg = 0; //负数个数 + for (int i = 1; i <= sum; i++) + { + cin >> a[i]; + if (a[i] < 0) + neg++; + } + sort(a + 1, a + 1 + sum); + ll ans = 0; + if (m == 0) + { //若没有负号 + for (int i = 1; i <= sum; i++) + ans += a[i]; + } + else + { + if (neg == 0) + { //若没有负数 + ans -= a[1]; + for (int i = 2; i <= sum; i++) + ans += abs(a[i]); + } + else + { + if (neg == sum) + { //若全为负数 + for (int i = 1; i < sum; i++) + ans += abs(a[i]); + ans += a[sum]; + } + else + { + for (int i = 1; i <= sum; i++) + ans += abs(a[i]); + } + } + } + cout << ans; + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\223\252\345\244\251\350\277\224\345\233\236/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\223\252\345\244\251\350\277\224\345\233\236/desc.md" index e69de29bb..28636d80e 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\223\252\345\244\251\350\277\224\345\233\236/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\223\252\345\244\251\350\277\224\345\233\236/desc.md" @@ -0,0 +1,5 @@ +小明被不明势力劫持,后莫名其妙被扔到x星站再无问津。 +小明得知每天都有飞船飞往地球,但需要 108 元的船票,而他却身无分文,他决定在 x 星战打工。 +好心的老板答应包食宿,第 1 天给他 1 元钱,并且,以后的每一天都比前一天多2元钱,直到他有足够的钱买票。 +请计算一下,小明在第几天就能凑够 108 元,返回地球。 + diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\223\252\345\244\251\350\277\224\345\233\236/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\223\252\345\244\251\350\277\224\345\233\236/solution.cpp" index e69de29bb..ca35952b6 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\223\252\345\244\251\350\277\224\345\233\236/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\223\252\345\244\251\350\277\224\345\233\236/solution.cpp" @@ -0,0 +1,19 @@ +#include +using namespace std; + +int main() +{ + int money = 0, day = 0; + for (int i = 1;; i += 2) + { + day++; + money += i; + if (money >= 108) + { + cout << day << endl; + break; + } + } + + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\225\244\351\205\222\345\222\214\351\245\256\346\226\231/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\225\244\351\205\222\345\222\214\351\245\256\346\226\231/desc.md" index e69de29bb..ef59362ac 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\225\244\351\205\222\345\222\214\351\245\256\346\226\231/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\225\244\351\205\222\345\222\214\351\245\256\346\226\231/desc.md" @@ -0,0 +1,2 @@ +啤酒每罐2.3元,饮料每罐1.9元。小明买了若干啤酒和饮料,一共花了82.3元。 +我们还知道他买的啤酒比饮料的数量少,请你计算他买了几罐啤酒。 \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\225\244\351\205\222\345\222\214\351\245\256\346\226\231/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\225\244\351\205\222\345\222\214\351\245\256\346\226\231/solution.cpp" index e69de29bb..785bef99a 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\225\244\351\205\222\345\222\214\351\245\256\346\226\231/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\225\244\351\205\222\345\222\214\351\245\256\346\226\231/solution.cpp" @@ -0,0 +1,18 @@ +#include +using namespace std; + +int main(void) +{ + int x, y; + for (x = 0; x <= 19; x++) + { + for (y = 43; y > x; y--) + { + if (2.3 * x + 1.9 * y == 82.3) + { + cout << x << endl; + } + } + } + return 0; +} \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\233\233\345\271\263\346\226\271\345\222\214/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\233\233\345\271\263\346\226\271\345\222\214/desc.md" index e69de29bb..64059958f 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\233\233\345\271\263\346\226\271\345\222\214/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\233\233\345\271\263\346\226\271\345\222\214/desc.md" @@ -0,0 +1,45 @@ +四平方和定理,又称为拉格朗日定理: + +每个正整数都可以表示为至多4个正整数的平方和。 +如果把0包括进去,就正好可以表示为4个数的平方和。 + +比如: +``` +5 = 0^ 2 + 0^ 2 + 1^ 2 + 2^2 +7 = 1^ 2 + 1^ 2 + 1^ 2 + 2^2 +(^符号表示乘方的意思) +``` +对于一个给定的正整数,可能存在多种平方和的表示法。 +要求你对4个数排序: +``` +0 <= a <= b <= c <= d +``` +并对所有的可能表示法按 a,b,c,d 为联合主键升序排列,最后输出第一个表示法 + +程序输入为一个正整数N (N<5000000) +要求输出4个非负整数,按从小到大排序,中间用空格分开 + +例如,输入: +``` +5 +``` +则程序应该输出: +``` +0 0 1 2 +``` +再例如,输入: +``` +12 +``` +则程序应该输出: +``` +0 2 2 2 +``` +再例如,输入: +``` +773535 +``` +则程序应该输出: +``` +1 1 267 838 +``` \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\233\233\345\271\263\346\226\271\345\222\214/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\233\233\345\271\263\346\226\271\345\222\214/solution.cpp" index e69de29bb..7df09f549 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\233\233\345\271\263\346\226\271\345\222\214/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\233\233\345\271\263\346\226\271\345\222\214/solution.cpp" @@ -0,0 +1,37 @@ +#include +#include +#include +#include +using namespace std; + +int N; +map cache; //int和int映射,哈希表用于缓存数值 +int main() +{ + scanf("%d", &N); + for (int c = 0; c * c <= N / 2; c++) + { + for (int d = c; c * c + d * d <= N; d++) + { + if (cache.find(c * c + d * d) == cache.end()) //如果未找到,再去存,已经存在就不需要去存了 + cache[c * c + d * d] = c; //查平方数,先要看cache里面有没有,没有说明它不是一个平方数存起来 + //有的话通过较小的数映射找到它 + } + } + //c*c+d*d要比a*a+d*d要大(至少相同) + for (int a = 0; a * a <= N / 4; a++) + { //单独看a*a小于等于N/4 + for (int b = a; a * a + b * b <= N / 2; b++) + { //a*a+b*b小于等于N/2 + if (cache.find(N - a * a - b * b) != cache.end()) + { //查表,能找到 + int c = cache[N - a * a - b * b]; //c就可以知道 + int d = int(sqrt(N - a * a - b * b - c * c)); //d开方 + printf("%d %d %d %d\n", a, b, c, d); + return 0; //跳出整个主函数 + } + } + } + return 0; +} +//整个过程不需要再排序,因为一开始在写代码时,就已经限定了顺序大小,c*c+d*d要比a*a+d*d要大 diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\233\236\346\226\207\346\227\245\346\234\237/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\233\236\346\226\207\346\227\245\346\234\237/desc.md" index e69de29bb..92133e42d 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\233\236\346\226\207\346\227\245\346\234\237/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\233\236\346\226\207\346\227\245\346\234\237/desc.md" @@ -0,0 +1,23 @@ +#### 问题描述 +2020 年春节期间,有一个特殊的日期引起了大家的注意:2020年2月2日。因为如果将这个日期按“yyyymmdd” 的格式写成一个8 位数是20200202,恰好是一个回文数。我们称这样的日期是回文日期。 +有人表示20200202 是“千年一遇” 的特殊日子。对此小明很不认同,因为不到2年之后就是下一个回文日期:20211202 即2021年12月2日。 +也有人表示20200202 并不仅仅是一个回文日期,还是一个ABABBABA型的回文日期。对此小明也不认同,因为大约100 年后就能遇到下一个ABABBABA 型的回文日期:21211212 即2121 年12 月12 日。算不上“千年一遇”,顶多算“千年两遇”。 +给定一个8 位数的日期,请你计算该日期之后下一个回文日期和下一个ABABBABA型的回文日期各是哪一天。 + +#### 输入格式 +输入包含一个八位整数N,表示日期。 + +#### 输出格式 +输出两行,每行1 个八位数。第一行表示下一个回文日期,第二行表示下 +一个ABABBABA 型的回文日期。 +#### 样例输入 +``` +20200202 +``` +#### 样例输出 +``` +20211202 +21211212 +``` +#### 评测用例规模与约定 +对于所有评测用例,10000101 ≤ N ≤ 89991231,保证N 是一个合法日期的8位数表示。 \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\233\236\346\226\207\346\227\245\346\234\237/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\233\236\346\226\207\346\227\245\346\234\237/solution.cpp" index e69de29bb..772e1de8a 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\233\236\346\226\207\346\227\245\346\234\237/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\233\236\346\226\207\346\227\245\346\234\237/solution.cpp" @@ -0,0 +1,55 @@ +#include +#include +using namespace std; + +int days[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; + +bool check(int year) +{ + return year % 400 == 0 || year % 4 == 0 && year % 100 != 0; +} + +int get_day(int year, int month) +{ + if (month == 2) + return 28 + check(year); + return days[month]; +} + +int main() +{ + int n; + cin >> n; + + string ans1, ans2; + bool flag1 = false, flag2 = false; + for (int i = n / 10000; i <= 9999; i++) + { + string a = to_string(i); + string b = a; + reverse(b.begin(), b.end()); + if (a + b <= to_string(n)) + continue; + + int month = stoi(b.substr(0, 2)); + int day = stoi(b.substr(2, 2)); + if (month < 1 || month > 12) + continue; + if (day < 1 || day > get_day(i, month)) + continue; + + string s1 = a.substr(0, 2); + string s2 = a.substr(2, 2); + if (!flag1) + ans1 = a + b, flag1 = true; + if (!flag2 && s1 == s2 && s1[0] != s1[1]) + ans2 = a + b, flag2 = true; + + if (flag1 && flag2) + break; + } + + cout << ans1 << endl; + cout << ans2 << endl; + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\234\206\345\221\250\347\216\207/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\234\206\345\221\250\347\216\207/desc.md" index e69de29bb..d90ae0e53 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\234\206\345\221\250\347\216\207/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\234\206\345\221\250\347\216\207/desc.md" @@ -0,0 +1,10 @@ +数学发展历史上,圆周率的计算曾有许多有趣甚至是传奇的故事。其中许多方法都涉及无穷级数。 + +图中所示,就是一种用连分数的形式表示的圆周率求法。 + +![](https://img-blog.csdnimg.cn/20210128181357213.png) + + +下面的程序实现了该求解方法。实际上数列的收敛对x的初始值 并不敏感。 + +结果打印出圆周率近似值(保留小数点后4位,并不一定与圆周率真值吻合)。 \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\234\206\345\221\250\347\216\207/solution.java" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\234\206\345\221\250\347\216\207/solution.java" index e69de29bb..fe19aa914 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\234\206\345\221\250\347\216\207/solution.java" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\234\206\345\221\250\347\216\207/solution.java" @@ -0,0 +1,12 @@ +package java_2014_B; + +public class Main005_圆周率 { + public static void main(String[] args) { + double x = 111; + for (int n = 10000; n >= 0; n--) { + int i = 2 * n + 1; + x = 2 + (i * i / x); + } + System.out.println(String.format("%.4f", 4 / (x - 1))); + } +} \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\234\260\345\256\253\345\217\226\345\256\235/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\234\260\345\256\253\345\217\226\345\256\235/desc.md" index e69de29bb..b1b1817c0 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\234\260\345\256\253\345\217\226\345\256\235/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\234\260\345\256\253\345\217\226\345\256\235/desc.md" @@ -0,0 +1,41 @@ +X 国王有一个地宫宝库,是 n×m 个格子的矩阵,每个格子放一件宝贝,每个宝贝贴着价值标签。 +地宫的入口在左上角,出口在右下角。 +小明被带到地宫的入口,国王要求他只能向右或向下行走。 +走过某个格子时,如果那个格子中的宝贝价值比小明手中任意宝贝价值都大,小明就可以拿起它(当然,也可以不拿)。 +当小明走到出口时,如果他手中的宝贝恰好是 k 件,则这些宝贝就可以送给小明。 +请你帮小明算一算,在给定的局面下,他有多少种不同的行动方案能获得这 k 件宝贝。 + +#### 输入格式 +第一行 3 个整数,n,m,k,含义见题目描述。 +接下来 n 行,每行有 m 个整数 Ci 用来描述宝库矩阵每个格子的宝贝价值。 + +#### 输出格式 +输出一个整数,表示正好取 k 个宝贝的行动方案数。 +该数字可能很大,输出它对 1000000007 取模的结果。 + +#### 数据范围 +``` +1≤n,m≤50, +1≤k≤12, +0≤Ci≤12 +``` +#### 输入样例1: +``` +2 2 2 +1 2 +2 1 +``` +#### 输出样例1: +``` +2 +``` +#### 输入样例2: +``` +2 3 2 +1 2 3 +2 1 5 +``` +#### 输出样例2: +``` +14 +``` \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\234\260\345\256\253\345\217\226\345\256\235/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\234\260\345\256\253\345\217\226\345\256\235/solution.cpp" index e69de29bb..e9df2f3b3 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\234\260\345\256\253\345\217\226\345\256\235/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\234\260\345\256\253\345\217\226\345\256\235/solution.cpp" @@ -0,0 +1,48 @@ +#include +using namespace std; +const int N = 55; +const int MOD = 1e9 + 7; +int dp[N][N][13][14]; +int g[N][N]; +int n, m, k; +int main() +{ + cin >> n >> m >> k; + for (int i = 1; i <= n; i++) + { + for (int j = 1; j <= m; j++) + { + cin >> g[i][j]; + g[i][j]++; + } + } + dp[1][1][1][g[1][1]] = 1; + dp[1][1][0][0] = 1; + for (int i = 1; i <= n; i++) + { + for (int j = 1; j <= m; j++) + { + for (int u = 0; u <= k; u++) + { + for (int v = 0; v <= 13; v++) + { + dp[i][j][u][v] = (dp[i][j][u][v] + dp[i - 1][j][u][v]) % MOD; + dp[i][j][u][v] = (dp[i][j][u][v] + dp[i][j - 1][u][v]) % MOD; + if (u > 0 && v == g[i][j]) + { + for (int c = 0; c < v; c++) + { + dp[i][j][u][v] = (dp[i][j][u][v] + dp[i - 1][j][u - 1][c]) % MOD; + dp[i][j][u][v] = (dp[i][j][u][v] + dp[i][j - 1][u - 1][c]) % MOD; + } + } + } + } + } + } + int res = 0; + for (int i = 0; i <= 13; i++) + res = (res + dp[n][m][k][i]) % MOD; + cout << res << endl; + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\236\222\351\252\260\345\255\220/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\236\222\351\252\260\345\255\220/desc.md" index e69de29bb..7dff7ea6b 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\236\222\351\252\260\345\255\220/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\236\222\351\252\260\345\255\220/desc.md" @@ -0,0 +1,38 @@ +赌圣atm晚年迷恋上了垒骰子,就是把骰子一个垒在另一个上边,不能歪歪扭扭,要垒成方柱体。 +经过长期观察,atm 发现了稳定骰子的奥秘:有些数字的面贴着会互相排斥! +我们先来规范一下骰子:1 的对面是 4,2 的对面是 5,3 的对面是 6。 +假设有 m 组互斥现象,每组中的那两个数字的面紧贴在一起,骰子就不能稳定的垒起来。 +atm想计算一下有多少种不同的可能的垒骰子方式。 +两种垒骰子方式相同,当且仅当这两种方式中对应高度的骰子的对应数字的朝向都相同。 +由于方案数可能过多,请输出模 $10^9 + 7$ 的结果。 + +不要小看了 atm 的骰子数量哦~ + +#### 输入格式 +第一行两个整数 n m +n表示骰子数目 +接下来 m 行,每行两个整数 a b ,表示 a 和 b 数字不能紧贴在一起。 + +#### 输出格式 +一行一个数,表示答案模 10^9 + 7 的结果。 + +#### 样例输入 +``` +2 1 +1 2 +``` +#### 样例输出 +``` +544 +``` + +#### 数据范围 +``` +对于 30% 的数据:n <= 5 +对于 60% 的数据:n <= 100 +对于 100% 的数据:0 < n <= 10^9, m <= 36 +``` + +#### 资源约定: +峰值内存消耗 < 256M +CPU消耗 < 2000ms diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\236\222\351\252\260\345\255\220/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\236\222\351\252\260\345\255\220/solution.cpp" index e69de29bb..e0bb33272 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\236\222\351\252\260\345\255\220/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\236\222\351\252\260\345\255\220/solution.cpp" @@ -0,0 +1,78 @@ +#include +#include +using namespace std; + +vector can[7]; //存can[i]能和哪些点挨着 +int up[7] = {1, 1, 1, 1, 1, 1, 1}; +int temp[7] = {1}; +int k = 4; + +const int MOD = 1000000007; + +void init() //初始化都可挨着 +{ + for (int i = 1; i <= 6; i++) + for (int j = 1; j <= 6; j++) + can[i].push_back(j); +} +void dele(int side1, int side2) //删除不可挨着的点 +{ + for (vector::iterator it = can[side1].begin(); it != can[side1].end(); it++) + if (*it == side2) + { + can[side1].erase(it); + break; + } + + for (vector::iterator it = can[side2].begin(); it != can[side2].end(); it++) + if (*it == side1) + { + can[side2].erase(it); + break; + } +} +void fun(int n) +{ + for (int i = 2; i <= n; i++) + { + //计算出第i层骰子每种底面的可能次数 + for (int j = 1; j <= 6; j++) + { + temp[j] = 0; + for (vector::iterator it = can[j].begin(); it != can[j].end(); it++) + temp[j] += up[*it]; + } + //转化为第i层骰子顶面的可能次数 + up[1] = temp[4] % MOD; + up[2] = temp[5] % MOD; + up[3] = temp[6] % MOD; + up[4] = temp[1] % MOD; + up[5] = temp[2] % MOD; + up[6] = temp[3] % MOD; + //4^n + k = k * 4; + k = k % MOD; + } + int ans = 0; + for (int j = 1; j <= 6; j++) + ans += up[j]; + cout << (ans * k) % MOD; +} +int main(int argc, char **argv) +{ + init(); + + int n, m; + cin >> n >> m; + + for (int i = 0; i < m; i++) + { + int side1, side2; + cin >> side1 >> side2; + dele(side1, side2); + } + + fun(n); + + return 0; +} \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\240\206\347\232\204\350\256\241\346\225\260/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\240\206\347\232\204\350\256\241\346\225\260/desc.md" index e69de29bb..b2d26208a 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\240\206\347\232\204\350\256\241\346\225\260/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\240\206\347\232\204\350\256\241\346\225\260/desc.md" @@ -0,0 +1,52 @@ +#### 题目描述 +我们知道包含N个元素的堆可以看成是一棵包含N个节点的完全二叉树。 +每个节点有一个权值。对于小根堆来说,父节点的权值一定小于其子节点的权值。 + +假设N个节点的权值分别是1~N,你能求出一共有多少种不同的小根堆吗? + +例如对于N=4有如下3种: +``` + 1 + / \ + 2 3 + / +4 + + 1 + / \ + 3 2 + / +4 + + 1 + / \ + 2 4 + / +3 + +``` +由于数量可能超过整型范围,你只需要输出结果除以1000000009的余数。 + + +#### 输入格式 +一个整数N。 +对于40%的数据,1 <= N <= 1000 +对于70%的数据,1 <= N <= 10000 +对于100%的数据,1 <= N <= 100000 + +#### 输出格式 +一个整数表示答案。 + +#### 输入样例 +``` +4 +``` + +#### 输出样例 +``` +3 +``` +#### 资源约定: +峰值内存消耗(含虚拟机) < 256M +CPU消耗 < 1000ms + diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\240\206\347\232\204\350\256\241\346\225\260/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\240\206\347\232\204\350\256\241\346\225\260/solution.cpp" index e69de29bb..63ec7e2b8 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\240\206\347\232\204\350\256\241\346\225\260/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\240\206\347\232\204\350\256\241\346\225\260/solution.cpp" @@ -0,0 +1,52 @@ +#include +using namespace std; +typedef long long ll; +const int maxn = 100000; +ll s[maxn + 10], dp[maxn + 10], inv[maxn + 10], f[maxn + 10]; +ll n; +ll mod = 1000000009; +ll qPow(ll a, ll b) +{ + ll ans = 1; + while (b != 0) + { + if (b & 1) + { + ans = ans * a % mod; + } + a = a * a % mod; + b >>= 1; + } + return ans % mod; +} +ll C(ll n, ll m) +{ + return (f[n] * inv[f[m]]) % mod * inv[f[n - m]] % mod; +} +int main() +{ + cin >> n; + f[0] = 1; + for (int i = 1; i <= maxn; i++) + { + f[i] = (f[i - 1] * i) % mod; + inv[i] = qPow(i, mod - 2); + } + for (int i = n; i >= 1; i--) + { + s[i] = (s[i * 2 + 1] <= n ? s[i * 2 + 1] : 0) + (s[i * 2] <= n ? s[i * 2] : 0) + 1; + } + for (int i = 1; i <= n; i++) + { + dp[i] = 1; + } + for (int i = n; i >= 1; i--) + { + if (i * 2 + 1 <= n) + { + dp[i] = (C(s[i] - 1, s[i * 2 + 1]) * dp[i * 2 + 1]) % mod * dp[i * 2] % mod; + } + } + cout << dp[1] << endl; + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\244\215\346\225\260\345\271\202/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\244\215\346\225\260\345\271\202/desc.md" index e69de29bb..66881fd45 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\244\215\346\225\260\345\271\202/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\244\215\346\225\260\345\271\202/desc.md" @@ -0,0 +1,6 @@ +设i为虚数单位。对于任意正整数n,(2+3i)^n 的实部和虚部都是整数。 +求 (2+3i)^123456 等于多少? 即(2+3i)的123456次幂,这个数字很大,要求精确表示。 + +答案写成 "实部±虚部i" 的形式,实部和虚部都是整数(不能用科学计数法表示),中间任何地方都不加空格,实部为正时前面不加正号。 +(2+3i)^2 写成: -5+12i, +(2+3i)^5 写成: 122-597i diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\244\215\346\225\260\345\271\202/solution.java" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\244\215\346\225\260\345\271\202/solution.java" index e69de29bb..942bdcfb6 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\244\215\346\225\260\345\271\202/solution.java" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\244\215\346\225\260\345\271\202/solution.java" @@ -0,0 +1,30 @@ +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.OutputStreamWriter; +import java.io.PrintWriter; +import java.math.BigInteger; + +public class Main { + public static void main(String[] args) throws FileNotFoundException { + PrintWriter out = new PrintWriter( // 打印流输出到复幂数.txt中 + new OutputStreamWriter(new FileOutputStream("复幂数.txt"))); + BigInteger a = BigInteger.valueOf(2); // 相当于(a+bi)*(x+yi) + BigInteger b = BigInteger.valueOf(3); // a、b两个值一值不变 + BigInteger x = BigInteger.valueOf(2); + BigInteger y = BigInteger.valueOf(3); + for (int i = 2; i <= 123456; ++i) // 每次都是两组数据相乘 + { + BigInteger t1 = a.multiply(x); // a*x + BigInteger t2 = a.multiply(y); // a*y + BigInteger t3 = b.multiply(x); // b*x + BigInteger t4 = b.multiply(y); // b*y + x = t1.subtract(t4); // i^2==-1 ax-by + y = t2.add(t3); // bx+ay + } + // 由于数字太长,打印台根本输出不了,即便是输出了,也看不到,所以直接砸在控制台Ctrl+C复制即可,然后粘贴到一个txt文档中 + // 可以通过输出流或打印流输出到一个文档中即可 + out.println(x.toString() + y.toString() + "i"); // 这个题不用想y也一定是负数,要不然那么大的一个数还要判断正负? + out.close(); // 释放资源 + } + +} \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\244\226\345\215\226\345\272\227\344\274\230\345\205\210\347\272\247/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\244\226\345\215\226\345\272\227\344\274\230\345\205\210\347\272\247/desc.md" index e69de29bb..2761aca68 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\244\226\345\215\226\345\272\227\344\274\230\345\205\210\347\272\247/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\244\226\345\215\226\345\272\227\344\274\230\345\205\210\347\272\247/desc.md" @@ -0,0 +1,31 @@ +#### 问题描述 +“饱了么”外卖系统中维护着 N 家外卖店,编号 1 ∼ N。每家外卖店都有一个优先级,初始时 (0 时刻) 优先级都为 0。 +每经过 1 个时间单位,如果外卖店没有订单,则优先级会减少 1,最低减到 0;而如果外卖店有订单,则优先级不减反加,每有一单优先级加 2。 +如果某家外卖店某时刻优先级大于 5,则会被系统加入优先缓存中;如果优先级小于等于 3,则会被清除出优先缓存。 +给定 T 时刻以内的 M 条订单信息,请你计算 T 时刻时有多少外卖店在优先缓存中。 +#### 输入格式 +第一行包含 3 个整数 N、 M 和 T。 +以下 M 行每行包含两个整数 ts 和 id,表示 ts 时刻编号 id 的外卖店收到一个订单。 +#### 输出格式 +输出一个整数代表答案。 +#### 样例输入 +``` +2 6 6 +1 1 +5 2 +3 1 +6 2 +2 1 +6 2 +``` +#### 样例输出 +``` +1 +``` +#### 样例解释 +6 时刻时, 1 号店优先级降到 3,被移除出优先缓存; 2 号店优先级升到 6,加入优先缓存。所以是有 1 家店 (2 号) 在优先缓存中。 +#### 评测用例规模与约定 +``` +对于 80% 的评测用例, 1 ≤ N; M; T ≤ 10000。 +对于所有评测用例, 1 ≤ N; M; T ≤ 100000, 1 ≤ ts ≤ T, 1 ≤ id ≤ N。 +``` \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\244\226\345\215\226\345\272\227\344\274\230\345\205\210\347\272\247/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\244\226\345\215\226\345\272\227\344\274\230\345\205\210\347\272\247/solution.cpp" index e69de29bb..a47f063fd 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\244\226\345\215\226\345\272\227\344\274\230\345\205\210\347\272\247/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\244\226\345\215\226\345\272\227\344\274\230\345\205\210\347\272\247/solution.cpp" @@ -0,0 +1,44 @@ +#include +using namespace std; +const int maxn = 100052; +typedef long long int qq; +vector a[maxn]; +int n, m, t; +bool f(int x) +{ + if (a[x].size() == 0) + return 0; + bool ret = 0; + int now = 2; + for (int i = 1; i < a[x].size(); i++) + { + now = max(0, now - (a[x][i] - a[x][i - 1] - 1)); + if (now <= 3) + ret = 0; + now += 2; + if (now > 5) + ret = 1; + } + now = max(0, now - (t - a[x][a[x].size() - 1])); + if (now <= 3) + ret = 0; + return ret; +} +int main() +{ + scanf("%d%d%d", &n, &m, &t); + while (m--) + { + int ts, id; + scanf("%d%d", &ts, &id); + a[id].push_back(ts); + } + int ans = 0; + for (int i = 1; i <= n; i++) + { + if (f(i) == true) + ans++; + } + printf("%d\n", ans); + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\244\272\345\206\240\346\246\202\347\216\207/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\244\272\345\206\240\346\246\202\347\216\207/desc.md" index e69de29bb..56d5fc078 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\244\272\345\206\240\346\246\202\347\216\207/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\244\272\345\206\240\346\246\202\347\216\207/desc.md" @@ -0,0 +1,17 @@ +足球比赛具有一定程度的偶然性,弱队也有战胜强队的可能。 + +假设有甲、乙、丙、丁四个球队。根据他们过去比赛的成绩,得出每个队与另一个队对阵时取胜的概率表: +``` + 甲 乙 丙 丁 +甲 - 0.1 0.3 0.5 +乙 0.9 - 0.7 0.4 +丙 0.7 0.3 - 0.2 +丁 0.5 0.6 0.8 - +``` +数据含义:甲对乙的取胜概率为0.1,丙对乙的胜率为0.3,... + +现在要举行一次锦标赛。双方抽签,分两个组比,获胜的两个队再争夺冠军。(参见【1.jpg】) + +请你进行10万次模拟,计算出甲队夺冠的概率。 + + \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\244\272\345\206\240\346\246\202\347\216\207/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\244\272\345\206\240\346\246\202\347\216\207/solution.cpp" index e69de29bb..3e93baa8f 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\244\272\345\206\240\346\246\202\347\216\207/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\244\272\345\206\240\346\246\202\347\216\207/solution.cpp" @@ -0,0 +1,74 @@ +#include +#include +int main(void) +{ + int i, j, k; //count + int randfigure; + int awin = 0; + + for (i = 0; i < 100000; i++) + { + randfigure = rand(); + if (randfigure % 3 == 0) + { //AB together + if (randfigure % 10 < 1) + { //A win B + if (randfigure % 10 < 2) + { //C win D + if (randfigure % 10 < 3) + { //A win C + awin++; + } + } + else + { //D win C + if (randfigure % 10 < 5) + { //A win D + awin++; + } + } + } + } + else if (randfigure % 3 == 1) + { //AC together + if (randfigure % 10 < 3) + { //A win C + if (randfigure % 10 < 4) + { //B win D + if (randfigure % 10 < 1) + { //A win B + awin++; + } + } + else + { //D win B + if (randfigure % 10 < 5) + { //A win D + awin++; + } + } + } + } + else + { //AD together + if (randfigure % 10 < 5) + { //A win D + if (randfigure % 10 < 3) + { //C win B + if (randfigure % 10 < 3) + { //A win C + awin++; + } + } + else + { //B win C + if (randfigure % 10 < 1) + { //A win B + awin++; + } + } + } + } + } + printf("%f\n", awin / 100000.0); +} \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\245\207\345\246\231\347\232\204\346\225\260\345\255\227/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\245\207\345\246\231\347\232\204\346\225\260\345\255\227/desc.md" index e69de29bb..87a6b129f 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\245\207\345\246\231\347\232\204\346\225\260\345\255\227/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\245\207\345\246\231\347\232\204\346\225\260\345\255\227/desc.md" @@ -0,0 +1,2 @@ +小明发现了一个奇妙的数字。它的平方和立方正好把0~9的10个数字每个用且只用了一次。 +你能猜出这个数字是多少吗? \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\245\207\345\246\231\347\232\204\346\225\260\345\255\227/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\245\207\345\246\231\347\232\204\346\225\260\345\255\227/solution.cpp" index e69de29bb..bdd33eb48 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\245\207\345\246\231\347\232\204\346\225\260\345\255\227/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\245\207\345\246\231\347\232\204\346\225\260\345\255\227/solution.cpp" @@ -0,0 +1,35 @@ +#include +#include +#include +using namespace std; +int visited[10]; + +int main() +{ + for (int i = 47; i <= 99; i++) + { + for (int i = 0; i < 10; i++) + visited[i] = 0; //初始化数字状态数组 + + stringstream s; //用来将int 转化为string + string s2, s3; + s << i * i; + s2 = s.str(); //s2存平方 + s << i * i * i; + s3 = s.str(); //s3存立方 + + for (int i = 0; i < s2.length(); i++) + visited[s2[i] - 48] = 1; //遍历平方字符串,将此数字标记为已使用,数字的ASCII-48为数字的数值 + + for (int i = 0; i < s3.length(); i++) + visited[s3[i] - 48] = 1; //同理 + + int j; + for (j = 0; j < 10; j++) + if (visited[j] == 0) //判断数字是否全部使用 + break; + if (j == 10) //如果没有跳出,则j为10,所有数字都被使用 + cout << i; + } + return 1; +} \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\245\207\346\200\252\347\232\204\345\210\206\345\274\217/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\245\207\346\200\252\347\232\204\345\210\206\345\274\217/desc.md" index e69de29bb..4b3e8bdb8 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\245\207\346\200\252\347\232\204\345\210\206\345\274\217/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\245\207\346\200\252\347\232\204\345\210\206\345\274\217/desc.md" @@ -0,0 +1,12 @@ +上小学的时候,小明经常自己发明新算法。一次,老师出的题目是: +1/4 乘以 8/5 +小明居然把分子拼接在一起,分母拼接在一起,答案是:18/45 + +![](https://images2015.cnblogs.com/blog/1139769/201704/1139769-20170406155423800-1872161918.png) + + +老师刚想批评他,转念一想,这个答案凑巧也对啊,真是见鬼! +对于分子、分母都是 1~9 中的一位数的情况,还有哪些算式可以这样计算呢? +请写出所有不同算式的个数(包括题中举例的)。 +显然,交换分子分母后,例如:4/1 乘以 5/8 是满足要求的,这算做不同的算式。 +但对于分子分母相同的情况,2/2 乘以 3/3 这样的类型太多了,不在计数之列! diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\245\207\346\200\252\347\232\204\345\210\206\345\274\217/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\245\207\346\200\252\347\232\204\345\210\206\345\274\217/solution.cpp" index e69de29bb..904030d0a 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\245\207\346\200\252\347\232\204\345\210\206\345\274\217/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\245\207\346\200\252\347\232\204\345\210\206\345\274\217/solution.cpp" @@ -0,0 +1,21 @@ +#include +using namespace std; +int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } +int main() +{ + int ans = 0; + + for (int a = 1; a < 10; a++) + for (int b = 1; b < 10; b++) + for (int c = 1; c < 10; c++) + for (int d = 1; d < 10; d++) + if (a != b && c != d) + { + int g1 = gcd(a * c, b * d), g2 = gcd(a * 10 + c, b * 10 + d); + if (a * c / g1 == (a * 10 + c) / g2 && b * d / g1 == (b * 10 + d) / g2) + ans++; + } + + cout << ans; + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\245\207\346\200\252\347\232\204\346\257\224\350\265\233/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\245\207\346\200\252\347\232\204\346\257\224\350\265\233/desc.md" index e69de29bb..e776de405 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\245\207\346\200\252\347\232\204\346\257\224\350\265\233/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\245\207\346\200\252\347\232\204\346\257\224\350\265\233/desc.md" @@ -0,0 +1,7 @@ +某电视台举办了低碳生活大奖赛。题目的计分规则相当奇怪: +每位选手需要回答10个问题(其编号为1到10),越后面越有难度。答对的,当前分数翻倍;答错了则扣掉与题号相同的分数(选手必须回答问题,不回答按错误处理)。 +每位选手都有一个起步的分数为10分。 +某获胜选手最终得分刚好是100分,如果不让你看比赛过程,你能推断出他(她)哪个题目答对了,哪个题目答错了吗? +如果把答对的记为1,答错的记为0,则10个题目的回答情况可以用仅含有1和0的串来表示。例如:0010110011 就是可能的情况。 + +你的任务是算出所有可能情况。每个答案占一行。 diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\245\207\346\200\252\347\232\204\346\257\224\350\265\233/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\245\207\346\200\252\347\232\204\346\257\224\350\265\233/solution.cpp" index e69de29bb..fa3cae0ca 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\245\207\346\200\252\347\232\204\346\257\224\350\265\233/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\245\207\346\200\252\347\232\204\346\257\224\350\265\233/solution.cpp" @@ -0,0 +1,31 @@ +#include + +using namespace std; + +int a[11]; +void dfs(int s, int u) +{ + if (u > 11) + return; + if (u == 11) + { //10道题答完 + if (s == 100) //如果是100分 + { + for (int i = 1; i < 11; i++) + cout << a[i] << " "; + cout << endl; + } + return; + } + + a[u] = 1; //正 + dfs(s * 2, u + 1); + a[u] = 0; //错 + dfs(s - u, u + 1); +} + +int main() +{ + dfs(10, 1); + + return 0; diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\245\226\345\210\270\346\225\260\347\233\256/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\245\226\345\210\270\346\225\260\347\233\256/desc.md" index e69de29bb..aac95a90f 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\245\226\345\210\270\346\225\260\347\233\256/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\245\226\345\210\270\346\225\260\347\233\256/desc.md" @@ -0,0 +1,2 @@ +有些人很迷信数字,比如带“4”的数字,认为和“死”谐音,就觉得不吉利。 +虽然这些说法纯属无稽之谈,但有时还要迎合大众的需求。某抽奖活动的奖券号码是5位数(10000-99999),要求其中不要出现带“4”的号码,主办单位请你计算一下,如果任何两张奖券不重号,最多可发出奖券多少张。 diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\245\226\345\210\270\346\225\260\347\233\256/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\245\226\345\210\270\346\225\260\347\233\256/solution.cpp" index e69de29bb..a92aeef2f 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\245\226\345\210\270\346\225\260\347\233\256/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\245\226\345\210\270\346\225\260\347\233\256/solution.cpp" @@ -0,0 +1,28 @@ +#include +#include +#include +using namespace std; +int main() +{ + int cnt = 0, flag = 0; //计数 + string s; + for (int i = 10000; i <= 99999; i++) + { + flag = 0; + stringstream ss; + ss << i; + ss >> s; + for (int j = 0; j < s.length(); j++) + { + if (s[j] == '4') + { + flag = 1; + break; + } + } + if (flag == 0) + cnt++; + } + cout << cnt; + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\255\220\344\270\262\345\210\206\345\200\274/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\255\220\344\270\262\345\210\206\345\200\274/desc.md" index e69de29bb..0db5c591f 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\255\220\344\270\262\345\210\206\345\200\274/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\255\220\344\270\262\345\210\206\345\200\274/desc.md" @@ -0,0 +1,48 @@ +#### 题目描述 +对于一个字符串 S,我们定义 S 的分值 f(S)为 S 中出现的不同的字符个数。 + +例如f(“aba”)=2,f(“abc”)=3,f(“aaa”)=1。 + +现在给定一个字符串 S[0…n−1](长度为 n),请你计算对于所有S的非空子串S[i…j] (0≤i≤j +using namespace std; + +typedef long long LL; + +const int N = 100010, M = 150; + +string s; +int Pre[N], Next[N], Idx[M]; + +int main() +{ + cin >> s; + + int n = s.size(); + s = ' ' + s; + + for (int i = 1; i <= n; i++) + { + Pre[i] = Idx[s[i]]; + Idx[s[i]] = i; + } + + for (int i = 97; i <= 122; i++) + Idx[i] = n + 1; // 右边界初始化 + + for (int i = n; i >= 1; i--) + { + Next[i] = Idx[s[i]]; + Idx[s[i]] = i; + } + + LL ans = 0; + for (int i = 1; i <= n; i++) + ans += (LL)(i - Pre[i]) * (Next[i] - i); + + cout << ans << endl; + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\255\220\344\270\262\345\210\206\345\200\274\345\222\214/config.json" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\255\220\344\270\262\345\210\206\345\200\274\345\222\214/config.json" deleted file mode 100644 index f6416a1a5..000000000 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\255\220\344\270\262\345\210\206\345\200\274\345\222\214/config.json" +++ /dev/null @@ -1,6 +0,0 @@ -{ - "node_id": "569d5e11c4fc5de7844053d9a733c5e8", - "keywords": [], - "children": [], - "export": [] -} \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\255\220\344\270\262\345\210\206\345\200\274\345\222\214/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\255\220\344\270\262\345\210\206\345\200\274\345\222\214/desc.md" deleted file mode 100644 index e69de29bb..000000000 diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\255\220\344\270\262\345\210\206\345\200\274\345\222\214/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\255\220\344\270\262\345\210\206\345\200\274\345\222\214/solution.cpp" deleted file mode 100644 index e69de29bb..000000000 diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\255\220\344\270\262\345\210\206\345\200\274\345\222\214/solution.java" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\255\220\344\270\262\345\210\206\345\200\274\345\222\214/solution.java" deleted file mode 100644 index e69de29bb..000000000 diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\255\227\344\270\262\346\216\222\345\272\217/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\255\227\344\270\262\346\216\222\345\272\217/desc.md" index e69de29bb..c31915634 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\255\227\344\270\262\346\216\222\345\272\217/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\255\227\344\270\262\346\216\222\345\272\217/desc.md" @@ -0,0 +1,35 @@ +#### 问题描述 +小蓝最近学习了一些排序算法,其中冒泡排序让他印象深刻。 +在冒泡排序中,每次只能交换相邻的两个元素。小蓝发现,如果对一个字符串中的字符排序,只允许交换相邻的两个字符,则在所有可能的排序方案中,冒泡排序的总交换次数是最少的。 +例如,对于字符串 lan 排序,只需要 1 次交换。对于字符串 qiao 排序,总共需要 4 次交换。 +小蓝找到了很多字符串试图排序,他恰巧碰到一个字符串,需要 V 次交换,可是他忘了把这个字符串记下来,现在找不到了。 +请帮助小蓝找一个只包含小写英文字母且没有字母重复出现的字符串,对该串的字符排序,正好需要 V 次交换。如果可能找到多个,请告诉小蓝最短的那个。如果最短的仍然有多个,请告诉小蓝字典序最小的那个。请注意字符串中可以包含相同的字符。 + +#### 输入格式 +输入的第一行包含一个整数V,小蓝的幸运数字。 + +#### 输出格式 +题面要求的一行字符串。 + +#### 样例输入 +``` +4 +``` +#### 样例输出 +``` +bbaa +``` +#### 样例输入 +``` +100 +``` +#### 样例输出 +``` +jihgfeeddccbbaa +``` +#### 评测用例规模与约定 +``` +对于 30% 的评测用例, 1 ≤ V ≤ 20。 +对于 50% 的评测用例, 1 ≤ V ≤ 100。 +对于所有评测用例, 1 ≤ V ≤ 10000。 +``` \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\255\227\344\270\262\346\216\222\345\272\217/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\255\227\344\270\262\346\216\222\345\272\217/solution.cpp" index e69de29bb..bd163915c 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\255\227\344\270\262\346\216\222\345\272\217/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\255\227\344\270\262\346\216\222\345\272\217/solution.cpp" @@ -0,0 +1,45 @@ +#include +#include +#include +#include +#include +#include +using namespace std; +const int N = 1e5 + 5; +char str[N]; +int main() +{ //字母只有26个,数大了就会超,剩下的还要分情况 + // ios::sync_with_stdio(false); + // cin.tie(false); + int n; + cin >> n; + int r = 0; + while (r * (r + 1) / 2 < n) + r++; + r++; + // cout<= 0; i--) + { + if (t > r / 2) + { + str[i] = str[i + 1]; + i--; + str[i] = str[i + 1]; + i--; + t -= 3; + } + else if (t > 0) + { + str[i] = str[i + 1]; + i--; + t--; + } + if (i >= 0) + str[i] = str[i + 1] + 1; + } + puts(str); + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\255\227\346\257\215\347\273\204\344\270\262/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\255\227\346\257\215\347\273\204\344\270\262/desc.md" index e69de29bb..d95211269 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\255\227\346\257\215\347\273\204\344\270\262/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\255\227\346\257\215\347\273\204\344\270\262/desc.md" @@ -0,0 +1,3 @@ +由A , B , C A,B,CA,B,C这3个字母就可以组成许多串。 + +比如:"A AA","A B ABAB","A B C ABCABC","A B A ABAABA","A A C B B AACBBAACBB"……现在,小明正在思考一个问题:如果每个字母的个数有限定,能组成多少个已知长度的串呢? diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\255\227\346\257\215\347\273\204\344\270\262/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\255\227\346\257\215\347\273\204\344\270\262/solution.cpp" index e69de29bb..b3d835710 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\255\227\346\257\215\347\273\204\344\270\262/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\255\227\346\257\215\347\273\204\344\270\262/solution.cpp" @@ -0,0 +1,16 @@ +#include +using namespace std; +int f(int a, int b, int c, int n) +{ + if (a < 0 || b < 0 || c < 0) + return 0; + if (n == 0) + return 1; + return f(a - 1, b, c, n - 1) + f(a, b - 1, c, n - 1) + f(a, b, c - 1, n - 1); //f(a-1,b,c,n-1)表示串中有添加一个a后,所以递归字符串长度为n-1 +} +int main() +{ + printf("%d\n", f(1, 1, 1, 2)); + printf("%d\n", f(1, 2, 3, 3)); + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\255\227\346\257\215\351\230\265\345\210\227/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\255\227\346\257\215\351\230\265\345\210\227/desc.md" index e69de29bb..4f46d2b65 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\255\227\346\257\215\351\230\265\345\210\227/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\255\227\346\257\215\351\230\265\345\210\227/desc.md" @@ -0,0 +1,122 @@ +仔细寻找,会发现:在下面的8x8的方阵中,隐藏着字母序列:“LANQIAO”。 +``` +SLANQIAO +ZOEXCCGB +MOAYWKHI +BCCIPLJQ +SLANQIAO +RSFWFNYA +XIFZVWAL +COAIQNAL +``` +我们约定: 序列可以水平,垂直,或者是斜向;并且走向不限(实际上就是有一共8种方向)。 + +上面一共有4个满足要求的串。 + +下面有一个更大的(100x100)的字母方阵。 + +你能算出其中隐藏了多少个“LANQIAO”吗? + +我就把这些东西放在了txt文件里 +``` +FOAIQNALWIKEGNICJWAOSXDHTHZPOLGYELORAUHOHCZIERPTOOJUITQJCFNIYYQHSBEABBQZPNGYQTCLSKZFCYWDGOAIADKLSNGJ +GSOZTQKCCSDWGUWAUOZKNILGVNLMCLXQVBJENIHIVLRPVVXXFTHQUXUAVZZOFFJHYLMGTLANQIAOQQILCDCJERJASNCTLYGRMHGF +TSDFYTLVIBHKLJVVJUDMKGJZGNNSTPVLCKTOFMUEUFSVQIAUVHNVFTGBDDARPKYNNCUOYUAZXQJNOEEYKLFRMOEMHUKJTPETHLES +FKVINSLWEVGAGMKVFVIUBMYOIAFHLVNKNTYKTZWVXQWRWIGPENFXYDTKRVPKRTHMGHVYOCLDCKMEKRLGEKBYUCLOLYPAKPFSOREH +KWPUOLOVMOFBIXYACWRDYBINTMPASPCEOKHXQIGBQQMCEOIVULIEOPFSCSIHENAJCVDPJDOIWIIULFDNOZOFVAMCABVGKAKCOZMG +XWMYRTAFGFOCNHLBGNGOXPJSTWLZUNNAGIRETGXFWAQSSJPFTQAXMTQWMZWYVEPQERKSWTSCHSQOOBGXAQTBCHOEGBDVKGWJIFTG +ZWWJEIISPLMXIMGHOOGDRZFTGNDDWDWMNUFWJYJGULPHNUFSAQNNIUVAAFZIAZKFXXNWCEABGJAUMGYEIEFVQXVHHHEDYUITRCQB +XZHDPZQTOBECJVBZLACVXACZEDYOGVAVQRNWEOWGRAQYUEUESTEDQTYJUTEFOOITSHDDZHONJGBRCWNEQLZUTBNQIADKNFIOMWZR +EBFKCVNLURZSNPOLTISRPDTNUMCDGKTYRGIOVEPTUTSBAWQKWWEUWIWHAANUZUADGZEATZOQICWFUJTWNZDBKLQNELWVTBNDLNFH +PESISEATZNCDFRMXBQUKBFTIGYSFCWVHPMSUSDKPSCOMVLDOHYQVFHAJKRDTAVLIMNZBZSMLMRTLRPSLAHXDBASDMWAAYBPYVJZF +SCCWYHLQOUKBMCEYENQNJXFOMOOJMTKDSHJJOHDKEGATFZHGWJJAZJROWHAZUFGEQKPYXLCAAXHHQBDALPYUDWZQHBASBBCFGQCQ +ZKNXUBRYZVSPQHOVLAEUAUITMPWXNXJQVIBJVBCSVXKWFAFRPRWOLYVSDVTGGOFFMNQJZOBUDJLFHJTCYMPNOBHQJHGKLIKLZMLA +POCKVEQXUAVHERIAQLGJHYOOVOMTXQFRTBFSETOZICPCHZHFBWNESVJJLSVSVOOGYYABFESWNWDNYBGBNAKRCFQMTCUMIFTESVIN +JCAULIQRYUMAMAOVVWSEUTMECXSDTONRMMROQUISYEURSAYNZUVOPXLIFBDOHPXMABBLEQZGLJXQJOEYYRRRCFTEZQAOIWKRJQDL +ZNUUDWZXZZURPMHGXQGNQBIQWWNERZWULSAPIBODBFFQQIHEQKCKLJYQNXQUTAAYGRBXSLLQNOQPZJEWHETQHPXJANMJFOHINWOW +KJGAWWFSVIZHFNUWBLWYVPIWAEICCAHOEIWRADSLOZGPSVGPUBUUQAVYCHOIGINKYKJABWAQCZCXOBKTNJZQRHLUFKQLACAAOIWJ +SIKWLXQHKDFJVGBVXWDWJKUSFRQRTDJYQMNFOQQALHRLMHSDMCFLAOVKDMTKMTPVTLAZLYJNJXZCFRHHSDIXYUUSVIMIICLUJHFW +JHWUSMCFYHPIXHAPBBSHYDQCKVGQFTENLVERFVOVDCLSTQFUSEPUMTFODLZLYQXDOXAEPONIQWTDWSAWBNSZYACGSJQSHAUMIKXT +MVBNFXMFNPAYSODPXEAYNRKTEZJWMUACSIUYPIORUFPMXAOZZJPJXPFLNSKNIAMETMOVULZPQIJJIRCSYQXOEVRHCNACSBRHKYNW +KGKBTBHGWKVJYZCOVNSKUREKZEIWVLOHAMUAYKLUGHEUESICBZAHURNTJAECTHRNKSIJQFIPVZANSZYSPJWHPKHCAPEYWNXUYQSD +RRRFYQFIQSWYRQTSNGNUFOBMSLGAFWPJGYEHGASFKTJCCZPXFIQLSXNKNWCYVTETOAPCOZJNHEWOCCAWVDEZUQCLLAVUQJJTQCKJ +NMBKMUENVGXXVMQCLXPJDQIQCFWYADIFDSGINGZDJYHPUPXVRMWDIPJRWPNRYOFGYYPEAVKDEMLYRRRMNCRQXPTDSQIVKKGJWDEF +SBAEKIFZCKDOMIQKBDWVQGBYWPDIBOLQUGAQRXLJDAZMXVZXYSNWEWTNZKYREMBEUHOTFOCKEJSXCMUBCKXNGQXTQJRCRCLWJTOI +YXBFBIBRAAFNPKBLTSMCFERZURZNWHMOEHIHNQTBWXNPJGIDYDPRGEWACCBULJRACOFLANQIAOIHMYCNQHVKXSIGAMWAHUSNBBTD +QDGPTRONXHAZWOUPNBFJFEWAMFZUQZFDKAPNJUBQPWBPYGPZHKUDZZDLCCWHGAUKJCSLLFWGPYJKJQBNLCZESOGXXSQCVVKVRVAW +NXPGQOUEFLUZHHSAODIWEPZLXVQLYGVOOVCCREDJZJOMCSCFFKEIEAVCTPUZOWNOLJHGBJHJFBFFORGXOXXFOCAGBWEFCIDEKDLB +PTXSUINQAJURNFQPMMSPLZTQAHCIOFJUEFFZGIHTSJNIEXQLLHRQUXXLLORJEHGQJOXSLIAVFPEJNGMMVAXDDMPXLOSTRLLFLYRM +JQNCLENGTROIKDWBMXRNJYPGZRQOREPJJPTXKVVKPYYZENEOIQKZOPXAYGFXORXRIDGATHMZFDJIOIOKVDJBHSXQMYCBYFGXWHLH +CITGTILGPGBHZMNWWHXEFPGDPJUVFBJKAQWACZHPRPJYCOLGZTBDCVHNRSUAJUQAWAPMQJDQIFPZQZEONWHIYKMXDZOMVETEFJRB +RDOTIDCFEESOKYPYCGQQKOGPMGJRITSVTKOKDSXLRLJRRHNFRFXCMDNQMCEGZFJWHZOAFBQXXPXNBSWTSUYPAWQRHAUGLNPBRSJT +HOWRIUGMOQTUYIHDWJRFBWWKWYKCICSVBVKTBIIWGFSVIFCTUKIHHUUISCOTEOYRWQXTAEBXQQOLLMOALNIYVCCHNSWIKHMYYNZO +OFRIYYXPPSRTPAYMUJSSDILKIZAYSEIOLANQIAOVKARDPGVFCSYBSNHAPGTIKLAWTTKOEADWRLAACAAFYTBTNSGFTYLYUHJXBMMA +NJFTMLUIBKDPWBXQOMBVQXCZOIREHRSZCSJOIVBXWQIBUTYBQNTZRVROHGOIZYAJWXLEATLOZJIKJMIHSLGSVTCXJWIOOGWSERRQ +DBQJNGBLRIYFIKHBEYOZQBOAGGNIZKFDHWXCFNJLBQXVLHIQNIBZSDLTTRERHNWCMLJCVBBGGAQTPUQHIRABXPQSYGSDVMBNNDFG +KPLFUYXHYGOCZPPXMWCZYNKCYBCRZVKFBHQXPGPBZFTTGEPQTJMOFHAYSQQZDMQECGXOXADYHNNXUKNBXZBYHBOULXNBJZKIZREF +LVHAMSNXJOCVRPVGJUWXFVOCUCLCZDXRPBBDRLRAVVNLOZWOHWMXYSNMXAKJYWYGILNGUJGIPKAUDVANZLFWKUWWUSQYBRCBVDIJ +QCXPLOTPPGXCUZOUSSTXHVMLHVMJTUSSOPLRKEBQSGWNGVHKANVZWYQHSHLIPWSYCPKTUKPMWPLVFLLAHXZQANFXHFNYHIQVIOYN +ZPTJJCBHXPSUPOMNRVCKXSUFCNRCRNCPTPGIDQOEQUDFNUNMJPOEKVIMUJAJZOUKMAFSLDWYMCHTSNJYUDJAHQOIXPYSRHVAFFCR +DCGMEEWXWMNOSSJNIZCINRHENPPPCYVFWYCONOPKXMFZXXIHNXIGAHAMHSBRESOETGVXWDNQLGCEOUDDJXHQIVCHRNKBFFEWILGY +SOAIQNALXRBSGAQIDQVMVDKVZCPMJNXKXRXPFZAUVQPBHHQKTPDSQROLQTUGMFQRWGVEWCYPDYDZGNNNUFKJUEHJKPLIQNRQYXHU +GKGWUCJXUKAEHLRLNDFUQPSJAZTVJRXWXQVBMRJXULEMJJPDCVTOWVFDBVLSBHZRRQUVMUQYKTJCLSGGHGCPHPHMWYAECLJIZUWV +QQNKPQRJMSOCEAYDNKPHVEGKAGCKAPDXTGVXULHUXHJPDXCSKQTCJENVTZTMRUENCSWHBEORALSREBWAJEMQDXMRKGHJGICDHKHY +YNSDSWDRLBBFUFVVICMGUCGBSVDLJNXGKXNFGVLKAVBJRRRUHKRXTPBJAKIEBAVMDIOJLIUDABCGNPNJIYBCXMOOWKRPHPYSWRDC +BORWTNBISSLTVKBRTLWKRNCEDCNEGCIYJIPDICFAVNOISYAHWBLGMNFKXZYTTWJOBEPNMSJEJMHXVPGOJOLQQQVXFGEULANQIAOD +OQETOJHCZXGTUKIWGMEVVMXCURISUOFQSAWZWDMZWVYHZMPEIMWKJDGERODVVUXYRTYLCRGYQQOIOFZSSZRAIESWBQOAIQNALJNR +HEYWHPLLPCUEOCBAOWGAYEJZQJHLVNMVQNSQQGGUBOIMDPFLOVSQGBLYAMBRYJDVOXOQINLJAVYALAKHPKOYNKGXIISSJNGKHYMS +IQVRYKXCUFIRNENEXFJTMOTJWYXSMTDHHPRHWIXETWVVIXZELKLLWRWQYGBCGJNYSUQEFCOUDNIJMLJNLAWSYJGULKBCFPYVSSMW +WQHGWRQFWFOTGPBBSJBDUKOMBXNRPIMCGPGVZFADWTBVIEMVTBXVAFQDDMJALCOMZTXUFFKBQQZDFAMTFWEXTHBKNWRLUVITQXLN +OPPJQKNGHWWPENVQIABJCQNKXNPWOWRFEOKQPQLANQIAORGGOLAYCEGZBHZVLPBERWYIJNJUNXKULUQOJLTNRDZDEYWEMYCHJLLB +LJISOAQLXJEFXVTOZSICOLQIJEXUANJWIFSIMGUQWHBXUDWOEILYFUZTGDZDSPLZPDPXBLFAXLEFQFEPDSJQWEQMXKKHCXHMSATM +UMUJENPBYKZLWAJAXJKDIYCBREBPOETQHMRHLKSEZUIPRGWIZDDQLSJAPKPBWMJMPZWLNFLFCQOCDBMLIHIYCXUJLFLPZVGWBKMY +WHZJLKEWUPETVUREKVKCLBNYFLWCERVIPUDINNWGQTUHWXCTDVTMYATYUZLMVLOHKBOGIZCQDOWFBCWJAVUXYUEVRKPOXCKHAWZC +RPLNLCUHJRADHJNSDPZXIKXGUKEJZCFJQASVUBSNLXCJXVCJZXGMRYRLOBCNGPDUJQVEFKMYHNZGZOAIQNALQDHTBWJXPKJLFXJY +MKCEZEDAFGSOCORWJGMOKWPVVBVDYZDZHPXFWJBDELHPGOQHMBAHUUUJMGXAEKZCTQTBXNVYUIQUVZGXSKQXJWRUPSFIJDYIAORC +GKFKQNXPJWOPPBTUKTHUBIROSYOVFEMJBRREWICJPCIOSTWPAUSKTRQULXPWRSXHSRYBCWYCYOTCTPFSQLDIILIGMEVZKYSOYRPH +SFDSCSMLLNARCCGCBJOGZAEQTGNGSFAQIXLPDBSWZDTYVASYYPVBRFBTIAGGWONGSVKCJDBBLYKAIOXUATGMALZXFOHZFTXALCFU +CUSSTLCRYPDTFSFJFENKJWTEBOBEPLSNXLALQWCKSLVMZQDJITHZKVCCQXTEXOSVAUFYAZXJUOAPPVEEWOIIMOSZZMCOQBRUXWKG +PDOFSCKKJJTRYRWGLEZODQTJSIMXIAOLNMLPHBAYLPTTLPYWILSEIIQVSXNHIJEORVCNJHYXRBIZZJTADGMRTSXVRXYGVQQNUEIC +IHNJOQXUXTXFPALCHOELNVMWDWQTEARUKPIFWXJSMWZLMNLAODUTKNZDYRFRLGBLIBGIBXJBOYMLYLANQIAORORYKSJPOOOAMVRN +IWIUHLYJKTQGVJBDPROSRGZUFITDIBCDPICNEFIGHWGSROWBYKUCLCQYLJXLHLXSCTJWKDLHHMLDBZCVDKPXYYASHUUMUJMVSXAD +GXOYXQFEBFIEJJLHBNGSYALOUXNQBXXZAAZJXENJJVVGFVHOTKSLEGLJVSJCQHSSZFEIOGBOGWSPIRENQAAWRQFBEFEXBKGMSTRC +PYIANSGMNKBCDPHWDUPKICQEUDNZPNGRUJYSZIRLXGXXITAFBCANGDLVAQLDPVTJNSAUZMBBNOBBOERSHQIOLBVTSPPJKVCMXUBS +IKMDIYSNCJZKJKJQMTIKEPRUNAHJUSWJHSLWIVWHYAYLOIOGSZVWKQWXZDBPHWZRAIPMXDJHBIISVJWVEVZAEGAKCYYMNZARBZPC +DLDFVQDFDMVHYVOWEKMFKWUXLTPWIVKPRZZXOLMDAPAIQEKJHCHYAGJDBOFWDGNEGQGOOKWSKLTLREMGGTVJFHAIBCQKNZVRCZYS +FBQASGNCCBBGNKJHCDBTGBIIWKMPHDABKEWDEPYEAVKNMPATUZZUOEHGUGAZNECSGUCIIJPMMRAMTVADMTCRJCBWDLWWFNFOWMVZ +XFJFBGDAVGGAIZHAUIYENDZTRUWHPQUFWCHOXNCWYNAWVPLBLNQKQDTKQQKXNFXCTBGRWUZFHNRBDNLNKQVOLLGBBJQIYOBCEIKO +CURAGWXMLYBSIZLAXFONZZMQMRNNSRQKRHQGFGZUTLONAYRKSSOWAMKZBSGOOYQDPTBHGPBNQEDCZHRTOXREOFJEKJVIZXZBCJPN +KGYBZTZRKOGBETJRUWRNUCIFKIMCZGYTZLCZYGCGKVZRJIFZQIQPTCPPUHYWIXBOFFGSGSAIMNGKKUUROAVNJUQQNSWJRZIZEHAF +DDAOBVCPOVODVJFLSNPJXHWQBHILWZAHQQMTQASNADZLZNXJLJMFCOUWOZJCMVVTYCKTUBABWLCEBNYWAMOLNBQQYBRUJCQCZALE +TVVRPMYFIKINHIUEJBDLTCUMMUWICIUVCZNIQIUEWVAHLANQIAONMEYJWPDAFXVNOSOFDOCESSLGZPTJINBUAFWWWMPTYALZIGVD +DCZGKILMBFXIQQFEKJBIUDEMIFCANVGNYZAYSQFMNNQFEPZFUUVGTBKSMDXITBLANQIAOQUKTPNYPOWSQQYWWMJHSDYVFDJYXBAF +VGYXAMDRRZWVIHNQPZZWRNWBTROOJOLNUGXBILZKQEGIQSYGKZGODPWBJSCMRRWSSQURUFIAFQGEZLGZNOEQMNQEYUKPEQPPVAMO +SYSFUAJFKIPUJVQSZRWQCJYAUMLDDNOKODDXIEQIFLANQIAOZFUNKUBVDBLMJOAUTVCZVLKJRQIORQPGAVCEYVNYUZHXILHERYEC +GJEKWEKIJNIWUXZNVIWIAANHIOSOLATSQFSSCTAKESUTSPPYFHEHLVLIBJZEEBCOWMNHFTZMAPKFUPNFLTFFJQRVJHAKDVMGGUIX +KAKXXNKSOAIQNALLWKWGVACYWBQEVTFSEUCYRORQTHWFUJFLQHONWZEKPLSNPRPBOMOFFCPMKXFZBKIERBKDYFKYUEYVYRPMOAQI +WNICDLQKZXGTKDLIEFBGELGJOAIQNALXZLGGDQIBVEULDPBWUJNTYOKFBPGMAWRRUJPPIGYCNYURNOSQRIRBAZAGWWDUHAAZQWPT +KFXZQXRMKSBUXWOUVVHSJWTLKZELGXMMAIDSJIWGCJPCBWZIEKMNUPUAFHTUMOZKJWVTIAQNOHELEMWGKJHKPNJVSRVHAUFXBUOU +XOWCZJYQLXJRUOOYSKDLDXKWTTJBYBTLKSWRUYPOYTPBGUJXBMRWNELBWADCSZDAEEFGPVRHNNLBFDDXNPDXLKQUSJAZDEUDBMBD +QIKYEKMVUHGGWZDKXFVQQNECZOAWCFUBHQMEPEPKEFSDBAYJQOSGAIHRBRAUKLQRANKMTTIOJDDXAEWTQHIYSGRRMEFTNNWCLZSI +ZFUQAQCSFNVUQMKUQWBWFQIEQVVXPOSVIDTUOBLLTGHQKEMSUWWHWRISLGRDPPQPZBANSGDWXKNYTKMWECPMPDYSCJZXPUKPWGYI +CNGVLBSCBHRLJARWSRENGHYYQDKRATERCPEAOPAJZUMOYIDHVPDMQPKKHCBAMRBGEIEXXJALMCXKPUGXYVINRORFYURXAMOJCBZQ +YJHHAWESCLMDIHVYMLAJZQSYTDEURWYPOLJCAKIKSATGVIALBLWPPKDEGSPMRLDBQNVPPCLQXKUQLQJERMYFGAETUATEBQZUMGUN +NBWUBVXYDFPLPJYLIDFVTVKKGFWMXVINLJUDUPABTSBJAJENZSXIMUJQWPEZTAVDMBBHFYTJKYFXIXQTBTTQIKQXQDPWYNMXRQDJ +OGWLZQUBJJHAQNPVRGHGPNMMJPIDGANYEEDWYPOLKLNEPYSRTQYCJLSWFRJRRGGSNSDHIXYYSNAKKBWQDDGYYMOGPUXQEUSAPSOU +CLLSELRVFZUFYVTJQKCQHNICMERWQFQNPVRPIIYKHZWJYJAFCLNSZXUHSPOZWQUMJHLKKYJENVZOCSWCTPYWIZONUUCLSUROGAYS +AZGNIMXPLPCEPULRRBHHQOBELHJZPUQAMWUASVKDXVEWAOFMAYSJFXHCNEUXUQWUESFBRUFZQLKKWHCHKOPLECCBYSLECAEZIMMI +TUUEOCEBAUKWLTSYJJPLZTIARAOZXKYYWIOXBBTZZCSAULKNEJWVQXIKUWBIWVHGNTHVBAWAVPGLHSDJDLPVHHHUNVSFKXARXLVQ +EMVDFSLANQIAOPTLFLFRKGNUZCTXWCAXHECTZFHWUFENRGQICHTYLSHZWIEGLNVDJZOMTKAAUWOHVOVOCTUKOSINSAYIAEUYORNA +VGPRMLCAQZIPRFQOZMEFTQZYVOTVFNVOIQSJCIPPQXQKJIXICUIGMHAJJMSXENCBQFIJHNZXIQMWACKDKQSEWWKMLOAUPFHAZGRY +SQWQMRSQBGGKYKGWEZYRIHWGNXRPOUMFSFGTYDLUDWPWAVQORTMQUXWKUQVNMDPWQFIZPOIHCJATODRQGZDMQXZVNXXVEJNGWZOM +PVBGZSQPCELDIWDHOQWAUHILGLPYRIICTLFSOYKQZYZOCIZPTECSWOODGGBDTSGIMYGMVPJPRPEVWOOKYFWRGXHWUCRQNYJEMSYL +XWOFXFVDXPTHYTCEGMODCILAHYBREZVVHOUPZKCNHUEVPMKHUBNRPFMWXVQACVZCALZLYMZSBLCEASPMIEFOTGKMPGWYQADSNDPR +QPHAVLZDZLKIEISFLLVWXAVBZLZIJRHGROUVGXRDLUJAXNHBBZYNCVERJGSKLWZEKGJBCWMSMLYIHZFFMIOGVIMZQBSRHQWAADYN +MNXEGTDXCDKIUDOISQXEUJWETPELKBCYFSDNJQWNNBPYMWBUPQBAAINMYZOYCEGNLFNNHZFEMSQVXJJGWBCRAVKZFWFBKMBRVBFD +HKACSZIUWUXLWKFPKOCUQJEPQDZCMUJFLVCLIOQQRVKSWFIAKNHMRLNJTKGVNTGLCVPVMBLJANOBCXUGVWBJYSIXZQVAVFWILWFB +QWNLTPMCYHRSKVHXLONRANWKWXUTHYQLIOFKGDBMSWDRCYRKVSAGGRJMWQYQFLMUIGGCLAUQAACTYLPZEOJBHMWRKHCRXGTGRMUP +CPQKJRBLYDNPUGHCRBVYBAIRVCAWLBWVWCMKNBIRKJOUGYQEBQRHDSTWXDIWGRVMLIJFBWHLHCDAAVUDLZSCGQNOUXVUIVIZZZMD +NMHGYPFUUDWKQGTAKKGCDFJFYJFNRZVXDPGZEAMWQVQZODKTXHIYFVKJSSAWVHYCUCZMLLBPXTILDYJQEMWDRUFKISOUVPUDTYPB +FDAQUBXHUJYTAYNWVIJNUSQDTQDEMUAPWXRYUWONTBDZCHZOUEGPMWEZTQWWSHAYOBWVTDIMZYNVNZKUHOFCQKPHJXWNRCGUJEKO +WSDAUGUTVWCVHEMOIRJJGTANUWTSAIXXEVZTBDHPGSRHHVWCDZVZYRJTLONIJVXEATHQXOUKBIGZONFRSZIOGWNTYAJYLQCGEOWY +``` \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\255\227\346\257\215\351\230\265\345\210\227/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\255\227\346\257\215\351\230\265\345\210\227/solution.cpp" index e69de29bb..b9a6c44a5 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\255\227\346\257\215\351\230\265\345\210\227/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\255\227\346\257\215\351\230\265\345\210\227/solution.cpp" @@ -0,0 +1,51 @@ +#include +using namespace std; +int main() +{ + char a[100][100]; + ifstream fin("1.txt"); //我把那些字符放在了1.txt里,读取它 + for (int i = 0; i < 100; i++) + { + for (int j = 0; j < 100; j++) + { + fin >> a[i][j]; + } + } + fin.close(); //关闭读取文件 + int sum, i, j; + for (i = 0; i < 105; i++) //把Q放在前面,分成八个方向分别判断是否成为LANQIAO。 + { + for (j = 0; j < 105; j++) + { + if (a[i][j] == 'Q' && j >= 3 && j < 97) + { + if (a[i][j - 3] == 'L' && a[i][j - 2] == 'A' && a[i][j - 1] == 'N' && a[i][j + 1] == 'I' && a[i][j + 2] == 'A' && a[i][j + 3] == 'O') + sum++; + + if (a[i][j - 3] == 'O' && a[i][j - 2] == 'A' && a[i][j - 1] == 'I' && a[i][j + 1] == 'N' && a[i][j + 2] == 'A' && a[i][j + 3] == 'L') + sum++; + } + + if (a[i][j] == 'Q' && i >= 3 && i < 97) + { + if (a[i - 3][j] == 'L' && a[i - 2][j] == 'A' && a[i - 1][j] == 'N' && a[i + 1][j] == 'I' && a[i + 2][j] == 'A' && a[i + 3][j] == 'O') + sum++; + if (a[i - 3][j] == 'O' && a[i - 2][j] == 'A' && a[i - 1][j] == 'I' && a[i + 1][j] == 'N' && a[i + 2][j] == 'A' && a[i + 3][j] == 'L') + sum++; + } + + if (a[i][j] == 'Q' && i >= 3 && i < 97 && j >= 3 && j < 97) + { + if (a[i - 3][j - 3] == 'L' && a[i - 2][j - 2] == 'A' && a[i - 1][j - 1] == 'N' && a[i + 1][j + 1] == 'I' && a[i + 2][j + 2] == 'A' && a[i + 3][j + 3] == 'O') + sum++; + if (a[i - 3][j - 3] == 'O' && a[i - 2][j - 2] == 'A' && a[i - 1][j - 1] == 'I' && a[i + 1][j + 1] == 'N' && a[i + 2][j + 2] == 'A' && a[i + 3][j + 3] == 'L') + sum++; + if (a[i + 3][j - 3] == 'L' && a[i + 2][j - 2] == 'A' && a[i + 1][j - 1] == 'N' && a[i - 1][j + 1] == 'I' && a[i - 2][j + 2] == 'A' && a[i - 3][j + 3] == 'O') + sum++; + if (a[i + 3][j - 3] == 'O' && a[i + 2][j - 2] == 'A' && a[i + 1][j - 1] == 'I' && a[i - 1][j + 1] == 'N' && a[i - 2][j + 2] == 'A' && a[i - 3][j + 3] == 'L') + sum++; + } + } + } + printf("%d", sum); +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\255\227\347\254\246\344\270\262\347\274\226\347\240\201/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\255\227\347\254\246\344\270\262\347\274\226\347\240\201/desc.md" index e69de29bb..c221a64bb 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\255\227\347\254\246\344\270\262\347\274\226\347\240\201/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\255\227\347\254\246\344\270\262\347\274\226\347\240\201/desc.md" @@ -0,0 +1,32 @@ +#### 问题描述 +小明发明了一种给由全大写字母组成的字符串编码的方法。 + +对于每一个大写字母,小明将它转换成它在 26 个英文字母中序号,即 A → 1, B → 2, … Z →26。 + +这样一个字符串就能被转化成一个数字序列:比如 ABCXYZ → 123242526。 + +现在给定一个转换后的数字序列,小明想还原出原本的字符串。 + +当然这样的还原有可能存在多个符合条件的字符串。 + +小明希望找出其中字典序最大的字符串。 + +#### 输入格式 +一个数字序列。 + +#### 输出格式 +一个只包含大写字母的字符串,代表答案 + +#### 样例输入 +``` +123242526 +``` +#### 样例输出 +``` +LCXYZ +``` +#### 数据范围 +``` +对于 20% 的评测用例,输入的长度不超过 20。 +对于所有评测用例,输入的长度不超过 200000。 +``` \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\255\227\347\254\246\344\270\262\347\274\226\347\240\201/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\255\227\347\254\246\344\270\262\347\274\226\347\240\201/solution.cpp" index e69de29bb..84d13fcc3 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\255\227\347\254\246\344\270\262\347\274\226\347\240\201/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\255\227\347\254\246\344\270\262\347\274\226\347\240\201/solution.cpp" @@ -0,0 +1,36 @@ +#include +#include +using namespace std; + +const int N = 200010; + +char op[27] = {'0', + 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', + 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'}; + +int main() +{ + string s; + cin >> s; + + string ans; + for (int i = 0; i < s.size(); i++) + { + if (i + 1 < s.size()) + { + int t = (s[i] - '0') * 10 + (s[i + 1] - '0'); + if (t <= 26) + { + ans += op[t]; + i++; + } + else + ans += op[s[i] - '0']; + } + else + ans += op[s[i] - '0']; + } + + cout << ans << endl; + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\256\214\345\205\250\344\272\214\345\217\211\346\240\221\347\232\204\346\235\203\345\200\274/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\256\214\345\205\250\344\272\214\345\217\211\346\240\221\347\232\204\346\235\203\345\200\274/desc.md" index e69de29bb..f8fd13f09 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\256\214\345\205\250\344\272\214\345\217\211\346\240\221\347\232\204\346\235\203\345\200\274/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\256\214\345\205\250\344\272\214\345\217\211\346\240\221\347\232\204\346\235\203\345\200\274/desc.md" @@ -0,0 +1,24 @@ +#### 问题描述 +给定一棵包含 N 个节点的完全二叉树,树上每个节点都有一个权值,按从上到下、从左到右的顺序依次是 A 1 , A 2 , ··· A N ,如下图所示: +![](https://img-blog.csdnimg.cn/20210402205939738.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTc5NjMxNg==,size_16,color_FFFFFF,t_70) + +现在小明要把相同深度的节点的权值加在一起,他想知道哪个深度的节点 +权值之和最大?如果有多个深度的权值和同为最大,请你输出其中最小的深度。 + +**注:根的深度是 1。** +#### 输入格式 +第一行包含一个整数 N。 +第二行包含 N 个整数 A 1 , A 2 , ··· A N 。 +#### 输出格式 +输出一个整数代表答案。 +#### 样例输入 +``` +7 +1 6 5 4 3 2 1 +``` +#### 样例输出 +``` +2 +``` +#### 评测用例规模与约定 +对于所有评测用例,1 ≤ N ≤ 100000,−100000 ≤ A i ≤ 100000。 diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\256\214\345\205\250\344\272\214\345\217\211\346\240\221\347\232\204\346\235\203\345\200\274/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\256\214\345\205\250\344\272\214\345\217\211\346\240\221\347\232\204\346\235\203\345\200\274/solution.cpp" index e69de29bb..da487152e 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\256\214\345\205\250\344\272\214\345\217\211\346\240\221\347\232\204\346\235\203\345\200\274/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\256\214\345\205\250\344\272\214\345\217\211\346\240\221\347\232\204\346\235\203\345\200\274/solution.cpp" @@ -0,0 +1,28 @@ +#include +#include +#include +using namespace std; +int num[100005] = {0}; +int main() +{ + int n; + scanf("%d", &n); + for (int i = 1; i <= n; i++) + scanf("%d", &num[i]); + int ans = 1, k = 1, max = -0x3f3f3f3f; + int x = log(n + 1) / log(2); //完全二叉树的层数 + for (int i = 1; i <= x; i++) //层数 + { + int sum = 0; + for (int j = 0; j < pow(2, i - 1); j++) //每层的节点个数 + sum += num[k++]; //每层节点的权值 + if (sum > max) + { + max = sum; + ans = i; + } + } + printf("%d\n", ans); + system("pause"); + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\256\214\347\276\216\345\271\263\346\226\271\346\225\260/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\256\214\347\276\216\345\271\263\346\226\271\346\225\260/desc.md" index e69de29bb..133a9dffd 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\256\214\347\276\216\345\271\263\346\226\271\346\225\260/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\256\214\347\276\216\345\271\263\346\226\271\346\225\260/desc.md" @@ -0,0 +1,4 @@ +如果整个整数 X 本身是完全平方数,同时它的每一位数字也都是完全平方数,我们就称 X 是完美平方数。 +前几个完美平方数是 0、1、4、9、49、100、144…… +即第 1 个完美平方数是 0,第 2 个是 1,第 3 个是 4,…… +请你计算第 2020 个完美平方数是多少? diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\256\214\347\276\216\345\271\263\346\226\271\346\225\260/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\256\214\347\276\216\345\271\263\346\226\271\346\225\260/solution.cpp" index e69de29bb..32630ae7c 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\256\214\347\276\216\345\271\263\346\226\271\346\225\260/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\256\214\347\276\216\345\271\263\346\226\271\346\225\260/solution.cpp" @@ -0,0 +1,84 @@ +#include +#include +struct bign +{ + int d[1000]; + int len; + bign() + { + memset(d, 0, sizeof(d)); + len = 0; + } +} a, b; +bign add(bign &a, bign &b) +{ + bign c; + int carry = 0; + for (int i = 0; i < a.len || i < b.len; i++) + { + int temp = a.d[i] + b.d[i] + carry; + c.d[c.len++] = temp % 10; + carry = temp / 10; + } + if (carry) + { + c.d[c.len++] = carry; + } + return c; +} +bign multi(bign &a, int &b) +{ + bign c; + int carry = 0; + for (int i = 0; i < a.len; i++) + { + int temp = a.d[i] * b + carry; + c.d[c.len++] = temp % 10; + carry = temp / 10; + } + while (carry) + { + c.d[c.len++] = carry % 10; + carry /= 10; + } + return c; +} +void print(bign &a) +{ + for (int i = a.len - 1; i >= 0; i--) + { + printf("%d", a.d[i]); + } + printf("\n"); +} +bool vis[10] = {false}; + +bool judge(bign &c) +{ + for (int i = 0; i <= c.len - 1; i++) + { + if (!vis[c.d[i]]) + return false; + } + return true; +} +int main() +{ + vis[0] = vis[1] = vis[4] = vis[9] = true; + b.d[0] = 1, b.len = 1; + a.d[0] = 0, a.len = 1; + int num = 0; + for (int i = 0; num < 2020; i++) + { + bign c = multi(a, i); + if (judge(c)) + { + num++; + printf("%d:", num); + print(c); + } + a = add(a, b); + } + + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\257\206\347\240\201\345\217\221\347\224\237\345\231\250/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\257\206\347\240\201\345\217\221\347\224\237\345\231\250/desc.md" index e69de29bb..dd1dccc36 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\257\206\347\240\201\345\217\221\347\224\237\345\231\250/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\257\206\347\240\201\345\217\221\347\224\237\345\231\250/desc.md" @@ -0,0 +1,41 @@ +在对银行账户等重要权限设置密码的时候,我们常常遇到这样的烦恼:如果为了好记用生日吧,容易被破解不安全;如果设置不好记的密码,又担心自己也会忘记;如果写在纸上,担心纸张被别人发现或弄丢了... + +这个程序的任务就是把一串拼音字母转换为6位数字(密码)。我们可以使用任何好记的拼音串(比如名字,喜明,就写:wangximing)作为输入,程序输出6位数字。 + +变换的过程如下: + +第一步. 把字符串6个一组折叠起来,比如wangximing则变为: +wangxi +ming + +第二步. 把所有垂直在同一个位置的字符的ascii码值相加,得出6个数字,如上面的例子,则得出: +228 202 220 206 120 105 + +第三步. 再把每个数字“缩位”处理:就是把每个位的数字相加,得出的数字如果不是一位数字,就再缩位,到变成一位数字为止。例如: 228 => 2+2+8=12 => 1+2=3 + +上面的数字缩位后变为:344836, 这就是程序最终的输出结果! + +要求程序从标准输入接收数据,在标准输出上输出结果。 + +#### 输入格式为: +第一行是一个整数n(<100),表示下边有多少输入行,接下来是n行字符串,就是等待变换的符串。 +#### 输出格式为: +n行变换后的6位密码。 + +#### 输入: +``` +5 +zhangfeng +wangximing +jiujingfazi +woaibeijingtiananmen +haohaoxuexi +``` +#### 输出: +``` +772243 +344836 +297332 +716652 +875843 +``` \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\257\206\347\240\201\345\217\221\347\224\237\345\231\250/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\257\206\347\240\201\345\217\221\347\224\237\345\231\250/solution.cpp" index e69de29bb..37b425542 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\257\206\347\240\201\345\217\221\347\224\237\345\231\250/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\257\206\347\240\201\345\217\221\347\224\237\345\231\250/solution.cpp" @@ -0,0 +1,71 @@ +#include +#include +using namespace std; + +int toOnenum(int n) +{ + int sum = 0; + if (n / 10 == 0) + { + return n; + } + else + { + while (n) + { + sum += n % 10; + n /= 10; + } + return toOnenum(sum); + } +} + +void change(int num[6]) +{ + for (int i = 0; i < 6; i++) + { + cout << toOnenum(num[i]) << ' '; + } + cout << endl; +} + +int main() +{ + int n; + cin >> n; + string *arr; + arr = new string[n]; + cin.get(); + for (int i = 0; i < n; i++) + { + getline(cin, arr[i]); + } + for (int i = 0; i < n; i++) + { + string buf = arr[i]; + int x = buf.length() / 6 + 1; + string *str = new string[x]; + int z = 0; + for (int j = 0; j < x; j++) + { + for (int k = 0; k < 6 && buf[z]; z++, k++) + { + str[j] += buf[z]; + } + } + for (int c = 0; c < x; c++, cout << endl) + { + cout << str[c]; + } + int num[6] = {0, 0, 0, 0, 0, 0}; + for (int m = 0; m < x; m++) + { + for (int n = 0; n < str[m].length(); n++) + { + num[n] += str[m][n]; + } + } + change(num); + } + return 0; +} \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\257\206\347\240\201\350\204\261\350\220\275/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\257\206\347\240\201\350\204\261\350\220\275/desc.md" index e69de29bb..7bfa7b399 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\257\206\347\240\201\350\204\261\350\220\275/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\257\206\347\240\201\350\204\261\350\220\275/desc.md" @@ -0,0 +1,27 @@ +X星球的考古学家发现了一批古代留下来的密码。 +这些密码是由A、B、C、D 四种植物的种子串成的序列。 +仔细分析发现,这些密码串当初应该是前后对称的(也就是我们说的镜像串)。 +由于年代久远,其中许多种子脱落了,因而可能会失去镜像的特征。 + +你的任务是: +给定一个现在看到的密码串,计算一下从当初的状态,它要至少脱落多少个种子,才可能会变成现在的样子。 + +输入一行,表示现在看到的密码串(长度不大于1000) +要求输出一个正整数,表示至少脱落了多少个种子。 + +例如,输入: +``` +ABCBA +``` +则程序应该输出: +``` +0 +``` +再例如,输入: +``` +ABDCDCBABC +``` +则程序应该输出: +``` +3 +``` \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\257\206\347\240\201\350\204\261\350\220\275/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\257\206\347\240\201\350\204\261\350\220\275/solution.cpp" index e69de29bb..752f15565 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\257\206\347\240\201\350\204\261\350\220\275/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\257\206\347\240\201\350\204\261\350\220\275/solution.cpp" @@ -0,0 +1,37 @@ +#include +#include +#include +using namespace std; +int a[1001][1001]; + +int fun(string ss) +{ + int num = 0; + int len = ss.length(); + string s2 = ss; + memset(a, 0, sizeof(a)); + reverse(s2.begin(), s2.end()); + for (int i = 1; i <= len; i++) + { + for (int j = 0; j <= len; j++) + { + if (ss[i] == s2[j]) + { + a[i][j] = a[i - 1][j - 1] + 1; + } + else + { + a[i][j] = max(a[i - 1][j], a[i][j - 1]); + } + } + } + num = len - a[len][len]; + return num; +} +int main() +{ + string s; + cin >> s; + cout << fun(s); + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\257\222\345\201\207\344\275\234\344\270\232/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\257\222\345\201\207\344\275\234\344\270\232/desc.md" index e69de29bb..14af780fa 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\257\222\345\201\207\344\275\234\344\270\232/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\257\222\345\201\207\344\275\234\344\270\232/desc.md" @@ -0,0 +1,25 @@ +现在小学的数学题目也不是那么好玩的。 +看看这个寒假作业: +``` +□ + □ = □ +□ - □ = □ +□ × □ = □ +□ ÷ □ = □ +``` +每个方块代表1~13中的某一个数字,但不能重复。比如: +``` +6 + 7 = 13 +9 - 8 = 1 +3 * 4 = 12 +10 / 2 = 5 +``` +以及: +``` +7 + 6 = 13 +9 - 8 = 1 +3 * 4 = 12 +10 / 2 = 5 +``` +就算两种解法。(加法,乘法交换律后算不同的方案) + +你一共找到了多少种方案? diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\257\222\345\201\207\344\275\234\344\270\232/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\257\222\345\201\207\344\275\234\344\270\232/solution.cpp" index e69de29bb..06fd9a074 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\257\222\345\201\207\344\275\234\344\270\232/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\257\222\345\201\207\344\275\234\344\270\232/solution.cpp" @@ -0,0 +1,53 @@ +#include +using namespace std; + +int a[12] = {0}; +int vis[14] = {0}; +int count; +void dfs(int step) +{ + if (step == 3) + { + if (a[0] + a[1] != a[2]) + return; + } + + if (step == 6) + { + if (a[3] - a[4] != a[5]) + return; + } + + if (step == 9) + { + if (a[6] * a[7] != a[8]) + return; + } + + if (step == 13) + { + if (a[11] * a[10] == a[9]) + { + count++; + } + return; + } + for (int i = 1; i < 14; i++) + { + if (vis[i] == 0) + { + vis[i] = 1; + a[step] = i; + dfs(step + 1); + vis[i] = 0; + } + } +} +int main() +{ + + count = 0; + dfs(0); + cout << count; + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\257\273\346\211\2762020/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\257\273\346\211\2762020/desc.md" index e69de29bb..c13f89c69 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\257\273\346\211\2762020/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\257\273\346\211\2762020/desc.md" @@ -0,0 +1,21 @@ +小蓝有一个数字矩阵,里面只包含数字 0 和 2。小蓝很喜欢 2020,他想找到这个数字矩阵中有多少个 2020 。 + +小蓝只关注三种构成 2020 的方式: +* 同一行里面连续四个字符从左到右构成 2020。 +* 同一列里面连续四个字符从上到下构成 2020。 +* 在一条从左上到右下的斜线上连续四个字符,从左上到右下构成 2020。 + +例如,对于下面的矩阵: +``` +220000 +000000 +002202 +000000 +000022 +002020 +``` +一共有 5 个 2020。其中 1 个是在同一行里的,1 个是在同一列里的,3 个是斜线上的。 +小蓝的矩阵比上面的矩阵要大,由于太大了,他只好将这个矩阵放在了一个文件里面,在试题目录下有一个文件 2020.txt,里面给出了小蓝的矩阵。 +请帮助小蓝确定在他的矩阵中有多少个 2020。 + + diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\257\273\346\211\2762020/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\257\273\346\211\2762020/solution.cpp" index e69de29bb..fa6a6bb0e 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\257\273\346\211\2762020/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\257\273\346\211\2762020/solution.cpp" @@ -0,0 +1,69 @@ +#include +#include +char text[500][500]; +void copytext() +{ //将文本内容复制到数组text中 + char c[500]; + int line = 0; + FILE *fp = fopen("find2020.txt", "r"); + if (fp == NULL) + { + printf("failed to open file!\n"); + } + else + { + while (fgets(c, 500, fp)) + strcpy(text[line++], c); + } + fclose(fp); +} +int main() +{ + int i, j = 0, count = 0; + copytext(); //将文本内容复制到数组text中 + //求每行的2020 + for (i = 0; i < 500; i++) + for (j = 0; j < 500; j++) + if (text[i][j + 3] != NULL) + { + if (text[i][j] == '2' && text[i][j + 1] == '0' && text[i][j + 2] == '2' && text[i][j + 3] == '0') + { + count++; + j = j + 1; + } + } + else + { + break; + } + //求每列的2020 + for (j = 0; j < 500; j++) + for (i = 0; i < 500; i++) + if (text[i + 3][j] != NULL) + { + if (text[i][j] == '2' && text[i + 1][j] == '0' && text[i + 2][j] == '2' && text[i + 3][j] == '0') + { + count++; + i = i + 1; + } + } + else + { + break; + } + //求对角线的2020 + for (i = 0; i < 500; i++) + for (j = 0; j < 500; j++) + if (text[i + 3][j + 3] != NULL) + { + if (text[i][j] == '2' && text[i + 1][j + 1] == '0' && text[i + 2][j + 2] == '2' && text[i + 3][j + 3] == '0') + count++; + } + else + { + break; + } + printf("%d\n", count); + + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\260\217\346\234\213\345\217\213\345\264\207\346\213\234\345\234\210/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\260\217\346\234\213\345\217\213\345\264\207\346\213\234\345\234\210/desc.md" index e69de29bb..bb8949232 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\260\217\346\234\213\345\217\213\345\264\207\346\213\234\345\234\210/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\260\217\346\234\213\345\217\213\345\264\207\346\213\234\345\234\210/desc.md" @@ -0,0 +1,40 @@ +#### 问题描述: + +班里 N个小朋友,每个人都有自己最崇拜的一个小朋友(也可以是自己)。在一个游戏中,需要小朋友坐一个圈,每个小朋友都有自己最崇拜的小朋友在他的右手边。求满足条件的圈最大多少人?小朋友编号为1,2,3....N + +#### 输入描述 + +输入第一行,一个整数N(3 < N < 100000) + +接下来一行 N个整数,由空格分开。 + +#### 输出描述 + +要求输出一个整数,表示满足条件的最大圈的人数。 + +### 输入输出样例 +#### 输入 +``` +9 +3 4 2 5 3 8 4 6 9 +``` +#### 输出 +``` +4 +``` +#### 样例解释 + +如下图所示,崇拜关系用箭头表示,红色表示不在圈中。 +显然,最大圈是[2 4 5 3] 构成的圈。 + +![](https://img-blog.csdnimg.cn/20190317193536482.png) + +#### 输入: +``` +30 +22 28 16 6 27 21 30 1 29 10 9 14 24 11 7 2 8 5 26 4 12 3 25 18 20 19 23 17 13 15 +``` +#### 输出: +``` +16 +``` \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\260\217\346\234\213\345\217\213\345\264\207\346\213\234\345\234\210/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\260\217\346\234\213\345\217\213\345\264\207\346\213\234\345\234\210/solution.cpp" index e69de29bb..fa56050b2 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\260\217\346\234\213\345\217\213\345\264\207\346\213\234\345\234\210/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\260\217\346\234\213\345\217\213\345\264\207\346\213\234\345\234\210/solution.cpp" @@ -0,0 +1,34 @@ +#include +#include + +int main() +{ + int a[100100]; + int b[100010]; + int n = 9, i, j, k, max = 0; + + scanf("%d", &n); //输入 + for (i = 1; i <= n; i++) + scanf("%d", &a[i]); + + for (i = 1; i <= n; i++) //n: 总共多少个数 + { + for (k = i, j = 0; j < n; j++) + { + b[j] = a[k]; //数组 a 用来存储输入的 n 个数 + k = b[j]; + if (b[j] == i) + { + if (max < (j + 1)) + { + max = j + 1; + break; + } + break; + } + } + memset(b, 0, sizeof(b)); + } + printf("%d", max); + return 0; +} \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\260\217\346\234\213\345\217\213\346\216\222\351\230\237/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\260\217\346\234\213\345\217\213\346\216\222\351\230\237/desc.md" index e69de29bb..298aa067c 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\260\217\346\234\213\345\217\213\346\216\222\351\230\237/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\260\217\346\234\213\345\217\213\346\216\222\351\230\237/desc.md" @@ -0,0 +1,39 @@ +#### 题目描述 +n 个小朋友站成一排。 + +现在要把他们按身高从低到高的顺序排列,但是每次只能交换位置相邻的两个小朋友。 + +每个小朋友都有一个不高兴的程度。 + +开始的时候,所有小朋友的不高兴程度都是 0。 + +如果某个小朋友第一次被要求交换,则他的不高兴程度增加 1,如果第二次要求他交换,则他的不高兴程度增加 2(即不高兴程度为 3),依次类推。当要求某个小朋友第 k 次交换时,他的不高兴程度增加 k。 + +请问,要让所有小朋友按从低到高排队,他们的不高兴程度之和最小是多少。 + +如果有两个小朋友身高一样,则他们谁站在谁前面是没有关系的。 + +#### 输入格式 +输入的第一行包含一个整数 n,表示小朋友的个数。 + +第二行包含 n 个整数 H1,H2,…,Hn,分别表示每个小朋友的身高。 + +#### 输出格式 +输出一行,包含一个整数,表示小朋友的不高兴程度和的最小值。 + +#### 数据范围 +``` +1≤n≤100000, +0≤Hi≤1000000 +``` +#### 输入样例: +``` +3 +3 2 1 +``` +#### 输出样例: +``` +9 +``` +#### 样例解释 +首先交换身高为3和2的小朋友,再交换身高为3和1的小朋友,再交换身高为2和1的小朋友,每个小朋友的不高兴程度都是3,总和为9。 \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\260\217\346\234\213\345\217\213\346\216\222\351\230\237/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\260\217\346\234\213\345\217\213\346\216\222\351\230\237/solution.cpp" index e69de29bb..5589bb39e 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\260\217\346\234\213\345\217\213\346\216\222\351\230\237/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\260\217\346\234\213\345\217\213\346\216\222\351\230\237/solution.cpp" @@ -0,0 +1,45 @@ +#include +#include + +using namespace std; +typedef long long LL; +const int N = 1e6 + 10; +int h[N], s[N], tr[N]; //h高,s多少个大于h[i]和小于h[i]的人,tr树状数组 +int n; + +int lowbit(int x) { return x & -x; } +int add(int x) +{ + for (int i = x; i < N; i += lowbit(i)) + tr[i]++; +} //这里不是添加值,支持计算次数,所以自增1 +int q(int x) +{ + int res = 0; + for (int i = x; i; i -= lowbit(i)) + res += tr[i]; + return res; +} +int main() +{ + cin >> n; + for (int i = 0; i < n; i++) + { + cin >> h[i], h[i]++; //树状数组必须从1开始 + + s[i] = q(N - 1) - q(h[i]); //比i大的数 + add(h[i]); + } + + memset(tr, 0, sizeof tr); //tr清零重复使用 + + for (int i = n - 1; i >= 0; i--) + s[i] += q(h[i] - 1), add(h[i]); //逆序比较//比h[i]小的数 + + LL res = 0; + for (int i = 0; i < n; i++) + res += (LL)s[i] * (s[i] + 1) / 2; //公式计算 累加 因为过大所以用LL + cout << res; + + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\270\246\345\210\206\346\225\260/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\270\246\345\210\206\346\225\260/desc.md" index e69de29bb..52ca55a13 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\270\246\345\210\206\346\225\260/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\270\246\345\210\206\346\225\260/desc.md" @@ -0,0 +1,33 @@ +#### 问题描述 +100 可以表示为带分数的形式:100 = 3 + 69258 / 714。 + +还可以表示为:100 = 82 + 3546 / 197。 + +注意特征:带分数中,数字1~9分别出现且只出现一次(不包含0)。 + +类似这样的带分数,100 有 11 种表示法。 + +#### 输入格式 +从标准输入读入一个正整数N (N<1000*1000) + +#### 输出格式 +程序输出该数字用数码1~9不重复不遗漏地组成带分数表示的全部种数。 + +注意:不要求输出每个表示,只统计有多少表示法! + +#### 样例输入1 +``` +100 +``` +#### 样例输出1 +``` +11 +``` +#### 样例输入2 +``` +105 +``` +#### 样例输出2 +``` +6 +``` \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\270\246\345\210\206\346\225\260/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\270\246\345\210\206\346\225\260/solution.cpp" index e69de29bb..2a1e7dd0c 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\270\246\345\210\206\346\225\260/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\270\246\345\210\206\346\225\260/solution.cpp" @@ -0,0 +1,83 @@ +/* + Name: 蓝桥杯:带分数(全排列) + Copyright: 本算法由KeepThinking_提供 + Author: Jopus + Date: 08/02/14 19:57 + Description: dev-cpp 5.5.3 +*/ +#include +/*思路:将list[1,2,3,4,5,6,7,8,9]数组进行全排列,然后对于每一种排列进行处理 +处理方法:将list数组划分为三部分a,b,c,判断是否满足number == a+b/c && b%c == 0; +具体见分析......... +*/ +int x = 0, number = 0, count = 0; + +//交换a,b两数 +void Swap(int &a, int &b) +{ + int temp = a; + a = b; + b = temp; +} +//将数组区间转化为数字 +int getNum(int list[], int f, int r) +{ + int i = 0, num = 0; + for (i = f; i <= r; i++) + num = list[i] + num * 10; //进位 + return num; +} +//进行全排列并对每种排列结果进行处理 +void Prim(int list[], int k, int m) +{ + if (k == m - 1) //前缀是最后一个位置,此时出现一种排列数. + { + int a = 0, b = 0, c = 0, bLast = 0; //带分数:a+b/c + for (int i = 0; i < x; i++) //i表示a的末尾位置,不会超过number位数 + { + a = getNum(list, 0, i); //将list数组中的[0-i]转化为数字,赋值给a + bLast = ((number - a) * list[8]) % 10; //确定b最后一个数字 + for (int j = i + (8 - i) / 2; j < 8; j++) //从list数组中间位置开始找b末尾位置 + { + if (list[j] == bLast) //找到b尾部 + { + b = getNum(list, i + 1, j); //将list数组中的[i+1-j]转化为数字,赋值给b + c = getNum(list, j + 1, 8); //将list数组中的[j+1-8]转化为数字,赋值给c + if (b % c == 0 && a + b / c == number) //判断合理性 + { + // printf("%d+%d/%d\n",a,b,c); //打印每种情况 + ++count; + } + break; + } + } + } + } + else + { + for (int i = k; i < m; i++) //全排列数组list[] + { + //交换前缀,使之产生下一个前缀. + Swap(list[k], list[i]); //>>A + Prim(list, k + 1, m); //>>B + //将前缀换回来,继续做上一个的前缀排列.//>>C + Swap(list[k], list[i]); + } + } +} +//主函数 +int main() +{ + int temp = 0; + int list[] = {1, 2, 3, 4, 5, 6, 7, 8, 9}; //定义全排列数组 + scanf("%d", &number); + temp = number; + while (temp != 0) //统计number总共多少位 + { + ++x; + temp /= 10; + } + Prim(list, 0, 9); + printf("%d", count); //打印总共多少种 + return 0; +} \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\271\263\346\226\271\345\222\214/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\271\263\346\226\271\345\222\214/desc.md" index e69de29bb..f6fc2ec40 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\271\263\346\226\271\345\222\214/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\271\263\346\226\271\345\222\214/desc.md" @@ -0,0 +1,2 @@ +小明对数位中含有 2、0、1、9 的数字很感兴趣,在 1 到 40 中这样的数包括 1、2、9、10 至 32、39 和 40,共 28 个,他们的和是 574,平方和是 14362。注意,平方和是指将每个数分别平方后求和。 +请问,在 1 到 2019 中,所有这样的数的平方和是多少? diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\271\263\346\226\271\345\222\214/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\271\263\346\226\271\345\222\214/solution.cpp" index e69de29bb..cf9b77c28 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\271\263\346\226\271\345\222\214/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\271\263\346\226\271\345\222\214/solution.cpp" @@ -0,0 +1,22 @@ +#include +using namespace std; +bool f(int n) +{ + while (n) + { + int t = n % 10; + if (t == 0 || t == 2 || t == 1 || t == 9) + return true; + n /= 10; + } + return false; +} +int main() +{ + long long sum = 0; + for (int i = 1; i <= 2019; ++i) + if (f(i)) + sum += i * i; + cout << sum << endl; + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\271\263\351\235\242\345\210\206\345\211\262/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\271\263\351\235\242\345\210\206\345\211\262/desc.md" index e69de29bb..9c6943112 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\271\263\351\235\242\345\210\206\345\211\262/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\271\263\351\235\242\345\210\206\345\211\262/desc.md" @@ -0,0 +1 @@ +20个圆和20条直线最多能把平面分成多少个部分? \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\271\263\351\235\242\345\210\206\345\211\262/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\271\263\351\235\242\345\210\206\345\211\262/solution.cpp" index e69de29bb..a2c76a5ce 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\271\263\351\235\242\345\210\206\345\211\262/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\271\263\351\235\242\345\210\206\345\211\262/solution.cpp" @@ -0,0 +1,14 @@ +#include + +using namespace std; +typedef long long int ll; + +int main() +{ + ios::sync_with_stdio(false); + int m = 20, n = 20; + int value = m * m + 0.5 * n * n + 2 * m * n - m + 0.5 * n + 1; + cout << value << endl; + system("pause"); + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\271\263\351\235\242\345\210\207\345\210\206/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\271\263\351\235\242\345\210\207\345\210\206/desc.md" index e69de29bb..795634640 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\271\263\351\235\242\345\210\207\345\210\206/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\271\263\351\235\242\345\210\207\345\210\206/desc.md" @@ -0,0 +1,24 @@ +#### 问题描述 +平面上有 N条直线,其中第 i条直线是$ y = A_i*x + B_i$。 + +请计算这些直线将平面分成了几个部分。 + +#### 输入格式 +第一行包含一个整数N。 + +以下N行,每行包含两个整数 $A_i, B_i$。 + +#### 输出格式 +一个整数代表答案。 + +#### 样例输入 +``` +3 +1 1 +2 2 +3 3 +``` +#### 样例输出 +``` +6 +``` \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\271\263\351\235\242\345\210\207\345\210\206/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\271\263\351\235\242\345\210\207\345\210\206/solution.cpp" index e69de29bb..b682f789e 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\271\263\351\235\242\345\210\207\345\210\206/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\271\263\351\235\242\345\210\207\345\210\206/solution.cpp" @@ -0,0 +1,40 @@ +#include +using namespace std; + +long double s[1010][2]; //存储直线的A,B +long long ans; +bool st[1010]; //false表示不是重边 +pair p; + +int main() +{ + int n; + cin >> n; + for (int i = 0; i < n; i++) + { + cin >> s[i][0] >> s[i][1]; + set> points; + for (int j = 0; j < i; j++) + { + if (st[j]) + continue; //直线是重边,跳过 + if (s[i][0] == s[j][0]) + { //两条直线斜率相等时,判断是平行还是重合 + if (s[i][1] == s[j][1]) + { + st[i] = true; //待添加直线是重边,退出循环 + break; + } + else + continue; //直线平行,不需要计算交点 + } + p.first = (s[j][1] - s[i][1]) / (s[i][0] - s[j][0]); //交点的x坐标 + p.second = s[i][0] * p.first + s[i][1]; //交点的y坐标 + points.insert(p); + } + if (!st[i]) + ans += points.size() + 1; //若当前直线不是重边,更新答案 + } + cout << ans + 1; + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\271\264\345\217\267\345\255\227\347\254\246/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\271\264\345\217\267\345\255\227\347\254\246/desc.md" index e69de29bb..151302ed6 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\271\264\345\217\267\345\255\227\347\254\246/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\271\264\345\217\267\345\255\227\347\254\246/desc.md" @@ -0,0 +1,2 @@ +小明用字母 A 对应数字 1,B 对应 2,以此类推,用 Z 对应 26。对于 27 以上的数字,小明用两位或长位的字符串来对应,例如 AA 对应 27,AB 对 应 28,AZ 对应 52,LQ 对应 329。 +请问 2019 对应的字符串是什么? diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\271\264\345\217\267\345\255\227\347\254\246/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\271\264\345\217\267\345\255\227\347\254\246/solution.cpp" index e69de29bb..a734d69c7 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\271\264\345\217\267\345\255\227\347\254\246/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\271\264\345\217\267\345\255\227\347\254\246/solution.cpp" @@ -0,0 +1,18 @@ +#include +using namespace std; + +void solve(int n) +{ + if (!n) + { + return; + } + solve(n / 26); + cout << (char)(n % 26 + 64); +} + +int main() +{ + solve(2019); + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\271\270\350\277\220\346\225\260/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\271\270\350\277\220\346\225\260/desc.md" index e69de29bb..b15d12fff 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\271\270\350\277\220\346\225\260/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\271\270\350\277\220\346\225\260/desc.md" @@ -0,0 +1,35 @@ +#### 问题描述 +幸运数是波兰数学家乌拉姆命名的。它采用与生成素数类似的“筛法”生成。 +首先从1开始写出自然数1,2,3,4,5,6,… +1 就是第一个幸运数。 +我们从2这个数开始。把所有序号能被2整除的项删除,变为: +1 _ 3 _ 5 _ 7 _ 9 … +把它们缩紧,重新记序,为: +1 3 5 7 9 … 。 +这时,3为第2个幸运数,然后把所有能被3整除的序号位置的数删去。注意,是序号位置,不是那个数本身能否被3整除!! 删除的应该是5,11, 17, … +此时7为第3个幸运数,然后再删去序号位置能被7整除的(19,39,…) +最后剩下的序列类似: +``` +1, 3, 7, 9, 13, 15, 21, 25, 31, 33, 37, 43, 49, 51, 63, 67, 69, 73, 75, 79, … +``` +#### 输入格式 +输入两个正整数m n, 用空格分开 (m < n < 1000*1000) + +#### 输出格式 +程序输出 位于m和n之间的幸运数的个数(不包含m和n)。 +#### 样例输入1 +``` +1 20 +``` +#### 样例输出1 +``` +5 +``` +#### 样例输入2 +``` +30 69 +``` +#### 样例输出2 +``` +8 +``` \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\271\270\350\277\220\346\225\260/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\271\270\350\277\220\346\225\260/solution.cpp" index e69de29bb..776997f14 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\271\270\350\277\220\346\225\260/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\271\270\350\277\220\346\225\260/solution.cpp" @@ -0,0 +1,40 @@ +#include +using namespace std; + +int a[500005]; + +int main() +{ + int i, k = 1; //k表示a数组大小 + int m, n, sum = 0; //sum表示幸运数个数 + int temp; + cin >> m >> n; + for (i = 1; i <= 1000000; i += 2) + { + a[k++] = i; + } + temp = 2; //当前幸运数所处的序号位置 + while (temp <= 1000) + { + int b[500005], t = 1; //b记录幸运数 + for (i = 1; i < k; i++) + { + if (i % a[temp] != 0) //如果序号位置i不能被某一个幸运数整除,则将其存储到b数组 + b[t++] = a[i]; + } + for (i = 1; i < t; i++) + a[i] = b[i]; + temp++; + k = t; + } + for (i = 1; i <= n; i++) + { + if (a[i] > m && a[i] < n) //注意幸运数的区间(不包含m和n) + { + sum++; + } + } + cout << sum << endl; + + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\276\252\347\216\257\350\212\202\351\225\277\345\272\246/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\276\252\347\216\257\350\212\202\351\225\277\345\272\246/desc.md" index e69de29bb..4ec4b2bfb 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\276\252\347\216\257\350\212\202\351\225\277\345\272\246/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\276\252\347\216\257\350\212\202\351\225\277\345\272\246/desc.md" @@ -0,0 +1,3 @@ +两个整数做除法,有时会产生循环小数,其循环部分称为:循环节。 +比如,11/13=6=>0.846153846153….. 其循环节为[846153] 共有6位。 +下面的方法,可以求出循环节的长度。 \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\276\252\347\216\257\350\212\202\351\225\277\345\272\246/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\276\252\347\216\257\350\212\202\351\225\277\345\272\246/solution.cpp" index e69de29bb..4103a5f01 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\276\252\347\216\257\350\212\202\351\225\277\345\272\246/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\276\252\347\216\257\350\212\202\351\225\277\345\272\246/solution.cpp" @@ -0,0 +1,28 @@ +#include +#include +#include +using namespace std; +int f(int n, int m) +{ + n = n % m; + vector v; + for (;;) + { + v.push_back(n); + n *= 10; + n = n % m; + if (n == 0) + return 0; + if (find(v.begin(), v.end(), n) != v.end()) + { + return (int)(v.end() - find(v.begin(), v.end(), n)); + } + } +} +int main() +{ + int n, m; + cin >> n >> m; + cout << f(n, m) << endl; + return 0; +} \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\276\256\347\224\237\347\211\251\345\242\236\346\256\226/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\276\256\347\224\237\347\211\251\345\242\236\346\256\226/desc.md" index e69de29bb..5d941fd4b 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\276\256\347\224\237\347\211\251\345\242\236\346\256\226/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\276\256\347\224\237\347\211\251\345\242\236\346\256\226/desc.md" @@ -0,0 +1,6 @@ +假设有两种微生物 X 和 Y +X出生后每隔3分钟分裂一次(数目加倍),Y出生后每隔2分钟分裂一次(数目加倍)。 +一个新出生的X,半分钟之后吃掉1个Y,并且,从此开始,每隔1分钟吃1个Y。 +现在已知有新出生的 X=10, Y=89,求60分钟后Y的数目。 +如果X=10,Y=90呢? +本题的要求就是写出这两种初始条件下,60分钟后Y的数目。 diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\276\256\347\224\237\347\211\251\345\242\236\346\256\226/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\276\256\347\224\237\347\211\251\345\242\236\346\256\226/solution.cpp" index e69de29bb..467e2efde 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\276\256\347\224\237\347\211\251\345\242\236\346\256\226/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\276\256\347\224\237\347\211\251\345\242\236\346\256\226/solution.cpp" @@ -0,0 +1,16 @@ +#include +using namespace std; +int main() +{ + int x = 10, y = 90; + for (int i = 1; i <= 120; i++) + { + if (i % 2 == 1) + y -= x; + if (i % 4 == 0) + y *= 2; + if (i % 6 == 0) + x *= 2; + } + cout << y << endl; +} \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\277\253\351\200\237\346\216\222\345\272\217/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\277\253\351\200\237\346\216\222\345\272\217/desc.md" index e69de29bb..f6f65c1d8 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\277\253\351\200\237\346\216\222\345\272\217/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\277\253\351\200\237\346\216\222\345\272\217/desc.md" @@ -0,0 +1,15 @@ +#### 问题描述 +用递归来实现快速排序(quick sort)算法。快速排序算法的基本思路是:假设要对一个数组a进行排序,且a[0] = x。首先对数组中的元素进行调整,使x放在正确的位置上。同时,所有比x小的数都位于它的左边,所有比x大的数都位于它的右边。然后对于左、右两段区域,递归地调用快速排序算法来进行排序。 +#### 输入格式: +输入只有一行,包括若干个整数(不超过10个),以0结尾。 +#### 输出格式: +输出只有一行,即排序以后的结果(不包括末尾的0)。 +### 输入输出样例 +#### 样例输入 +``` +5 2 6 1 7 3 4 0 +``` +#### 样例输出 +``` +1 2 3 4 5 6 7 +``` \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\277\253\351\200\237\346\216\222\345\272\217/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\277\253\351\200\237\346\216\222\345\272\217/solution.cpp" index e69de29bb..62bd14df9 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\277\253\351\200\237\346\216\222\345\272\217/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\277\253\351\200\237\346\216\222\345\272\217/solution.cpp" @@ -0,0 +1,58 @@ +#include + +using namespace std; + +int a[10]; + +void quick_sort(int s[], int l, int r) +{ + if (l < r) + { + int i = l; + int j = r; + int x = s[l]; + while (i < j) + { + while (i < j && a[j] >= x) + { + j--; + } + if (i < j) + { + s[i++] = s[j]; + } + while (i < j && a[i] < x) + { + i++; + } + if (i < j) + { + s[j--] = s[i]; + } + } + s[i] = x; + quick_sort(s, l, i - 1); + quick_sort(s, i + 1, r); + } +} + +int main() +{ + int index = 0; + int num; + while (1) + { + cin >> num; + if (num == 0) + { + break; + } + a[index++] = num; + } + quick_sort(a, 0, index - 1); + for (int i = 0; i < index; i++) + { + cout << a[i] << " "; + } + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\211\213\351\223\276\346\240\267\345\274\217/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\211\213\351\223\276\346\240\267\345\274\217/desc.md" index e69de29bb..4bfad6cee 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\211\213\351\223\276\346\240\267\345\274\217/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\211\213\351\223\276\346\240\267\345\274\217/desc.md" @@ -0,0 +1,3 @@ +小明有3颗红珊瑚,4颗白珊瑚,5颗黄玛瑙。 +他想用它们串成一圈作为手链,送给女朋友。 +现在小明想知道:如果考虑手链可以随意转动或翻转,一共可以有多少不同的组合样式呢? \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\211\213\351\223\276\346\240\267\345\274\217/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\211\213\351\223\276\346\240\267\345\274\217/solution.cpp" index e69de29bb..d20669020 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\211\213\351\223\276\346\240\267\345\274\217/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\211\213\351\223\276\346\240\267\345\274\217/solution.cpp" @@ -0,0 +1,30 @@ +#include +#include +#include +#include +using namespace std; +vector v; +int main() +{ + int count = 0; + string a = "xxxyyyyzzzzz"; + do + { + int i; + for (i = 0; i < v.size(); i++) + { + if (v[i].find(a) != string::npos) + { + break; + } + } + if (i != v.size()) + continue; + string b = a + a; + v.push_back(b); + reverse(b.begin(), b.end()); + v.push_back(b); + count++; + } while (next_permutation(a.begin(), a.end())); + cout << count; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\211\221\345\205\213\345\272\217\345\210\227/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\211\221\345\205\213\345\272\217\345\210\227/desc.md" index e69de29bb..b5f46709f 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\211\221\345\205\213\345\272\217\345\210\227/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\211\221\345\205\213\345\272\217\345\210\227/desc.md" @@ -0,0 +1,7 @@ +A A 2 2 3 3 4 4, 一共4对扑克牌。请你把它们排成一行。 +要求:两个A中间有1张牌,两个2之间有2张牌,两个3之间有3张牌,两个4之间有4张牌。 + +请填写出所有符合要求的排列中,字典序最小的那个。 + +例如:22AA3344 比 A2A23344 字典序小。当然,它们都不是满足要求的答案。 + diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\211\221\345\205\213\345\272\217\345\210\227/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\211\221\345\205\213\345\272\217\345\210\227/solution.cpp" index e69de29bb..948bdca9c 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\211\221\345\205\213\345\272\217\345\210\227/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\211\221\345\205\213\345\272\217\345\210\227/solution.cpp" @@ -0,0 +1,44 @@ +#include +using namespace std; +int n = 0; +void swap(char *a, char *b) +{ + int m; + m = *a; + *a = *b; + *b = m; +} +void pailie(string str, int k, int m) +{ + int i; + if (k > m) + { + int a = str.find('A'); + int b = str.find_last_of('A'); + int c = str.find('2'); + int d = str.find_last_of('2'); + int e = str.find('3'); + int f = str.find_last_of('3'); + int g = str.find('4'); + int l = str.find_last_of('4'); + if (b - a == 2 && d - c == 3 && f - e == 4 && l - g == 5) + { + cout << str << endl; + } + } + else + { + for (i = k; i <= m; i++) + { + swap(&str[k], &str[i]); + pailie(str, k + 1, m); + swap(&str[k], &str[i]); + } + } +} +int main() +{ + string str = "AA223344"; + pailie(str, 0, 7); + return 0; +} \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\214\257\345\205\264\344\270\255\345\215\216/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\214\257\345\205\264\344\270\255\345\215\216/desc.md" index e69de29bb..4eab57685 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\214\257\345\205\264\344\270\255\345\215\216/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\214\257\345\205\264\344\270\255\345\215\216/desc.md" @@ -0,0 +1,15 @@ +小明参加了学校的趣味运动会,其中的一个项目是:跳格子。 + +地上画着一些格子,每个格子里写一个字,如下所示: +``` +从我做起振 +我做起振兴 +做起振兴中 +起振兴中华 +``` +![](https://img-blog.csdn.net/20180327194316347) +比赛时,先站在左上角的写着“从”字的格子里,可以横向或纵向跳到相邻的格子里,但不能跳到对角的格子或其它位置。一直要跳到“华”字结束。 + +要求跳过的路线刚好构成“从我做起振兴中华”这句话。 + +请你帮助小明算一算他一共有多少种可能的跳跃路线呢? \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\214\257\345\205\264\344\270\255\345\215\216/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\214\257\345\205\264\344\270\255\345\215\216/solution.cpp" index e69de29bb..4fe64321c 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\214\257\345\205\264\344\270\255\345\215\216/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\214\257\345\205\264\344\270\255\345\215\216/solution.cpp" @@ -0,0 +1,28 @@ +#include +using namespace std; + +int a[4][5]; +int sum; +void dfs(int row, int col, int index) +{ + if (a[row][col] == index && index == 7) + sum++; + else + { + if (row + 1 < 4) + dfs(row + 1, col, index + 1); + if (col + 1 < 5) + dfs(row, col + 1, index + 1); + } +} +int main() +{ + int row, col; + for (row = 0; row < 4; row++) + for (col = 0; col < 5; col++) + a[row][col] = row + col; + + dfs(0, 0, 0); + cout << sum << endl; + return 0; +} \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\216\222\345\256\203\345\271\263\346\226\271\346\225\260/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\216\222\345\256\203\345\271\263\346\226\271\346\225\260/desc.md" index e69de29bb..0095416e1 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\216\222\345\256\203\345\271\263\346\226\271\346\225\260/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\216\222\345\256\203\345\271\263\346\226\271\346\225\260/desc.md" @@ -0,0 +1,7 @@ +203879 * 203879 = 41566646641 +这有什么神奇呢?仔细观察,203879 是个6位数,并且它的每个数位上的数字都是不同的,并且它平方后的所有数位上都不出现组成它自身的数字。 +具有这样特点的6位数还有一个,请你找出它! +再归纳一下筛选要求: +1. 6位正整数 +2. 每个数位上的数字不同 +3. 其平方数的每个数位不含原数字的任何组成数位 diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\216\222\345\256\203\345\271\263\346\226\271\346\225\260/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\216\222\345\256\203\345\271\263\346\226\271\346\225\260/solution.cpp" index e69de29bb..9f21136dd 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\216\222\345\256\203\345\271\263\346\226\271\346\225\260/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\216\222\345\256\203\345\271\263\346\226\271\346\225\260/solution.cpp" @@ -0,0 +1,41 @@ +#include +using namespace std; +int main() +{ + + for (long long i = 100000; i < 1000000; i++) + { + //i要用longlong,不然相乘会溢出 + set s1, s2; + int t1 = i; + while (t1) + { + s1.insert(t1 % 10); + t1 /= 10; + } + long long t2 = i * i; + if (s1.size() == 6) + { + while (t2) + { + s2.insert(t2 % 10); + t2 /= 10; + } + bool flag = 1; + for (auto it : s1) + { + if (s2.find(it) != s2.end()) + { + flag = 0; + break; + } + } + if (flag == 1) + cout << i << ' ' << i * i << endl; + } + s1.clear(); + s2.clear(); + } + + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\216\222\345\272\217/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\216\222\345\272\217/desc.md" index e69de29bb..41c0a474e 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\216\222\345\272\217/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\216\222\345\272\217/desc.md" @@ -0,0 +1,13 @@ +#### 问题描述 +编写一个程序,输入3个整数,然后程序将对这三个整数按照从大到小进行排列。 +输入格式:输入只有一行,即三个整数,中间用空格隔开。 +输出格式:输出只有一行,即排序后的结果。 +### 输入输出样例 +#### 样例输入 +``` +9 2 30 +``` +#### 样例输出 +``` +30 9 2 +``` \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\216\222\345\272\217/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\216\222\345\272\217/solution.cpp" index e69de29bb..34475a8f6 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\216\222\345\272\217/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\216\222\345\272\217/solution.cpp" @@ -0,0 +1,28 @@ +#include + +using namespace std; + +int main() +{ + int a[3]; + int i, j; + for (i = 0; i < 3; i++) + cin >> a[i]; + for (i = 0; i < 2; i++) + { + for (j = 0; j < 2 - i; j++) + { + if (a[j] < a[j + 1]) + { + int temp = a[j]; + a[j] = a[j + 1]; + a[j + 1] = temp; + } + } + } + for (i = 0; i < 3; i++) + { + cout << a[i] << " "; + } + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\224\276\346\243\213\345\255\220/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\224\276\346\243\213\345\255\220/desc.md" index e69de29bb..8084053c9 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\224\276\346\243\213\345\255\220/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\224\276\346\243\213\345\255\220/desc.md" @@ -0,0 +1,2 @@ +今有6×6的棋盘,其中某些格子已预放了棋子。现在要再放上去一些,使得每行每列都正好有3颗棋子。我们希望推算出所有可能的放法,下面的代码就实现了这个功能。初始数组中,“1”表示放有棋子,“0”表示空白。 +![](https://img-blog.csdn.net/20170302185510449) \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\224\276\346\243\213\345\255\220/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\224\276\346\243\213\345\255\220/solution.cpp" index e69de29bb..50bd27a5d 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\224\276\346\243\213\345\255\220/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\224\276\346\243\213\345\255\220/solution.cpp" @@ -0,0 +1,115 @@ +#include +#include +int N = 0; +bool CheckStoneNum(int x[][6]) +{ + for (int k = 0; k < 6; ++k) + { + int NumRow = 0, NumCol = 0; + for (int i = 0; i < 6; ++i) + { + if (x[k][i]) + NumRow++; + if (x[i][k]) + NumCol++; + } + if (NumRow != 3 || NumCol != 3) + return false; + } + return true; +} +int GetRowStoneNum(int x[][6], int r) +{ + int sum = 0; + for (int i = 0; i < 6; ++i) + { + if (x[r][i]) + sum++; + } + return sum; +} +int GetColStoneNum(int x[][6], int c) +{ + int sum = 0; + for (int i = 0; i < 6; ++i) + { + if (x[i][c]) + sum++; + } + return sum; +} +void show(int x[][6]) +{ + for (int i = 0; i < 6; ++i) + { + for (int j = 0; j < 6; ++j) + { + printf("%2d", x[i][j]); + } + printf("\n"); + } + printf("\n"); +} +void f(int x[][6], int r, int c); +void GoNext(int x[][6], int r, int c) +{ + if (c < 6) + { + f(x, r, c + 1); + } + else + { + f(x, r + 1, 0); + } +} +void f(int x[][6], int r, int c) +{ + if (r == 6) + { + if (CheckStoneNum(x)) + { + N++; + show(x); + } + return; + } + if (x[r][c]) + { + GoNext(x, r, c); + return; + } + int rr = GetRowStoneNum(x, r); + int cc = GetColStoneNum(x, c); + if (cc >= 3) + { + GoNext(x, r, c); + } + else if (rr >= 3) + { + f(x, r + 1, 0); + } + else + { + x[r][c] = 1; + GoNext(x, r, c); + x[r][c] = 0; + if (!(3 - rr >= 6 - c || 3 - cc >= 6 - r)) + { + GoNext(x, r, c); + } + } +} +int main() +{ + int x[6][6] = { + {1, 0, 0, 0, 0, 0}, + {0, 0, 1, 0, 1, 0}, + {0, 0, 1, 1, 0, 1}, + {0, 1, 0, 0, 1, 0}, + {0, 0, 0, 1, 0, 0}, + {1, 0, 1, 0, 0, 1}, + }; + f(x, 0, 0); + printf("%d\n", N); + return 0; +} \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\225\260\345\210\227\346\261\202\345\200\274/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\225\260\345\210\227\346\261\202\345\200\274/desc.md" index e69de29bb..035a9fcb5 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\225\260\345\210\227\346\261\202\345\200\274/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\225\260\345\210\227\346\261\202\345\200\274/desc.md" @@ -0,0 +1 @@ +给定数列1, 1, 1, 3, 5, 9, 17, …,从第4 项开始,每项都是前3 项的和。求第20190324 项的最后4 位数字。 \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\225\260\345\210\227\346\261\202\345\200\274/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\225\260\345\210\227\346\261\202\345\200\274/solution.cpp" index e69de29bb..11023eb82 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\225\260\345\210\227\346\261\202\345\200\274/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\225\260\345\210\227\346\261\202\345\200\274/solution.cpp" @@ -0,0 +1,14 @@ +#include +int main(void) +{ + int a[20190324]; + a[0] = 1; + a[1] = 1; + a[2] = 1; + for (int i = 3; i < 20190324; i++) + { + a[i] = (a[i - 1] + a[i - 2] + a[i - 3]) % 10000; + } + printf("%d", a[20190323]); + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\225\260\345\255\227\344\270\211\350\247\222\345\275\242/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\225\260\345\255\227\344\270\211\350\247\222\345\275\242/desc.md" index e69de29bb..3304d9327 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\225\260\345\255\227\344\270\211\350\247\222\345\275\242/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\225\260\345\255\227\344\270\211\350\247\222\345\275\242/desc.md" @@ -0,0 +1,39 @@ +#### 题目描述 + +![](https://img-blog.csdnimg.cn/20210330204547371.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NjIzOTM3MA==,size_16,color_FFFFFF,t_70) + +上图给出了一个数字三角形。 + +从三角形的顶部到底部有很多条不同的路径。 + +对于每条路径,把路径上面的数加起来可以得到一个和,你的任务就是找到最大的和。 + +路径上的每一步只能从一个数走到下一层和它最近的左边的那个数或者右边的那个数。 + +此外,向左下走的次数与向右下走的次数相差不能超过 1。 + +#### 输入格式 +输入的第一行包含一个整数 N,表示三角形的行数。 +下面的 N 行给出数字三角形。 +数字三角形上的数都是 0 至 100 之间的整数。 + +#### 输出格式 +输出一个整数,表示答案。 + +#### 输入样例 +``` +5 +7 +3 8 +8 1 0 +2 7 4 4 +4 5 2 6 5 +``` +#### #### 输出样例 +``` +27 +``` +数据范围 +``` +1 ≤ N ≤ 100 +``` \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\225\260\345\255\227\344\270\211\350\247\222\345\275\242/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\225\260\345\255\227\344\270\211\350\247\222\345\275\242/solution.cpp" index e69de29bb..ed71f91e3 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\225\260\345\255\227\344\270\211\350\247\222\345\275\242/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\225\260\345\255\227\344\270\211\350\247\222\345\275\242/solution.cpp" @@ -0,0 +1,25 @@ +#include +using namespace std; + +const int N = 110; + +int n; +int f[N][N]; + +int main() +{ + cin >> n; + for (int i = 1; i <= n; i++) + for (int j = 1; j <= i; j++) + cin >> f[i][j]; + + for (int i = 2; i <= n; i++) + for (int j = 1; j <= i; j++) + f[i][j] += max(f[i - 1][j - 1], f[i - 1][j]); + + if (n % 2) + cout << f[n][n / 2 + 1] << endl; + else + cout << max(f[n][n / 2 + 1], f[n][n / 2]) << endl; + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\225\260\347\232\204\345\210\206\350\247\243/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\225\260\347\232\204\345\210\206\350\247\243/desc.md" index e69de29bb..6699fad9b 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\225\260\347\232\204\345\210\206\350\247\243/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\225\260\347\232\204\345\210\206\350\247\243/desc.md" @@ -0,0 +1,3 @@ +把 2019 分解成 3 个各不相同的正整数之和,并且要求每个正整数都不包含数字 2 和 4,一共有多少种不同的分解方法? + +注意交换 3 个整数的顺序被视为同一种方法,例如 1000+1001+18 和 1001+1000+18 被视为同一种。 \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\225\260\347\232\204\345\210\206\350\247\243/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\225\260\347\232\204\345\210\206\350\247\243/solution.cpp" index e69de29bb..1901e6da8 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\225\260\347\232\204\345\210\206\350\247\243/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\225\260\347\232\204\345\210\206\350\247\243/solution.cpp" @@ -0,0 +1,33 @@ +#include +#include +#include +using namespace std; + +bool check(int x) +{ + while (x) + { + if (x % 10 == 2 || x % 10 == 4) + return false; + x /= 10; + } + return true; +} + +int main() +{ + int ans = 0; + for (int i = 1; i < 2019; i++) + { + if (!check(i)) + continue; + for (int j = i + 1; j < 2019; j++) + { + int k = 2019 - i - j; + if (k > j && check(j) && check(k)) ///此处记得j,k都要check + ans++; + } + } + printf("%d\n", ans); + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\225\264\346\225\260\345\260\217\346\213\274\346\216\245/config.json" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\225\264\346\225\260\345\260\217\346\213\274\346\216\245/config.json" deleted file mode 100644 index f6416a1a5..000000000 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\225\264\346\225\260\345\260\217\346\213\274\346\216\245/config.json" +++ /dev/null @@ -1,6 +0,0 @@ -{ - "node_id": "569d5e11c4fc5de7844053d9a733c5e8", - "keywords": [], - "children": [], - "export": [] -} \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\225\264\346\225\260\345\260\217\346\213\274\346\216\245/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\225\264\346\225\260\345\260\217\346\213\274\346\216\245/desc.md" deleted file mode 100644 index e69de29bb..000000000 diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\225\264\346\225\260\345\260\217\346\213\274\346\216\245/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\225\264\346\225\260\345\260\217\346\213\274\346\216\245/solution.cpp" deleted file mode 100644 index e69de29bb..000000000 diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\225\264\346\225\260\345\260\217\346\213\274\346\216\245/solution.java" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\225\264\346\225\260\345\260\217\346\213\274\346\216\245/solution.java" deleted file mode 100644 index e69de29bb..000000000 diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\225\264\346\225\260\346\213\274\346\216\245/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\225\264\346\225\260\346\213\274\346\216\245/desc.md" index e69de29bb..8e07fd564 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\225\264\346\225\260\346\213\274\346\216\245/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\225\264\346\225\260\346\213\274\346\216\245/desc.md" @@ -0,0 +1,32 @@ +#### 问题描述 +给定义个长度为 n 的数组 $A_1, A_2 , ··· , A_n$。 + +你可以从中选出两个数 $A_i 和 A_j$ (i 不等于 j),然后将 $A_i 和 A_j$ 一前一后拼成一个新的整数。 + +例如 12 和 345 可以拼成 12345 或 34512。 + +注意交换 $A_i$ 和 $A_j$ 的顺序总是被视为 2 种拼法,即便是 $A_i$ = $A_j$ 时。 + +请你计算有多少种拼法满足拼出的整数是 K 的倍数。 + +#### 输入格式 +第一行包含 2 个整数 n 和 K。 +第二行包含 n 个整数 $A_1, A_2 , ··· , A_n$。 + + +#### 输出格式 +一个整数代表答案。 + +#### 样例输入 +``` +4 2 +1 2 3 4 +``` +#### 样例输出 +``` +6 +``` +#### 数据范围 +对于 30% 的评测用例,1 ≤ n ≤ 1000, 1 ≤ K ≤ 20, 1 ≤ $A_i$ ≤ $10^4$ +对于所有评测用例,1 ≤ n ≤ $10^5$,1 ≤ K ≤ $10^5$ ,1 ≤ $A_i$ ≤ $10^9$ + diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\225\264\346\225\260\346\213\274\346\216\245/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\225\264\346\225\260\346\213\274\346\216\245/solution.cpp" index e69de29bb..6e0921656 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\225\264\346\225\260\346\213\274\346\216\245/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\225\264\346\225\260\346\213\274\346\216\245/solution.cpp" @@ -0,0 +1,50 @@ +#include +using namespace std; + +typedef long long LL; + +const int N = 10010; + +LL a[N]; + +LL judge(int x) +{ + LL len = 0, t = 1; + + while (x) + { + x /= 10; + len++; + } + + for (int i = 1; i <= len; i++) + t *= 10; + return t; +} + +int main() +{ + int n, k; + cin >> n >> k; + + for (int i = 1; i <= n; i++) + cin >> a[i]; + + LL ans = 0; + for (int i = 1; i <= n; i++) + for (int j = i + 1; j <= n; j++) + { + LL p = judge(a[i]), q = judge(a[j]); + + LL x = a[i] * q + a[j]; + LL y = a[j] * p + a[i]; + + if (x % k == 0) + ans++; + if (y % k == 0) + ans++; + } + + cout << ans << endl; + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\225\264\351\231\244\345\272\217\345\210\227/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\225\264\351\231\244\345\272\217\345\210\227/desc.md" index e69de29bb..c72540892 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\225\264\351\231\244\345\272\217\345\210\227/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\225\264\351\231\244\345\272\217\345\210\227/desc.md" @@ -0,0 +1,18 @@ +有一个序列,序列的第一个数是n,后面的每个数是前一个数整除2,请输出这个序列中值为正数的项。 +#### 输入格式 +输入一行包含一个整数n。 +#### 输出格式 +输出一行,包含多个整数,相邻的整数之间用一个空格分隔,表示答案。 +#### 样例输入 +``` +20 +``` +#### 样例输出 +``` +20 10 5 2 1 +``` +#### 评测用例规模与约定 +``` +对于80% 的评测用例,1 < n <= 10^9。 +对于所有评测用例,1 < n <=10^18。 +``` \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\225\264\351\231\244\345\272\217\345\210\227/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\225\264\351\231\244\345\272\217\345\210\227/solution.cpp" index e69de29bb..bea1bd156 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\225\264\351\231\244\345\272\217\345\210\227/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\225\264\351\231\244\345\272\217\345\210\227/solution.cpp" @@ -0,0 +1,13 @@ +#include +using namespace std; +int main() +{ + long long n; + cin >> n; + while (n) + { + cout << n << " "; + n = n / 2; + } + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\226\220\346\263\242\351\202\243\345\245\221/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\226\220\346\263\242\351\202\243\345\245\221/desc.md" index e69de29bb..d49ec3aa7 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\226\220\346\263\242\351\202\243\345\245\221/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\226\220\346\263\242\351\202\243\345\245\221/desc.md" @@ -0,0 +1,27 @@ +Fibonacci数列的递推公式为:Fn=Fn-1+Fn-2,其中F1=F2=1。 +当n比较大时,Fn也非常大,现在我们想知道,Fn除以10007的余数是多少。 +#### 输入格式 +输入包含一个整数n。 +输出格式 +输出一行,包含一个整数,表示Fn除以10007的余数。 +说明:在本题中,答案是要求Fn除以10007的余数,因此我们只要能算出这个余数即可,而不需要先计算出Fn的准确值,再将计算的结果除以10007取余数,直接计算余数往往比先算出原数再取余简单。 +#### 样例输入 +``` +10 +``` +#### 样例输出 +``` +55 +``` +#### 样例输入 +``` +22 +``` +#### 样例输出 +``` +7704 +``` +#### 数据规模与约定 +``` +1 <= n <= 1,000,000。 +``` \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\226\220\346\263\242\351\202\243\345\245\221/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\226\220\346\263\242\351\202\243\345\245\221/solution.cpp" index e69de29bb..2d66b3d52 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\226\220\346\263\242\351\202\243\345\245\221/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\226\220\346\263\242\351\202\243\345\245\221/solution.cpp" @@ -0,0 +1,20 @@ +#include + +int main() +{ + int n, b; + scanf("%d", &n); + int a[n]; + a[0] = a[1] = 1; + + for (int i = 2; i < n; i++) + { + a[i] = (a[i - 1] + a[i - 2]) % 10007; + b = a[i]; + } + if (n > 2) + printf("%d", b); + else + printf("1"); + return 0; +} \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227\346\234\200\345\244\247\345\205\254\347\272\246\346\225\260/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227\346\234\200\345\244\247\345\205\254\347\272\246\346\225\260/desc.md" index e69de29bb..2dddfe962 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227\346\234\200\345\244\247\345\205\254\347\272\246\346\225\260/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227\346\234\200\345\244\247\345\205\254\347\272\246\346\225\260/desc.md" @@ -0,0 +1,2 @@ +#### 问题描述 +斐波那契数列满足 F1 = F2 = 1,从 F3 开始有 Fn = Fn−1 + Fn−2。请你计算 GCD(F2020, F520),其中 GCD(A, B) 表示 A 和 B 的最大公约数。 \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227\346\234\200\345\244\247\345\205\254\347\272\246\346\225\260/solution.java" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227\346\234\200\345\244\247\345\205\254\347\272\246\346\225\260/solution.java" index e69de29bb..6641fde72 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227\346\234\200\345\244\247\345\205\254\347\272\246\346\225\260/solution.java" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227\346\234\200\345\244\247\345\205\254\347\272\246\346\225\260/solution.java" @@ -0,0 +1,24 @@ + +import java.math.BigInteger; + +public class BigNumber { + public static void main(String[] args) { + BigInteger a = new BigInteger("1"); + BigInteger b = new BigInteger("1"); + BigInteger[] fib = new BigInteger[2030]; + fib[1] = a; + fib[2] = b; + for (int x = 3; x < fib.length; x++) { + fib[x] = fib[x - 1].add(fib[x - 2]); + } + a = fib[2020]; + b = fib[520]; + BigInteger temp; + while (b != BigInteger.ZERO) { + temp = a.mod(b); + a = b; + b = temp; + } + System.out.println(a); + } +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\226\271\346\240\274\345\210\206\345\211\262/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\226\271\346\240\274\345\210\206\345\211\262/desc.md" index e69de29bb..0dda2c9ac 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\226\271\346\240\274\345\210\206\345\211\262/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\226\271\346\240\274\345\210\206\345\211\262/desc.md" @@ -0,0 +1,12 @@ +6x6的方格,沿着格子的边线剪开成两部分。 +要求这两部分的形状完全相同。 + +如图: +![](https://img-blog.csdn.net/20180321145603391) +![](https://img-blog.csdn.net/20180321145607269) +![](https://img-blog.csdn.net/20180321145611157) +就是可行的分割法。 + +试计算: +包括这3种分法在内,一共有多少种不同的分割方法。 +注意:旋转对称的属于同一种分割法。 \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\226\271\346\240\274\345\210\206\345\211\262/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\226\271\346\240\274\345\210\206\345\211\262/solution.cpp" index e69de29bb..9e4ec15c1 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\226\271\346\240\274\345\210\206\345\211\262/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\226\271\346\240\274\345\210\206\345\211\262/solution.cpp" @@ -0,0 +1,38 @@ +#include +using namespace std; + +int ans; +int dire[][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}}; //代表4个方向,上下左右 +int vis[7][7]; //哪些点已被访问过 +void dfs(int x, int y) +{ + if (x == 0 || y == 0 || x == 6 || y == 6) + { //终止出口条件,当走到边缘的时候,符合题意 + ans++; + return; + } + //当前的点标注为已访问的点 + vis[x][y] = 1; + //对称的点也标注为已访问的点 + vis[6 - x][6 - y] = 1; + for (int k = 0; k < 4; k++) + { + int nx = x + dire[k][0]; //横坐标的增量 + int ny = y + dire[k][1]; //纵坐标的增量 + //新坐标 + if (nx < 0 || nx > 6 || ny < 0 || ny > 6) + continue; //越界,不符合 + if (!vis[nx][ny]) + { //若新的点未被访问过 + dfs(nx, ny); //深搜 + } + } + vis[x][y] = 0; + vis[6 - x][6 - y] = 0; //对称 +} +int main() +{ + dfs(3, 3); //初始点 + cout << ans / 4 << endl; + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\226\271\346\240\274\345\241\253\346\225\260/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\226\271\346\240\274\345\241\253\346\225\260/desc.md" index e69de29bb..26e302f67 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\226\271\346\240\274\345\241\253\346\225\260/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\226\271\346\240\274\345\241\253\346\225\260/desc.md" @@ -0,0 +1,6 @@ +如下图 +![](https://img-blog.csdnimg.cn/20190313140048205.jpg) +填入0~9的数字。要求:连续的两个数字不能相邻。 +(左右、上下、对角都算相邻) + +一共有多少种可能的填数方案? \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\226\271\346\240\274\345\241\253\346\225\260/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\226\271\346\240\274\345\241\253\346\225\260/solution.cpp" index e69de29bb..447ac242d 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\226\271\346\240\274\345\241\253\346\225\260/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\226\271\346\240\274\345\241\253\346\225\260/solution.cpp" @@ -0,0 +1,41 @@ +#include +#include +#include +using namespace std; + +int a[10]; +int ans; + +bool check() +{ + if (abs(a[0] - a[1]) == 1 || abs(a[0] - a[3]) == 1 || abs(a[0] - a[4]) == 1 || abs(a[0] - a[5]) == 1) + return false; + if (abs(a[1] - a[2]) == 1 || abs(a[1] - a[4]) == 1 || abs(a[1] - a[5]) == 1 || abs(a[1] - a[6]) == 1) + return false; + if (abs(a[2] - a[5]) == 1 || abs(a[2] - a[6]) == 1) + return false; + if (abs(a[3] - a[4]) == 1 || abs(a[3] - a[7]) == 1 || abs(a[3] - a[8]) == 1) + return false; + if (abs(a[4] - a[5]) == 1 || abs(a[4] - a[7]) == 1 || abs(a[4] - a[8]) == 1 || abs(a[4] - a[9]) == 1) + return false; + if (abs(a[5] - a[6]) == 1 || abs(a[5] - a[8]) == 1 || abs(a[5] - a[9]) == 1) + return false; + if (abs(a[6] - a[9]) == 1) + return false; + if (abs(a[7] - a[8]) == 1 || abs(a[8] - a[9]) == 1) + return false; + return true; +} +int main() +{ + for (int i = 0; i <= 9; i++) + a[i] = i; //初始化 + + do + { + if (check()) + ans++; //如果符合条件则答案加1 + } while (next_permutation(a, a + 10)); + cout << ans; + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\226\271\346\240\274\350\256\241\346\225\260/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\226\271\346\240\274\350\256\241\346\225\260/desc.md" index e69de29bb..8ff04f618 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\226\271\346\240\274\350\256\241\346\225\260/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\226\271\346\240\274\350\256\241\346\225\260/desc.md" @@ -0,0 +1,4 @@ +如图所示,在二维平面上有无数个1x1的小方格。 +我们以某个小方格的一个顶点为圆心画一个半径为1000的圆。 +你能计算出这个圆里有多少个完整的小方格吗? +![](https://upload-images.jianshu.io/upload_images/15659652-2abc8a1de9a368d2.png?imageMogr2/auto-orient/strip|imageView2/2/w/394/format/webp) \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\226\271\346\240\274\350\256\241\346\225\260/solution.java" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\226\271\346\240\274\350\256\241\346\225\260/solution.java" index e69de29bb..d8ca3b326 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\226\271\346\240\274\350\256\241\346\225\260/solution.java" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\226\271\346\240\274\350\256\241\346\225\260/solution.java" @@ -0,0 +1,18 @@ +import java.util.*; + +public class Main { + public static void main(String[] args) { + int r = 1000; + int sum = 0; + for (int a = 1; a <= 1001; a++) { + for (int b = 1; b <= 1001; b++) { + if (a * a + b * b <= r * r) + sum++; + } + } + sum *= 4; + System.out.println(sum); + + } +} +// 3137548 diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\226\271\347\250\213\346\225\264\346\225\260\350\247\243/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\226\271\347\250\213\346\225\264\346\225\260\350\247\243/desc.md" index e69de29bb..e8bac703c 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\226\271\347\250\213\346\225\264\346\225\260\350\247\243/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\226\271\347\250\213\346\225\264\346\225\260\350\247\243/desc.md" @@ -0,0 +1,22 @@ +#### 题目描述 +方程: a^2 + b^2 + c^2 = 1000 +这个方程有正整数解吗?有:a,b,c=6,8,30 就是一组解。 +求出 a^2 + b^2 + c^2 = n(1<=n<=10000)的所有解,解要保证c>=b>=a>=1。 + +#### 输入 +存在多组测试数据,每组测试数据一行包含一个正整数n(1<=n<=10000) +#### 输出 +如果无解则输出"No Solution"。 +如果存在多解,每组解输出1行,输出格式:a b c,以一个空格分隔 +按照a从小到大的顺序输出,如果a相同则按照b从小到大的顺序输出,如果a,b都相同则按照c从小到大的顺序输出。 +#### 样例输入 +``` +4 +1000 +``` +#### 样例输出 +``` +No Solution +6 8 30 +10 18 24 +``` \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\226\271\347\250\213\346\225\264\346\225\260\350\247\243/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\226\271\347\250\213\346\225\264\346\225\260\350\247\243/solution.cpp" index e69de29bb..c7cc9476b 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\226\271\347\250\213\346\225\264\346\225\260\350\247\243/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\226\271\347\250\213\346\225\264\346\225\260\350\247\243/solution.cpp" @@ -0,0 +1,32 @@ +#include +#include +using namespace std; +int main() +{ + int n; + bool flag = false; + while (cin >> n) + { + flag = false; + for (int i = 1; i <= sqrt(n); i++) + { + for (int j = i; j <= sqrt(n); j++) + { + for (int k = j; k <= sqrt(n); k++) + { + if (i * i + j * j + k * k == n) + { + cout << i << ' ' << j << ' ' << k << endl; + flag = true; + } + else if (i * i + j * j + k * k > n) + break; + } + } + } + if (!flag) + cout << "No Solution" << endl; + } + + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\226\271\351\230\265\350\275\254\347\275\256/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\226\271\351\230\265\350\275\254\347\275\256/desc.md" index e69de29bb..785204fb7 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\226\271\351\230\265\350\275\254\347\275\256/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\226\271\351\230\265\350\275\254\347\275\256/desc.md" @@ -0,0 +1,22 @@ +#### 问题描述 + +给定一个n×m矩阵相乘,求它的转置。其中1≤n≤20,1≤m≤20,矩阵中的每个元素都在整数类型(4字节)的表示范围内。 +#### 输入格式 +第一行两个整数n和m; +第二行起,每行m个整数,共n行,表示n×m的矩阵。数据之间都用一个空格分隔。 +#### 输出格式 + +共m行,每行n个整数,数据间用一个空格分隔,表示转置后的矩阵。 +#### 样例输入 +``` +2 4 +34 76 -54 7 +-4 5 23 9 +``` +#### 样例输出 +``` +34 -4 +76 5 +-54 23 +7 9 +``` \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\226\271\351\230\265\350\275\254\347\275\256/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\226\271\351\230\265\350\275\254\347\275\256/solution.cpp" index e69de29bb..c65689567 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\226\271\351\230\265\350\275\254\347\275\256/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\226\271\351\230\265\350\275\254\347\275\256/solution.cpp" @@ -0,0 +1,27 @@ +#include + +using namespace std; + +int main() +{ + int m, n; + int a[20][20]; + int i, j; + cin >> m >> n; + for (i = 0; i < m; i++) + { + for (j = 0; j < n; j++) + { + cin >> a[j][i]; + } + } + for (i = 0; i < n; i++) + { + for (j = 0; j < m; j++) + { + cout << a[i][j] << " "; + } + cout << endl; + } + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\227\242\347\272\246\345\210\206\346\225\260/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\227\242\347\272\246\345\210\206\346\225\260/desc.md" index e69de29bb..cacb54521 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\227\242\347\272\246\345\210\206\346\225\260/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\227\242\347\272\246\345\210\206\346\225\260/desc.md" @@ -0,0 +1,3 @@ +如果一个分数的分子和分母的最大公约数是 1,这个分数称为既约分数。 +例如,3/4 , 2/5, 1/8 , 1/7 都是既约分数。 +请问,有多少个既约分数,分子和分母都是 1 到 2020 之间的整数(包括 1 和 2020)? \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\227\242\347\272\246\345\210\206\346\225\260/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\227\242\347\272\246\345\210\206\346\225\260/solution.cpp" index e69de29bb..9489a1dfc 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\227\242\347\272\246\345\210\206\346\225\260/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\227\242\347\272\246\345\210\206\346\225\260/solution.cpp" @@ -0,0 +1,23 @@ +#include +using namespace std; +int num = 2020; + +int hcf(int i, int j) +{ + return (!j) ? i : hcf(j, i % j); +} + +int main() +{ + int sum = 0; + for (int i = 1; i <= num; i++) + { + for (int j = 1; j <= num; j++) + { + if (hcf(i, j) == 1) + sum++; + } + } + cout << sum; + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\227\245\345\277\227\347\273\237\350\256\241/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\227\245\345\277\227\347\273\237\350\256\241/desc.md" index e69de29bb..9e13a8690 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\227\245\345\277\227\347\273\237\350\256\241/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\227\245\345\277\227\347\273\237\350\256\241/desc.md" @@ -0,0 +1,47 @@ +#### 题目描述 +小明维护着一个程序员论坛。现在他收集了一份”点赞”日志,日志共有 N 行。 + +其中每一行的格式是: +ts id +表示在 ts 时刻编号 id 的帖子收到一个”赞”。 + +现在小明想统计有哪些帖子曾经是”热帖”。 + +如果一个帖子曾在任意一个长度为 D 的时间段内收到不少于 K 个赞,小明就认为这个帖子曾是”热帖”。 + +具体来说,如果存在某个时刻 T 满足该帖在 [T,T+D) 这段时间内(注意是左闭右开区间)收到不少于 K 个赞,该帖就曾是”热帖”。 + +给定日志,请你帮助小明统计出所有曾是”热帖”的帖子编号。 + +#### 输入格式 +第一行包含三个整数 N,D,K。 + +以下 N 行每行一条日志,包含两个整数 ts 和 id。 + +#### 输出格式 +按从小到大的顺序输出热帖 id。 + +每个 id 占一行。 + +#### 数据范围 +``` +1≤K≤N≤10E5, +0≤ts,id≤10E5, +1≤D≤10000 +``` +#### 输入样例: +``` +7 10 2 +0 1 +0 10 +10 10 +10 1 +9 1 +100 3 +100 3 +``` +#### 输出样例: +``` +1 +3 +``` \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\227\245\345\277\227\347\273\237\350\256\241/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\227\245\345\277\227\347\273\237\350\256\241/solution.cpp" index e69de29bb..878d84d2a 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\227\245\345\277\227\347\273\237\350\256\241/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\227\245\345\277\227\347\273\237\350\256\241/solution.cpp" @@ -0,0 +1,35 @@ +#include +#include + +using namespace std; +const int N = 1e5 + 10; +typedef pair PII; +#define x first +#define y second +PII logs[N]; +bool st[N]; +int cnt[N]; + +int main() +{ + int n, d, k; + cin >> n >> d >> k; + for (int i = 0; i < n; i++) + cin >> logs[i].x >> logs[i].y; //时间,编号 + + sort(logs, logs + n); //按照时间先排序 + + for (int i = 0, j = 0; i < n; i++) + { + cnt[logs[i].y]++; //目标编号出现次数加1 + while (logs[i].x - logs[j].x >= d) + cnt[logs[j].y]--, j++; //滑动窗口,保证目标区域合法 + if (cnt[logs[i].y] >= k) + st[logs[i].y] = true; //如果编号次数超K则输出 + } + + for (int i = 0; i < N; i++) + if (st[i]) + cout << i << endl; + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\227\245\346\234\237\351\227\256\351\242\230/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\227\245\346\234\237\351\227\256\351\242\230/desc.md" index e69de29bb..e46bc7c89 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\227\245\346\234\237\351\227\256\351\242\230/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\227\245\346\234\237\351\227\256\351\242\230/desc.md" @@ -0,0 +1,24 @@ +小明正在整理一批历史文献。这些历史文献中出现了很多日期。小明知道这些日期都在1960年1月1日至2059年12月31日。令小明头疼的是,这些日期采用的格式非常不统一,有采用年/月/日的,有采用月/日/年的,还有采用日/月/年的。更加麻烦的是,年份也都省略了前两位,使得文献上的一个日期,存在很多可能的日期与其对应。 + +比如02/03/04,可能是2002年03月04日、2004年02月03日或2004年03月02日。 + +给出一个文献上的日期,你能帮助小明判断有哪些可能的日期对其对应吗? + +#### 输入 + +一个日期,格式是"AA/BB/CC"。 (0 <= A, B, C <= 9) + +#### 输出 + +输出若干个不相同的日期,每个日期一行,格式是"yyyy-MM-dd"。多个日期按从早到晚排列。 + +#### 样例输入 +``` +02/03/04 +``` +#### 样例输出 +``` +2002-03-04 +2004-02-03 +2004-03-02 +``` diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\227\245\346\234\237\351\227\256\351\242\230/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\227\245\346\234\237\351\227\256\351\242\230/solution.cpp" index e69de29bb..849d68a63 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\227\245\346\234\237\351\227\256\351\242\230/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\227\245\346\234\237\351\227\256\351\242\230/solution.cpp" @@ -0,0 +1,80 @@ +#include +#include +#include +using namespace std; + +typedef struct +{ + int year, month, day; +} date; + +bool isyn(int y) +{ + return (y % 4 == 0) || (y % 100 && y % 400 == 0); +} + +void print(const date &d) +{ + printf("%02d-%02d-%02d\n", d.year, d.month, d.day); +} + +bool compare(const date &d1, const date &d2) +{ + if (d1.year != d2.year) + { + return d1.year < d2.year; + } + if (d1.month != d2.month) + { + return d1.month < d2.month; + } + return d1.day < d2.day; +} + +bool check(const date &d) +{ + static int month_days[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; + if (isyn(d.year)) + { + month_days[2] = 29; + } + else + { + month_days[2] = 28; + } + + if (d.year < 1960 || d.year > 2059) + { + return false; + } + if (d.month < 1 || d.month > 12) + { + return false; + } + if (d.day < 1 || d.day > month_days[d.month]) + { + return false; + } +} + +int main() +{ + int aa, bb, cc; + scanf("%d/%d/%d", &aa, &bb, &cc); + date d[6] = { + {2000 + aa, bb, cc}, + {1900 + aa, bb, cc}, + {2000 + cc, aa, bb}, + {1900 + cc, aa, bb}, + {2000 + cc, bb, aa}, + {1900 + cc, bb, aa}}; + sort(d, d + 6, compare); + for (int i = 0; i < 6; ++i) + { + if (check(d[i])) + { + print(d[i]); + } + } + return 0; +} \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\230\216\347\240\201/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\230\216\347\240\201/desc.md" index e69de29bb..dcfbaa035 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\230\216\347\240\201/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\230\216\347\240\201/desc.md" @@ -0,0 +1,32 @@ +汉字的字形存在于字库中,即便在今天,16点阵的字库也仍然使用广泛。 + +16点阵的字库把每个汉字看成是16x16个像素信息。并把这些信息记录在字节中。 + +一个字节可以存储8位信息,用32个字节就可以存一个汉字的字形了。 + +把每个字节转为2进制表示,1表示墨迹,0表示底色。 + +每行2个字节,一共16行,布局是: + +第1字节,第2字节 +第3字节,第4字节 +… +第31字节, 第32字节 + +这道题目是给你一段多个汉字组成的信息,每个汉字用32个字节表示,这里给出了字节作为有符号整数的值。 + +题目的要求隐藏在这些信息中。你的任务是复原这些汉字的字形,从中看出题目的要求,并根据要求填写答案。 + +这段信息是(一共10个汉字): +``` +4 0 4 0 4 0 4 32 -1 -16 4 32 4 32 4 32 4 32 4 32 8 32 8 32 16 34 16 34 32 30 -64 0 +16 64 16 64 34 68 127 126 66 -124 67 4 66 4 66 -124 126 100 66 36 66 4 66 4 66 4 126 4 66 40 0 16 +4 0 4 0 4 0 4 32 -1 -16 4 32 4 32 4 32 4 32 4 32 8 32 8 32 16 34 16 34 32 30 -64 0 +0 -128 64 -128 48 -128 17 8 1 -4 2 8 8 80 16 64 32 64 -32 64 32 -96 32 -96 33 16 34 8 36 14 40 4 +4 0 3 0 1 0 0 4 -1 -2 4 0 4 16 7 -8 4 16 4 16 4 16 8 16 8 16 16 16 32 -96 64 64 +16 64 20 72 62 -4 73 32 5 16 1 0 63 -8 1 0 -1 -2 0 64 0 80 63 -8 8 64 4 64 1 64 0 -128 +0 16 63 -8 1 0 1 0 1 0 1 4 -1 -2 1 0 1 0 1 0 1 0 1 0 1 0 1 0 5 0 2 0 +2 0 2 0 7 -16 8 32 24 64 37 -128 2 -128 12 -128 113 -4 2 8 12 16 18 32 33 -64 1 0 14 0 112 0 +1 0 1 0 1 0 9 32 9 16 17 12 17 4 33 16 65 16 1 32 1 64 0 -128 1 0 2 0 12 0 112 0 +0 0 0 0 7 -16 24 24 48 12 56 12 0 56 0 -32 0 -64 0 -128 0 0 0 0 1 -128 3 -64 1 -128 0 0 +``` \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\230\216\347\240\201/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\230\216\347\240\201/solution.cpp" index e69de29bb..4284550be 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\230\216\347\240\201/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\230\216\347\240\201/solution.cpp" @@ -0,0 +1,47 @@ +#include //万能头文件 +using namespace std; +const int N = 15; +void code(int x) +{ + int std[N], flag = 0; + if (x < 0) + flag = 1, x = -x; //小于0求其绝对值 + for (int i = 0; i < 8; ++i) + { //转换2进制 + std[i] = x % 2; + x /= 2; + } + if (flag) // 如果是负数要求补码 + for (int i = 0; i < 8; ++i) //对8位二进制遍历 + if (std[i] == 1 && i < 7) + { //找到不为0的第一位 + for (int j = i + 1; j < 8; ++j) + std[j] = 1 - std[j]; //从第不为零的一位开始取反 + break; //跳出第一重for循环 + } + for (int i = 7; i >= 0; --i) + { //逆序输出 + if (std[i] == 0) + printf(" "); //0输出空格 + else + printf("*"); //1输出* + } +} +int main() +{ + int i = 10; + while (i--) + { //对10行数码遍历 + for (int j = 1; j < 17; ++j) + { //一行32个数,每次读取两个,所以循环16次 + int p; + scanf("%d", &p); + code(p); + scanf("%d", &p); + code(p); + printf("\n"); + } + printf("\n\n\n"); //输出完成一个字后换行 + } + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\230\237\346\234\237\344\270\200/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\230\237\346\234\237\344\270\200/desc.md" index e69de29bb..6864163fd 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\230\237\346\234\237\344\270\200/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\230\237\346\234\237\344\270\200/desc.md" @@ -0,0 +1 @@ +整个20世纪(1901年1月1日至2000年12月31日之间),一共有多少个星期一?(不要告诉我你不知道今天是星期几) \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\230\237\346\234\237\344\270\200/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\230\237\346\234\237\344\270\200/solution.cpp" index e69de29bb..eb068383d 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\230\237\346\234\237\344\270\200/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\230\237\346\234\237\344\270\200/solution.cpp" @@ -0,0 +1,47 @@ +#include +#include +using namespace std; + +int a[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; +int b[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; // 闰年 +int days = 0; //共多少天 +int rows = 0; //共多少行 +bool f(int n) // n是不是闰年 +{ + if ((n % 4 == 0 && n % 100 != 0) || n % 100 == 0) + return true; + else + return false; +} + +void print(int t[]) //打印那一年 +{ + for (int i = 0; i < 12; i++) + { + for (int j = 1; j <= t[i]; j++) + { + cout << j << " "; + days++; + if (days % 7 == 0) // 7天一礼拜 + { + cout << endl; + rows++; + } + } + } +} +int main() +{ + int start = 1901; + int end = 2000; + for (int i = start; i <= end; i++) + { + if (f(i) == true) //是闰年,按b数组打印 + print(b); + else //不是,按a数组打印 + print(a); + } + cout << "rows is " << endl; + cout << rows << endl; + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\230\237\347\263\273\347\202\270\345\274\271/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\230\237\347\263\273\347\202\270\345\274\271/desc.md" index e69de29bb..2dddddb90 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\230\237\347\263\273\347\202\270\345\274\271/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\230\237\347\263\273\347\202\270\345\274\271/desc.md" @@ -0,0 +1,4 @@ +在X星系的广袤空间中漂浮着许多X星人造“炸弹”,用来作为宇宙中的路标。 +每个炸弹都可以设定多少天之后爆炸。 +比如:阿尔法炸弹2015年1月1日放置,定时为15天,则它在2015年1月16日爆炸。 +有一个贝塔炸弹,2014年11月9日放置,定时为1000天,请你计算它爆炸的准确日期。 diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\230\237\347\263\273\347\202\270\345\274\271/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\230\237\347\263\273\347\202\270\345\274\271/solution.cpp" index e69de29bb..d79144265 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\230\237\347\263\273\347\202\270\345\274\271/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\230\237\347\263\273\347\202\270\345\274\271/solution.cpp" @@ -0,0 +1,32 @@ +#include +int month[13][2] = {{0, 0}, {31, 31}, {28, 29}, {31, 31}, {30, 30}, {31, 31}, {30, 30}, {31, 31}, {31, 31}, {30, 30}, {31, 31}, {30, 30}, {31, 31}}; + +bool isLeap(int year) +{ + return year % 400 == 0 || (year % 4 == 0 && year % 100 != 0); +} + +int main() +{ + int y, m, d; + int count; + scanf("%d-%d-%d", &y, &m, &d); + scanf("%d", &count); + while (count) + { + d++; + if (d > month[m][isLeap(y)]) + { + d = 1; + m++; + } + if (m > 12) + { + m = 1; + y++; + } + count--; + } + printf("%d-%d-%d", y, m, d); + return 0; +} \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\234\200\345\244\247\345\205\254\345\205\261\345\255\220\344\270\262/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\234\200\345\244\247\345\205\254\345\205\261\345\255\220\344\270\262/desc.md" index e69de29bb..1e39df5ec 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\234\200\345\244\247\345\205\254\345\205\261\345\255\220\344\270\262/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\234\200\345\244\247\345\205\254\345\205\261\345\255\220\344\270\262/desc.md" @@ -0,0 +1,9 @@ +最大公共子串长度问题就是: + +求两个串的所有子串中能够匹配上的最大长度是多少。 + +比如:“abcdkkk” 和 “baabcdadabc”, + +可以找到的最长的公共子串是"abcd",所以最大公共子串长度为4。 + +下面的程序是采用矩阵法进行求解的,这对串的规模不大的情况还是比较有效的解法。 diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\234\200\345\244\247\345\205\254\345\205\261\345\255\220\344\270\262/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\234\200\345\244\247\345\205\254\345\205\261\345\255\220\344\270\262/solution.cpp" index e69de29bb..2ad2cb60b 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\234\200\345\244\247\345\205\254\345\205\261\345\255\220\344\270\262/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\234\200\345\244\247\345\205\254\345\205\261\345\255\220\344\270\262/solution.cpp" @@ -0,0 +1,33 @@ +#include +#include + +#define N 256 +int f(const char *s1, const char *s2) +{ + int a[N][N]; + int len1 = strlen(s1); + int len2 = strlen(s2); + int i, j; + + memset(a, 0, sizeof(int) * N * N); + int max = 0; + for (i = 1; i <= len1; i++) + { + for (j = 1; j <= len2; j++) + { + if (s1[i - 1] == s2[j - 1]) + { + a[i][j] = a[i - 1][j - 1] + 1; //填空 + if (a[i][j] > max) + max = a[i][j]; + } + } + } + return max; +} + +int main() +{ + printf("%d\n", f("abcdkkk", "baabcdadabc")); + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\234\200\345\244\247\346\257\224\344\276\213/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\234\200\345\244\247\346\257\224\344\276\213/desc.md" index e69de29bb..f4a371e76 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\234\200\345\244\247\346\257\224\344\276\213/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\234\200\345\244\247\346\257\224\344\276\213/desc.md" @@ -0,0 +1,55 @@ +X星球的某个大奖赛设了 M 级奖励。 + +每个级别的奖金是一个正整数。 + +并且,相邻的两个级别间的比例是个固定值。 + +也就是说:所有级别的奖金数构成了一个等比数列。 + +比如:16,24,36,54,其等比值为:3/2。 + +现在,我们随机调查了一些获奖者的奖金数。 + +请你据此推算可能的最大的等比值。 + +#### 输入格式 +第一行为数字 N ,表示接下的一行包含 N 个正整数。 + +第二行 N 个正整数 Xi,用空格分开,每个整数表示调查到的某人的奖金数额。 + +#### 输出格式 +一个形如 A/B 的分数,要求 A、B 互质,表示可能的最大比例系数。 + +#### 数据范围 + +$0< N < 100$ +$0 < X_i < 10^12$ +数据保证一定有解。 + +#### 输入样例1: +``` +3 +1250 200 32 +``` +#### 输出样例1: +``` +25/4 +``` +#### 输入样例2: +``` +4 +3125 32 32 200 +``` +#### 输出样例2: +``` +5/2 +``` +#### 输入样例3: +``` +3 +549755813888 524288 2 +``` +#### 输出样例3: +``` +4/1 +``` \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\234\200\345\244\247\346\257\224\344\276\213/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\234\200\345\244\247\346\257\224\344\276\213/solution.cpp" index e69de29bb..8af0f3b7b 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\234\200\345\244\247\346\257\224\344\276\213/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\234\200\345\244\247\346\257\224\344\276\213/solution.cpp" @@ -0,0 +1,53 @@ +#include +#include + +using namespace std; + +typedef long long LL; +const int N = 110; +LL a[N]; +LL p[N], q[N]; //p存分子,q存分母 +int cnt; +int n; + +LL gcd(LL a, LL b) +{ + return b ? gcd(b, a % b) : a; +} + +LL sub_gcd(LL a, LL b) +{ + if (a < b) + swap(a, b); + if (b == 1) + return a; + else + return sub_gcd(b, a / b); +} + +int main() +{ + cin >> n; + for (int i = 0; i < n; i++) + cin >> a[i]; + sort(a, a + n); + LL t; + //化简分式 + for (int i = 1; i < n; i++) + { + t = gcd(a[i], a[i - 1]); + p[cnt] = a[i] / t; + q[cnt] = a[i - 1] / t; + cnt++; + } + //辗转相减法 + LL res1, res2; + res1 = sub_gcd(p[0], p[1]), res2 = sub_gcd(q[0], q[1]); + for (int i = 2; i < cnt; i++) + { + res1 = sub_gcd(res1, p[i]); + res2 = sub_gcd(res2, q[i]); + } + cout << res1 << "/" << res2 << endl; + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\234\200\345\244\247\351\231\215\351\233\250\351\207\217/config.json" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\234\200\345\244\247\351\231\215\351\233\250\351\207\217/config.json" deleted file mode 100644 index f6416a1a5..000000000 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\234\200\345\244\247\351\231\215\351\233\250\351\207\217/config.json" +++ /dev/null @@ -1,6 +0,0 @@ -{ - "node_id": "569d5e11c4fc5de7844053d9a733c5e8", - "keywords": [], - "children": [], - "export": [] -} \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\234\200\345\244\247\351\231\215\351\233\250\351\207\217/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\234\200\345\244\247\351\231\215\351\233\250\351\207\217/desc.md" deleted file mode 100644 index e69de29bb..000000000 diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\234\200\345\244\247\351\231\215\351\233\250\351\207\217/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\234\200\345\244\247\351\231\215\351\233\250\351\207\217/solution.cpp" deleted file mode 100644 index e69de29bb..000000000 diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\234\200\345\244\247\351\231\215\351\233\250\351\207\217/solution.java" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\234\200\345\244\247\351\231\215\351\233\250\351\207\217/solution.java" deleted file mode 100644 index e69de29bb..000000000 diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\234\211\347\220\206\346\225\260\347\261\273/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\234\211\347\220\206\346\225\260\347\261\273/desc.md" index e69de29bb..a94ef577a 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\234\211\347\220\206\346\225\260\347\261\273/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\234\211\347\220\206\346\225\260\347\261\273/desc.md" @@ -0,0 +1,4 @@ +有理数就是可以表示为两个整数的比值的数字。一般情况下,我们用近似的小数表示。 +但有些时候,不允许出现误差,必须用两个整数来表示一个有理数。 +这时,我们可以建立一个“有理数类”,下面的代码初步实现了这个目标。 +为了简明,它只提供了加法和乘法运算。 \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\234\211\347\220\206\346\225\260\347\261\273/solution.java" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\234\211\347\220\206\346\225\260\347\261\273/solution.java" index e69de29bb..8f9401768 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\234\211\347\220\206\346\225\260\347\261\273/solution.java" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\234\211\347\220\206\346\225\260\347\261\273/solution.java" @@ -0,0 +1,39 @@ +public static void main(String[] args) { + Rational a = new Rational(1,3); + Rational b = new Rational(1,6); + Rational c = a.add(b); + System.out.println(a + "+" + b + "=" + c); +} + +private static class Rational +{ + private long ra; + private long rb; + + //辗转相除法求最大公约数gcd + private long gcd(long a, long b){ + if(b==0) return a; + return gcd(b,a%b); + } + public Rational(long a, long b){ + ra = a; + rb = b; + long k = gcd(ra,rb); + if(k>1){ //需要约分 + ra /= k; + rb /= k; + } + } + // 加法 + public Rational add(Rational x){ + return new Rational(ra*x.rb+x.ra*rb, rb*x.rb); //填空位置 + } + // 乘法 + public Rational mul(Rational x){ + return new Rational(ra*x.ra, rb*x.rb); + } + public String toString(){ + if(rb==1) return "" + ra; + return ra + "/" + rb; + } +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\235\216\347\231\275\346\211\223\351\205\222/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\235\216\347\231\275\346\211\223\351\205\222/desc.md" index e69de29bb..78d829acb 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\235\216\347\231\275\346\211\223\351\205\222/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\235\216\347\231\275\346\211\223\351\205\222/desc.md" @@ -0,0 +1,6 @@ +话说大诗人李白,一生好饮。幸好他从不开车。 +一天,他提着酒壶,从家里出来,酒壶中有酒2斗。他边走边唱: +无事街上走,提壶去打酒。 +逢店加一倍,遇花喝一斗。 +这一路上,他一共遇到店5次,遇到花10次,已知最后一次遇到的是花,他正好把酒喝光了。 +请你计算李白遇到店和花的次序,可以把遇店记为a,遇花记为b。则:babaabbabbabbbb 就是合理的序。像这样的答案一共有多少呢?请你计算出所有可能方案的个数(包含题目给出的)。 diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\235\216\347\231\275\346\211\223\351\205\222/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\235\216\347\231\275\346\211\223\351\205\222/solution.cpp" index e69de29bb..917304f08 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\235\216\347\231\275\346\211\223\351\205\222/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\235\216\347\231\275\346\211\223\351\205\222/solution.cpp" @@ -0,0 +1,19 @@ +#include +using namespace std; + +int sum = 0; //注意这里的sum需要是全局变量,否则在函数体内会每次都被初始化为0,无法达到计数效果 +int f(int a, int b, int c) //a代表遇到的是店,b代表遇到的是花,c代表酒的总量 +{ + if (a > 0) + f(a - 1, b, 2 * c); //逢店加一倍,同时遇到的店个数 -1 + if (b > 0) + f(a, b - 1, c - 1); //遇花喝一斗,同时遇到的花个数 -1 + if (a == 0 && b == 0 && c == 1) //这里的c为1,是因为最后遇到的是花,所以最后遇到花的情况在这里不考虑,那么遇到 + sum += 1; //花之前还剩1斗 + return sum; //因为需要多次调用这个函数,所以不能在函数体里输出sum +} +int main(void) +{ + cout << f(5, 9, 2) << endl; + return 0; +} \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\240\274\345\255\220\344\270\255\350\276\223\345\207\272/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\240\274\345\255\220\344\270\255\350\276\223\345\207\272/desc.md" index e69de29bb..e577b2803 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\240\274\345\255\220\344\270\255\350\276\223\345\207\272/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\240\274\345\255\220\344\270\255\350\276\223\345\207\272/desc.md" @@ -0,0 +1,4 @@ +StringInGrid函数会在一个指定大小的格子中打印指定的字符串。 要求字符串在水平、垂直两个方向上都居中。 如果字符串太长,就截断。 如果不能恰好居中,可以稍稍偏左或者偏上一点。 +输出: + +![](https://img-blog.csdnimg.cn/20200327144609874.png#pic_center) \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\240\274\345\255\220\344\270\255\350\276\223\345\207\272/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\240\274\345\255\220\344\270\255\350\276\223\345\207\272/solution.cpp" index e69de29bb..68e2dc13a 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\240\274\345\255\220\344\270\255\350\276\223\345\207\272/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\240\274\345\255\220\344\270\255\350\276\223\345\207\272/solution.cpp" @@ -0,0 +1,41 @@ +#include +#include +void StringInGrid(int width, int height, const char *s) +{ + int i, k; + char buf[1000]; + strcpy(buf, s); + if (strlen(s) > width - 2) + buf[width - 2] = 0; + printf("+"); + for (i = 0; i < width - 2; i++) + printf("-"); + printf("+\n"); + for (k = 1; k < (height - 1) / 2; k++) + { + printf("|"); + for (i = 0; i < width - 2; i++) + printf(" "); + printf("|\n"); + } + printf("|"); + printf("%*s%s%*s", (width - strlen(buf) - 2) / 2, "", buf, (width - strlen(buf) - 2) / 2, ""); + printf("|\n"); + for (k = (height - 1) / 2 + 1; k < height - 1; k++) + { + printf("|"); + for (i = 0; i < width - 2; i++) + printf(" "); + printf("|\n"); + } + printf("+"); + for (i = 0; i < width - 2; i++) + printf("-"); + printf("+\n"); +} + +int main() +{ + StringInGrid(20, 6, "abcd1234"); + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\242\205\346\243\256\347\264\240\346\225\260/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\242\205\346\243\256\347\264\240\346\225\260/desc.md" index e69de29bb..bf092ef0d 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\242\205\346\243\256\347\264\240\346\225\260/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\242\205\346\243\256\347\264\240\346\225\260/desc.md" @@ -0,0 +1,21 @@ +如果一个数字的所有真因子之和等于自身,则称它为“完全数”或“完美数” + +例如:6 = 1 + 2 + 3 + +28 = 1 + 2 + 4 + 7 + 14 + +早在公元前300多年,欧几里得就给出了判定完全数的定理: + +若 2^n - 1 是素数,则 2^(n-1) * (2^n - 1) 是完全数。 + +其中 ^ 表示“乘方”运算,乘方的优先级比四则运算高,例如:2^3 = 8, 2 * 2^3 = 16, 2^3-1 = 7 + +但人们很快发现,当n很大时,判定一个大数是否为素数到今天也依然是个难题。 + +因为法国数学家梅森的猜想,我们习惯上把形如:2^n - 1 的素数称为:梅森素数。 + +截止2013年2月,一共只找到了48个梅森素数。 新近找到的梅森素数太大,以至于难于用一般的编程思路窥其全貌,所以我们把任务的难度降低一点: + +1963年,美国伊利诺伊大学为了纪念他们找到的第23个梅森素数 n=11213,在每个寄出的信封上都印上了“2^11213-1 是素数”的字样。 + +2^11213 - 1 这个数字已经很大(有3000多位),请你编程求出这个素数的十进制表示的最后100位。 diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\242\205\346\243\256\347\264\240\346\225\260/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\242\205\346\243\256\347\264\240\346\225\260/solution.cpp" index e69de29bb..55f6aae65 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\242\205\346\243\256\347\264\240\346\225\260/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\242\205\346\243\256\347\264\240\346\225\260/solution.cpp" @@ -0,0 +1,34 @@ +#include + +int k = 1; +int a[1000] = {0}; +void print() +{ + for (int j = k - 1; j >= 0; j--) + printf("%d", a[j]); + printf("\n"); +} +int main() +{ + + a[0] = 2; + int n = 11213; //调整n的值得到2^n的值 + for (int i = 1; i < n; i++) + { + int temp = a[k]; + for (int j = 0; j < k; j++) + { + a[j] *= 2; + } + + for (int j = 0; j < k; j++) + { + a[j + 1] += a[j] / 10; + a[j] %= 10; + } //这两个循环都是模拟加法的过程 + if (temp == 0 && a[k] != 0) + k++; //说明加一个位数 如从百位到十位 十位到百位 + } + print(); + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\255\243\345\210\231\351\227\256\351\242\230/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\255\243\345\210\231\351\227\256\351\242\230/desc.md" index e69de29bb..0cf98a4d1 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\255\243\345\210\231\351\227\256\351\242\230/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\255\243\345\210\231\351\227\256\351\242\230/desc.md" @@ -0,0 +1,16 @@ +#### 问题描述: +考虑一种简单的正则表达式:只由```x()|```组成的正则表达式。 +小明想求出这个正则表达式能接受的最长字符串的长度。 +例如```((xx|xxx)x|(x|xx))xx``` 能接受的最长字符串是: ```xxxxxx```,长度是6。 +#### 输入格式: +一个由```x()|```组成的正则表达式。输入长度不超过100,保证合法。 +#### 输出格式: +这个正则表达式能接受的最长字符串的长度。 +#### 样例输入: +``` +((xx|xxx)x|(x|xx))xx +``` +样例输出: +``` +6 +``` \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\255\243\345\210\231\351\227\256\351\242\230/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\255\243\345\210\231\351\227\256\351\242\230/solution.cpp" index e69de29bb..426c155e0 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\255\243\345\210\231\351\227\256\351\242\230/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\255\243\345\210\231\351\227\256\351\242\230/solution.cpp" @@ -0,0 +1,39 @@ +#include +#include +using namespace std; +string str; +int i = 0; +int dfs() +{ + int mmax = 0, cnt = 0; + while (i < str.size()) + { + if (str[i] == '(') + { + i++; + cnt += dfs(); + } + else if (str[i] == 'x') + { + cnt++; + i++; + } + else if (str[i] == '|') + { + mmax = max(cnt, mmax); + i++; + cnt = 0; + } + else + { + i++; + break; + } + } + return mmax = max(mmax, cnt); +} +int main() +{ + cin >> str; + cout << dfs(); +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\255\246\345\212\237\347\247\230\347\261\215/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\255\246\345\212\237\347\247\230\347\261\215/desc.md" index e69de29bb..c386c17e9 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\255\246\345\212\237\347\247\230\347\261\215/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\255\246\345\212\237\347\247\230\347\261\215/desc.md" @@ -0,0 +1,2 @@ +小明到X山洞探险,捡到一本有破损的武功秘籍(2000多页!当然是伪造的)。他注意到:书的第10页和第11页在同一张纸上,但第11页和第12页不在同一张纸上。 +小明只想练习该书的第81页到第92页的武功,又不想带着整本书。请问他至少要撕下多少张纸带走? \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\255\246\345\212\237\347\247\230\347\261\215/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\255\246\345\212\237\347\247\230\347\261\215/solution.cpp" index e69de29bb..19d26fd39 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\255\246\345\212\237\347\247\230\347\261\215/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\255\246\345\212\237\347\247\230\347\261\215/solution.cpp" @@ -0,0 +1,15 @@ +#include +using namespace std; +int main() +{ + int m, n, a; + while (cin >> n >> m) + { + a = m - n + 2; + a = a / 2; + if (n % 2 != 0 && m % 2 == 0) + a++; + cout << a << endl; + } + return 0; +} \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\262\271\346\274\206\351\235\242\347\247\257/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\262\271\346\274\206\351\235\242\347\247\257/desc.md" index e69de29bb..55047f273 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\262\271\346\274\206\351\235\242\347\247\257/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\262\271\346\274\206\351\235\242\347\247\257/desc.md" @@ -0,0 +1,41 @@ +#### 问题描述 +X星球的一批考古机器人正在一片废墟上考古。 +该区域的地面坚硬如石、平整如镜。 +管理人员为方便,建立了标准的直角坐标系。 +每个机器人都各有特长、身怀绝技。它们感兴趣的内容也不相同。 +经过各种测量,每个机器人都会报告一个或多个矩形区域,作为优先考古的区域。 +矩形的表示格式为(x1,y1,x2,y2),代表矩形的两个对角点坐标。 +为了醒目,总部要求对所有机器人选中的矩形区域涂黄色油漆。 +小明并不需要当油漆工,只是他需要计算一下,一共要耗费多少油漆。 +其实这也不难,只要算出所有矩形覆盖的区域一共有多大面积就可以了。 +注意,各个矩形间可能重叠。 +本题的输入为若干矩形,要求输出其覆盖的总面积。 +   +#### 输入格式 +第一行,一个整数n,表示有多少个矩形(1<=n<10000) +接下来的n行,每行有4个整数x1 y1 x2 y2,空格分开,表示矩形的两个对角顶点坐标。 +(0<= x1,y1,x2,y2 <=10000) +#### 输出格式 +一行一个整数,表示矩形覆盖的总面积面积。 +#### 样例输入 +``` +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 +``` \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\262\271\346\274\206\351\235\242\347\247\257/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\262\271\346\274\206\351\235\242\347\247\257/solution.cpp" index e69de29bb..bea50b58d 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\262\271\346\274\206\351\235\242\347\247\257/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\262\271\346\274\206\351\235\242\347\247\257/solution.cpp" @@ -0,0 +1,38 @@ +#include +#include +using namespace std; +bool a[10005][10005]; //记录一个点是否被油漆涂过 +int sum; + +void paint(int x1, int y1, int x2, int y2) +{ + for (int i = x1; i < x2; i++) + { + for (int j = y1; j < y2; j++) + { + a[i][j] = 1; //涂上颜色 + } + } +} + +int main() +{ + int n; + cin >> n; + for (int i = 0; i < n; i++) + { + int x1, x2, y1, y2; + scanf("%d%d%d%d", &x1, &y1, &x2, &y2); + paint(x1, y1, x2, y2); + } + for (int i = 0; i < 10005; i++) + { + for (int j = 0; j < 10005; j++) + { + if (a[i][j]) + sum++; //面积增加 + } + } + printf("%d\n", sum); + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\266\210\351\231\244\345\260\276\344\270\200/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\266\210\351\231\244\345\260\276\344\270\200/desc.md" index e69de29bb..143a9ba22 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\266\210\351\231\244\345\260\276\344\270\200/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\266\210\351\231\244\345\260\276\344\270\200/desc.md" @@ -0,0 +1,18 @@ +下面的代码把一个整数的二进制表示的最右边的连续的1全部变成0 +如果最后一位是0,则原数字保持不变。 +#### 输入: +``` +00000000000000000000000001100111 +``` +#### 输出: +``` +00000000000000000000000001100000 +``` +#### 输入: +``` +00000000000000000000000000001100 +``` +#### 输出: +``` +00000000000000000000000000001100 +``` \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\266\210\351\231\244\345\260\276\344\270\200/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\266\210\351\231\244\345\260\276\344\270\200/solution.cpp" index e69de29bb..06e728c9b 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\266\210\351\231\244\345\260\276\344\270\200/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\266\210\351\231\244\345\260\276\344\270\200/solution.cpp" @@ -0,0 +1,22 @@ +#include + +void f(int x) +{ + int i; + for (i = 0; i < 32; i++) + printf("%d", (x >> (31 - i)) & 1); + printf(" "); + + x = x & (x + 1); + + for (i = 0; i < 32; i++) + printf("%d", (x >> (31 - i)) & 1); + printf("\n"); +} + +int main() +{ + f(103); + f(12); + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\201\265\350\203\275\344\274\240\350\276\223/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\201\265\350\203\275\344\274\240\350\276\223/desc.md" index e69de29bb..bf46c8619 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\201\265\350\203\275\344\274\240\350\276\223/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\201\265\350\203\275\344\274\240\350\276\223/desc.md" @@ -0,0 +1,53 @@ +#### 题目背景 +在游戏《星际争霸 II》中,高阶圣堂武士作为星灵的重要 AOE 单位,在游戏的中后期发挥着重要的作用,其技能”灵能风暴“可以消耗大量的灵能对一片区域内的敌军造成毁灭性的伤害。经常用于对抗人类的生化部队和虫族的 +刺蛇飞龙等低血量单位。 +#### 问题描述 +你控制着 n 名高阶圣堂武士,方便起见标为 1,2,··· ,n。每名高阶圣堂武士需要一定的灵能来战斗,每个人有一个灵能值$a_i$表示其拥有的灵能的多少($a_i$非负表示这名高阶圣堂武士比在最佳状态下多余了$a_i$点灵能,$a_i$为负则表示这名高阶圣堂武士还需要$-a_i$点灵能才能到达最佳战斗状态) 。现在系统赋予了你的高阶圣堂武士一个能力,传递灵能,每次你可以选择一个$ i ∈ [2,n − 1]$,若$a_i ≥ 0 $则其两旁的高阶圣堂武士,也就是$ i − 1、i + 1 $这两名高阶圣堂武士会从i 这名高阶圣堂武士这里各抽取$ a_i $点灵能;若$ a_i < 0 $则其两旁的高阶圣堂武士,也就是$ i−1,i+1 $这两名高阶圣堂武士会给 i 这名高阶圣堂武士$ −a_i $点灵能。形式化来讲就是$ a_{i-1} + = a_i ,a_{i+1} + = a_i ,a_i − = 2a_i $。 + +灵能是非常高效的作战工具,同时也非常危险且不稳定,一位高阶圣堂武士拥有的灵能过多或者过少都不好,定义一组高阶圣堂武士的不稳定度为$max^n_{i=1} |a_i|$,请你通过不限次数的传递灵能操作使得你控制的这一组高阶圣堂武士的不稳定度最小。 +#### 输入格式 +本题包含多组询问。输入的第一行包含一个正整数 T 表示询问组数。 +接下来依次输入每一组询问。 +每组询问的第一行包含一个正整数 n,表示高阶圣堂武士的数量。 +接下来一行包含 n 个数 $a_1 ,a_2 ,··· ,a_n $。 +#### 输出格式 +输出 T 行。每行一个整数依次表示每组询问的答案。 +#### 样例输入 +``` +3 +3 +5 -2 3 +4 +0 0 0 0 +3 +1 2 3 +``` +#### 样例输出 +``` +3 +0 +3 +``` +#### 样例说明 +``` +对于第一组询问: +对 2 号高阶圣堂武士进行传输操作后 a 1 = 3,a 2 = 2,a 3 = 1。答案为 3。 +对于第二组询问: +这一组高阶圣堂武士拥有的灵能都正好可以让他们达到最佳战斗状态。 +``` +#### 样例输入 +``` +3 +4 +-1 -2 -3 7 +4 +2 3 4 -8 +5 +-1 -1 6 -1 -1 +``` +#### 样例输出 +``` +5 +7 +4 +``` \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\201\265\350\203\275\344\274\240\350\276\223/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\201\265\350\203\275\344\274\240\350\276\223/solution.cpp" index e69de29bb..1476be2d2 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\201\265\350\203\275\344\274\240\350\276\223/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\201\265\350\203\275\344\274\240\350\276\223/solution.cpp" @@ -0,0 +1,67 @@ +#include +#include +#include +#include + +using namespace std; + +typedef long long LL; +const int N = 300010; + +int n; +LL sum[N], a[N], s0, sn; +bool st[N]; + +int main() +{ + int T; + scanf("%d", &T); + while (T--) + { + scanf("%d", &n); + sum[0] = 0; + for (int i = 1; i <= n; i++) + { + scanf("%lld", &sum[i]); + sum[i] += sum[i - 1]; + } + s0 = sum[0], sn = sum[n]; + if (s0 > sn) + swap(s0, sn); + sort(sum, sum + n + 1); + for (int i = 0; i <= n; i++) + if (s0 == sum[i]) + { + s0 = i; + break; + } + for (int i = n; i >= 0; i--) + if (sn == sum[i]) + { + sn = i; + break; + } + memset(st, 0, sizeof st); + int l = 0, r = n; + for (int i = s0; i >= 0; i -= 2) + { + a[l++] = sum[i]; + st[i] = true; + } + for (int i = sn; i <= n; i += 2) + { + a[r--] = sum[i]; + st[i] = true; + } + for (int i = 0; i <= n; i++) + if (!st[i]) + { + a[l++] = sum[i]; + } + LL res = 0; + for (int i = 1; i <= n; i++) + res = max(res, abs(a[i] - a[i - 1])); + printf("%d\n", res); + } + return 0; +} \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\201\276\345\220\216\351\207\215\345\273\272/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\201\276\345\220\216\351\207\215\345\273\272/desc.md" index e69de29bb..8ea3a6116 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\201\276\345\220\216\351\207\215\345\273\272/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\201\276\345\220\216\351\207\215\345\273\272/desc.md" @@ -0,0 +1,44 @@ +#### 问题描述: +Pear市一共有N(<=50000)个居民点,居民点之间有M(<=200000)条双向道路相连。这些居民点两两之间都可以通过双向道路到达。这种情况一直持续到最近,一次严重的地震毁坏了全部M条道路。 +震后,Pear打算修复其中一些道路,修理第i条道路需要Pi的时间。不过,Pear并不打算让全部的点连通,而是选择一些标号特殊的点让他们连通。 +Pear有Q(<=50000)次询问,每次询问,他会选择所有编号在[l,r]之间,并且 编号 mod K = C 的点,修理一些路使得它们连通。由于所有道路的修理可以同时开工,所以完成修理的时间取决于花费时间最长的一条路,即涉及到的道路中Pi的最大值。 +你能帮助Pear计算出每次询问时需要花费的最少时间么?这里询问是独立的,也就是上一个询问里的修理计划并没有付诸行动。 + +#### 输入格式 +第一行三个正整数N、M、Q,含义如题面所述。 +接下来M行,每行三个正整数Xi、Yi、Pi,表示一条连接Xi和Yi的双向道路,修复需要Pi的时间。可能有自环,可能有重边。1<=Pi<=1000000。 + +接下来Q行,每行四个正整数Li、Ri、Ki、Ci,表示这次询问的点是[Li,Ri]区间中所有编号Mod Ki=Ci的点。保证参与询问的点至少有两个。 + +#### 输出格式 +输出Q行,每行一个正整数表示对应询问的答案。 + +#### 样例输入 +``` +7 10 4 +1 3 10 +2 6 9 +4 1 5 +3 7 4 +3 6 9 +1 5 8 +2 7 4 +3 2 10 +1 7 6 +7 6 9 +1 7 1 0 +1 7 3 1 +2 5 1 0 +3 7 2 1 +``` +#### 样例输出 +``` +9 +6 +8 +8 +``` +#### 数据范围 +对于20%的数据,N,M,Q<=30 +对于40%的数据,N,M,Q<=2000 +对于100%的数据,N<=50000,M<=2*10^5,Q<=50000. Pi<=10^6. Li,Ri,Ki均在[1,N]范围内,Ci在[0,对应询问的Ki)范围内。 diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\201\276\345\220\216\351\207\215\345\273\272/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\201\276\345\220\216\351\207\215\345\273\272/solution.cpp" index e69de29bb..6e75e73af 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\201\276\345\220\216\351\207\215\345\273\272/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\201\276\345\220\216\351\207\215\345\273\272/solution.cpp" @@ -0,0 +1,114 @@ +#include +using namespace std; + +int N, M, Q; +const int maxM = 2e5; +const int maxN = 5e4 + 5; +int par[maxN]; + +//定义边 +struct edge +{ + int begin, end, cost; +} edges[maxM]; + +bool cmp(edge x, edge y) +{ + return x.cost < y.cost; +} + +//并查集 +int get_root(int a) +{ //求根节点 + if (par[a] != a) + { + par[a] = get_root(par[a]); + } + return par[a]; +} + +//查询是否在同一集合中 +bool query(int a, int b) +{ + return get_root(a) == get_root(b); +} + +//合并两个结点 +void merge(int a, int b) +{ + par[get_root(a)] = get_root(b); +} + +//每次询问都要初始化 +void init() +{ + for (int i = 1; i <= N; i++) + { + par[i] = i; + } +} + +int solve(int l, int r, int k, int c) +{ + init(); + for (int i = 0; i < M; i++) + { + int begin = edges[i].begin; + int end = edges[i].end; + int cost = edges[i].cost; + + if (get_root(begin) == get_root(end)) + { //该边的两个结点已经在同一个集合中 + continue; + } + else + { + merge(begin, end); //合并加边 + } + //每添加一条边都要判断一下已经满足条件,是就退出 + bool flag = true; + int parent = 0; + //检查l到r中模k余c的点是否已经连通 + for (int i = l; i <= r; i++) + { + if (i % k == c) + { + if (parent == 0) + { + parent = get_root(i); + } + else + { + if (parent != get_root(i)) + { //实际上就是检查这些结点是不是在同一个集合里 + flag = false; + break; + } + } + } + } + if (flag) + { + cout << cost << endl; //已经在同一个集合,说明已经连通 + break; + } + } + return 1; +} + +int main() +{ + cin >> N >> M >> Q; + for (int i = 0; i < M; i++) + { + cin >> edges[i].begin >> edges[i].end >> edges[i].cost; + } + sort(edges, edges + M, cmp); //边从小到大排序 + for (int i = 0; i < Q; i++) + { + int l, r, k, c; + cin >> l >> r >> k >> c; + solve(l, r, k, c); + } + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\205\244\347\220\203\346\225\260\347\233\256/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\205\244\347\220\203\346\225\260\347\233\256/desc.md" index e69de29bb..776547068 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\205\244\347\220\203\346\225\260\347\233\256/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\205\244\347\220\203\346\225\260\347\233\256/desc.md" @@ -0,0 +1,7 @@ +有一堆煤球,堆成三角棱锥形。具体: +第一层放1个, +第二层3个(排列成三角形), +第三层6个(排列成三角形), +第四层10个(排列成三角形), +.... +如果一共有100层,共有多少个煤球? \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\205\244\347\220\203\346\225\260\347\233\256/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\205\244\347\220\203\346\225\260\347\233\256/solution.cpp" index e69de29bb..e5a726d21 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\205\244\347\220\203\346\225\260\347\233\256/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\205\244\347\220\203\346\225\260\347\233\256/solution.cpp" @@ -0,0 +1,17 @@ +#include +#include +#include +using namespace std; +int main() +{ + int i, j; + long long int sum = 0; + for (i = 1; i <= 100; i++) + { + int num = 0; + for (j = 1; j <= i; j++) + num += j; + sum += num; + } + printf("%lld\n", sum); +} \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\206\212\346\200\252\345\220\203\346\240\270\346\241\203/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\206\212\346\200\252\345\220\203\346\240\270\346\241\203/desc.md" index e69de29bb..61b309032 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\206\212\346\200\252\345\220\203\346\240\270\346\241\203/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\206\212\346\200\252\345\220\203\346\240\270\346\241\203/desc.md" @@ -0,0 +1,3 @@ +森林里有一只熊怪,很爱吃核桃。不过它有个习惯,每次都把找到的核桃分成相等的两份,吃掉一份,留一份。 +如果不能等分,熊怪就会扔掉一个核桃再分。第二天再继续这个过程,直到最后剩一个核桃了,直接丢掉。 +有一天,熊怪发现了1543个核桃,请问,它在吃这些核桃的过程中,一共要丢掉多少个核桃? \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\206\212\346\200\252\345\220\203\346\240\270\346\241\203/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\206\212\346\200\252\345\220\203\346\240\270\346\241\203/solution.cpp" index e69de29bb..f8bf7e742 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\206\212\346\200\252\345\220\203\346\240\270\346\241\203/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\206\212\346\200\252\345\220\203\346\240\270\346\241\203/solution.cpp" @@ -0,0 +1,19 @@ +#include +using namespace std; +int main() +{ + int n = 1543, cnt = 0; + while (n) + { + if (n & 1) + { + n--; + cnt++; + n /= 2; + } + else + n /= 2; + } + cout << cnt << endl; + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\211\214\345\236\213\347\247\215\346\225\260/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\211\214\345\236\213\347\247\215\346\225\260/desc.md" index e69de29bb..ddf552151 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\211\214\345\236\213\347\247\215\346\225\260/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\211\214\345\236\213\347\247\215\346\225\260/desc.md" @@ -0,0 +1,6 @@ + +小明被劫持到X赌城,被迫与其他3人玩牌。 +一副扑克牌(去掉大小王牌,共52张),均匀发给4个人,每个人13张。 +这时,小明脑子里突然冒出一个问题: +如果不考虑花色,只考虑点数,也不考虑自己得到的牌的先后顺序,自己手里能拿到的初始牌型组合一共有多少种呢? + diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\211\214\345\236\213\347\247\215\346\225\260/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\211\214\345\236\213\347\247\215\346\225\260/solution.cpp" index e69de29bb..5427d3753 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\211\214\345\236\213\347\247\215\346\225\260/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\211\214\345\236\213\347\247\215\346\225\260/solution.cpp" @@ -0,0 +1,33 @@ +#include +using namespace std; + +int cnt, sum; //cnt是方案数,sum为小明当前手牌数 + +void dfs(int u) +{ //u是当前牌的种类 + if (sum > 13 || u > 13) + return; //如果手牌数超过13张 或 牌的点数大于13 则返回 + + if (sum == 13) + { //如果手牌数刚好够13张,说明刚好满足一组方案,cnt++并且返回上一层 + cnt++; + return; + } + + for (int i = 0; i <= 4; i++) + { //对于每个牌种,可以有五种选择,不拿或者拿1~4张 + sum += i; //对于每种选择 累加到小明的 手牌数当中 + dfs(u + 1); //对于他的每种选择都往下搜索,直到不能再往下走为止 + sum -= i; //每次回溯的时候,都需要把他刚才的选择给撤回 + } +} + +int main() +{ + + dfs(0); //初始状态为0 当第一次进入dfs时候,第一个for循环里面是dfs(1) 此时代表的是 对牌种1的五种选择进行 dfs + + cout << cnt << endl; + + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\211\271\345\210\253\346\225\260\347\232\204\345\222\214/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\211\271\345\210\253\346\225\260\347\232\204\345\222\214/desc.md" index e69de29bb..c0b7aee13 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\211\271\345\210\253\346\225\260\347\232\204\345\222\214/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\211\271\345\210\253\346\225\260\347\232\204\345\222\214/desc.md" @@ -0,0 +1,23 @@ +#### 题目描述 +小明对数位中含有 2、0、1、9 的数字很感兴趣(不包括前导 0),在 1 到 40 中这样的数包括 1、2、9、10 至 32、39 和 40,共 28 个,他们的和是 574。 + +请问,在 1 到 n 中,所有这样的数的和是多少? + +#### 输入格式 +共一行,包含一个整数 n。 + +#### 输出格式 +共一行,包含一个整数,表示满足条件的数的和。 + +#### 数据范围 +``` +1≤n≤10000 +``` +#### 输入样例: +``` +40 +``` +#### 输出样例: +``` +574 +``` diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\211\271\345\210\253\346\225\260\347\232\204\345\222\214/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\211\271\345\210\253\346\225\260\347\232\204\345\222\214/solution.cpp" index e69de29bb..513a18061 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\211\271\345\210\253\346\225\260\347\232\204\345\222\214/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\211\271\345\210\253\346\225\260\347\232\204\345\222\214/solution.cpp" @@ -0,0 +1,32 @@ +#include + +using namespace std; + +int ans, n; + +bool check(int n) +{ + while (n) + { + int tmpn = n % 10; + if (tmpn == 2 || tmpn == 0 || tmpn == 1 || tmpn == 9) + return true; + n /= 10; + } + return false; +} + +int main() +{ + cin >> n; + + for (int i = 1; i <= n; i++) + { + if (check(i)) + ans += i; + } + + cout << ans << endl; + + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\214\264\345\255\220\345\210\206\351\246\231\350\225\211/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\214\264\345\255\220\345\210\206\351\246\231\350\225\211/desc.md" index e69de29bb..0dc802ae0 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\214\264\345\255\220\345\210\206\351\246\231\350\225\211/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\214\264\345\255\220\345\210\206\351\246\231\350\225\211/desc.md" @@ -0,0 +1,8 @@ +5只猴子是好朋友,在海边的椰子树上睡着了。这期间,有商船把一大堆香蕉忘记在沙滩上离去。 +第1只猴子醒来,把香蕉均分成5堆,还剩下1个,就吃掉并把自己的一份藏起来继续睡觉。 +第2只猴子醒来,重新把香蕉均分成5堆,还剩下2个,就吃掉并把自己的一份藏起来继续睡觉。 +第3只猴子醒来,重新把香蕉均分成5堆,还剩下3个,就吃掉并把自己的一份藏起来继续睡觉。 +第4只猴子醒来,重新把香蕉均分成5堆,还剩下4个,就吃掉并把自己的一份藏起来继续睡觉。 +第5只猴子醒来,重新把香蕉均分成5堆,哈哈,正好不剩! +请计算一开始最少有多少个香蕉。 + \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\214\264\345\255\220\345\210\206\351\246\231\350\225\211/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\214\264\345\255\220\345\210\206\351\246\231\350\225\211/solution.cpp" index e69de29bb..c7729debc 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\214\264\345\255\220\345\210\206\351\246\231\350\225\211/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\214\264\345\255\220\345\210\206\351\246\231\350\225\211/solution.cpp" @@ -0,0 +1,32 @@ +#include +#include +using namespace std; + +int main() +{ + for (int i = 6; i < INT_MAX; i++) + { + if ((i - 1) % 5 != 0) + continue; + int m = i; + m -= 1; //吃掉一个 + m = m / 5 * 4; + if (m <= 0 || (m - 2) % 5 != 0) + continue; + m -= 2; + m = m / 5 * 4; + if (m <= 0 || (m - 3) % 5 != 0) + continue; + m -= 3; + m = m / 5 * 4; + if (m <= 0 || (m - 4) % 5 != 0) + continue; + m -= 4; + m = m / 5 * 4; + if (m <= 0 || m % 5 != 0) + continue; + cout << i << endl; + break; + } + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\224\237\345\221\275\344\271\213\346\240\221/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\224\237\345\221\275\344\271\213\346\240\221/desc.md" index e69de29bb..e8bbc9c16 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\224\237\345\221\275\344\271\213\346\240\221/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\224\237\345\221\275\344\271\213\346\240\221/desc.md" @@ -0,0 +1,48 @@ +在X森林里,上帝创建了生命之树。 + +他给每棵树的每个节点(叶子也称为一个节点)上,都标了一个整数,代表这个点的和谐值。 + +上帝要在这棵树内选出一个非空节点集 S,使得对于 S 中的任意两个点 a,b都存在一个点列 {a,v1,v2,…,vk,b} 使得这个点列中的每个点都是 S 里面的元素,且序列中相邻两个点间有一条边相连。 + +在这个前提下,上帝要使得 S 中的点所对应的整数的和尽量大。 + +这个最大的和就是上帝给生命之树的评分。 + +经过 atm 的努力,他已经知道了上帝给每棵树上每个节点上的整数。 + +但是由于 atm 不擅长计算,他不知道怎样有效的求评分。 + +他需要你为他写一个程序来计算一棵树的分数。 + +#### 输入格式 +第一行一个整数 n 表示这棵树有 n 个节点。 + +第二行 n 个整数,依次表示每个节点的评分。 + +接下来 n−1 行,每行 2 个整数 u,v,表示存在一条 u 到 v 的边。 + +由于这是一棵树,所以是不存在环的。 + +树的节点编号从 1 到 n。 + +#### 输出格式 +输出一行一个数,表示上帝给这棵树的分数。 + +#### 数据范围 +``` +1≤n≤105, +每个节点的评分的绝对值均不超过 10的6次方。 +``` +#### 输入样例: +``` +5 +1 -2 -3 4 5 +4 2 +3 1 +1 2 +2 5 +``` +#### 输出样例: +``` +8 +``` \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\224\237\345\221\275\344\271\213\346\240\221/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\224\237\345\221\275\344\271\213\346\240\221/solution.cpp" index e69de29bb..2ae81e8c2 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\224\237\345\221\275\344\271\213\346\240\221/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\224\237\345\221\275\344\271\213\346\240\221/solution.cpp" @@ -0,0 +1,42 @@ +#include +using namespace std; +const int N = 100010; +typedef long long LL; //可能爆出int +vector> v(100010); +int happy[N]; +LL f[N]; +bool st[N]; +void dfs(int u) +{ //以u为根的子树值 + f[u] = happy[u]; + st[u] = true; + for (int i = 0; i < v[u].size(); i++) + { + int j = v[u][i]; + if (st[j] == false) + { //不能重复搜 + dfs(j); //递归求下面的值 + f[u] += max(0ll, f[j]); //f[j]可能为负数 + } + } +} +int main() +{ + int n; + cin >> n; + for (int i = 1; i <= n; i++) + cin >> happy[i]; + for (int i = 0; i < n - 1; i++) + { + int a, b; + scanf("%d%d", &a, &b); + v[b].push_back(a); + v[a].push_back(b); + } + dfs(1); + LL res = f[1]; + //注意取个最大值 + for (int i = 2; i <= n; i++) + res = max(res, f[i]); + printf("%lld\n", res); +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\224\237\346\227\245\350\234\241\347\203\233/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\224\237\346\227\245\350\234\241\347\203\233/desc.md" index e69de29bb..740ebb02b 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\224\237\346\227\245\350\234\241\347\203\233/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\224\237\346\227\245\350\234\241\347\203\233/desc.md" @@ -0,0 +1,2 @@ +某君从某年开始每年都举办一次生日party,并且每次都要吹熄与年龄相同根数的蜡烛。 现在算起来,他一吹熄了236根蜡烛。 +请问,他从多少岁开始过生日party的? \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\224\237\346\227\245\350\234\241\347\203\233/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\224\237\346\227\245\350\234\241\347\203\233/solution.cpp" index e69de29bb..ebd489c7d 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\224\237\346\227\245\350\234\241\347\203\233/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\224\237\346\227\245\350\234\241\347\203\233/solution.cpp" @@ -0,0 +1,16 @@ +#include +using namespace std; +int main() +{ + for (int i = 1; i <= 50; i++) + { + for (int j = 50; j >= i; j--) + { + if ((i + j) * (j - i + 1) == 472) + { + cout << i << " " << j << endl; + } + } + } + return 0; +} \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\237\251\351\230\265/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\237\251\351\230\265/desc.md" index e69de29bb..734d19c6b 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\237\251\351\230\265/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\237\251\351\230\265/desc.md" @@ -0,0 +1,5 @@ +把 1 ∼ 2020 放在 2 × 1010 的矩阵里。 + +要求同一行中右边的比左边大,同一列中下边的比上边的大。一共有多少种方案? + +答案很大,你只需要给出方案数除以 2020 的余数即可。 \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\237\251\351\230\265/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\237\251\351\230\265/solution.cpp" index e69de29bb..27251c195 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\237\251\351\230\265/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\237\251\351\230\265/solution.cpp" @@ -0,0 +1,21 @@ +#include +int DP[1011][1011]; +int main() +{ + int i, j; + DP[1][0] = 1; + for (i = 1; i <= 1010; i++) + DP[i][0] = 1; //初始化 + for (i = 1; i <= 1010; i++) + { + for (j = 1; j <= i; j++) + { + if (i == j) + DP[i][j] = DP[i][j - 1]; + else + DP[i][j] = (DP[i - 1][j] + DP[i][j - 1]) % 2020; + } + } + printf("%d", DP[1010][1010]); + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\237\251\351\230\265\347\277\273\347\241\254\345\270\201/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\237\251\351\230\265\347\277\273\347\241\254\345\270\201/desc.md" index e69de29bb..2f931d481 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\237\251\351\230\265\347\277\273\347\241\254\345\270\201/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\237\251\351\230\265\347\277\273\347\241\254\345\270\201/desc.md" @@ -0,0 +1,25 @@ +#### 问题描述 +小明先把硬币摆成了一个 n 行 m 列的矩阵。 +随后,小明对每一个硬币分别进行一次 Q 操作。 +对第x行第y列的硬币进行 Q 操作的定义:将所有第 $i*x$ 行,第 $j*y$ 列的硬币进行翻转。 +其中i和j为任意使操作可行的正整数,行号和列号都是从1开始。 +当小明对所有硬币都进行了一次 Q 操作后,他发现了一个奇迹——所有硬币均为正面朝上。 +小明想知道最开始有多少枚硬币是反面朝上的。于是,他向他的好朋友小M寻求帮助。 +聪明的小M告诉小明,只需要对所有硬币再进行一次Q操作,即可恢复到最开始的状态。然而小明很懒,不愿意做。于是小明希望你给出他更好的方法。帮他计算出答案。 +#### 输入格式 +输入数据包含一行,两个正整数 n m,含义见题目描述。 +#### 输出格式 +输出一个正整数,表示最开始有多少枚硬币是反面朝上的。 +#### 样例输入 +``` +2 3 +``` +#### 样例输出 +``` +1 +``` +#### 数据规模和约定 +对于10%的数据,n、m <= 10^3; +对于20%的数据,n、m <= 10^7; +对于40%的数据,n、m <= 10^15; +对于10%的数据,n、m <= 10^1000(10的1000次方)。 \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\237\251\351\230\265\347\277\273\347\241\254\345\270\201/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\237\251\351\230\265\347\277\273\347\241\254\345\270\201/solution.cpp" index e69de29bb..8050e1cce 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\237\251\351\230\265\347\277\273\347\241\254\345\270\201/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\237\251\351\230\265\347\277\273\347\241\254\345\270\201/solution.cpp" @@ -0,0 +1,117 @@ +#include +#include +using namespace std; + +//两个字符串相乘 +string strMultiply(string str1, string str2) +{ + string strResult = ""; + int len1 = str1.length(); + int len2 = str2.length(); + int num[500] = {0}; + int i = 0, j = 0; + for (i = 0; i < len1; i++) + { + for (j = 0; j < len2; j++) + { + num[len1 - 1 - i + len2 - 1 - j] += (str1[i] - '0') * (str2[j] - '0'); + } + } + + for (i = 0; i < len1 + len2; i++) + { + num[i + 1] += num[i] / 10; + + num[i] = num[i] % 10; + } + + for (i = len1 + len2 - 1; i >= 0; i--) + { + if (0 != num[i]) + break; + } + + for (j = i; j >= 0; j--) + { + strResult += num[j] + '0'; + } + return strResult; +} + +//str1 * 10^pos后(即在str1后添上pos个0),与str2作比较 +int compare(string str1, string str2, int pos) +{ + int len1 = str1.length(); + int len2 = str2.length(); + if (len2 > len1 + pos) + return 0; + if (len2 < len1 + pos) + return 1; + int i = 0; + for (i = 0; i < len2; i++) + { + if (str1[i] - '0' > str2[i] - '0') + return 1; + if (str1[i] - '0' < str2[i] - '0') + return 0; + } + return 0; +} + +//对大数str开方取整 +string sqrtLarge(string str) +{ + int len = str.length(); + int i = 0; + int j = 0; + string strResult = ""; + string str1 = ""; + if (0 == len % 2) + { //为偶数位 + for (i = 0; i < len / 2; i++) + { + for (j = 0; j < 10; j++) + { + str1 = strResult; + str1 += j + '0'; + if (1 == compare(strMultiply(str1, str1), str, 2 * (len / 2 - i - 1))) + { //由于str1后少了len/2-i-1个0,所以平方以后少了2*(len/2-i-1)个 + strResult += j - 1 + '0'; + break; + } + if (9 == j) + strResult += '9'; + } + } + } + else + { //为奇数位 + for (i = 0; i < len / 2 + 1; i++) + { + for (j = 0; j < 10; j++) + { + str1 = strResult; + str1 += j + '0'; + if (1 == compare(strMultiply(str1, str1), str, 2 * (len / 2 - i))) + { + strResult += j - 1 + '0'; + break; + } + if (9 == j) + strResult += '9'; + } + } + } + return strResult; +} +int main() +{ + string str1; + string str2; + string strResult; + cin >> str1 >> str2; + + cout << strMultiply(sqrtLarge(str1), sqrtLarge(str2)) << endl; + + return 0; +} \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\245\236\345\245\207\347\256\227\345\274\217/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\245\236\345\245\207\347\256\227\345\274\217/desc.md" index e69de29bb..3055ccecb 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\245\236\345\245\207\347\256\227\345\274\217/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\245\236\345\245\207\347\256\227\345\274\217/desc.md" @@ -0,0 +1,9 @@ +由4个不同的数字,组成的一个乘法算式,它们的乘积仍然由这4个数字组成。 +比如: +``` +210 x 6 = 1260 +8 x 473 = 3784 +27 x 81 = 2187 +``` +都符合要求。 +如果满足乘法交换律的算式算作同一种情况,那么,包含上边已列出的3种情况,一共有多少种满足要求的算式。 diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\245\236\345\245\207\347\256\227\345\274\217/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\245\236\345\245\207\347\256\227\345\274\217/solution.cpp" index e69de29bb..e1f1ba349 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\245\236\345\245\207\347\256\227\345\274\217/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\245\236\345\245\207\347\256\227\345\274\217/solution.cpp" @@ -0,0 +1,106 @@ +#include +#define MAX_N 1005 +using namespace std; + +bool judge1(int n) //判断两个数的乘积是否为4位数 +{ + int ans = 0; + while (n) + { + ans++; + n /= 10; + } + if (ans == 4) + return true; + return false; +} + +bool judge2(int i, int j) //判断乘积的数是否为原来的四个数 +{ + int s1 = 0, s2 = 0; //和 + int ss1 = 1, ss2 = 1; //积 + int tmp = i * j; + bool flag1 = true, flag2 = true; + while (tmp) + { + s1 += tmp % 10; + if (tmp % 10 == 0) + flag1 = false; + else + ss1 *= tmp % 10; + tmp /= 10; + } + while (j) + { + s2 += j % 10; + if (j % 10 != 0) + ss2 *= j % 10; + else + flag2 = false; + j /= 10; + } + while (i) + { + s2 += i % 10; + if (i % 10 != 0) + ss2 *= i % 10; + else + flag2 = false; + i /= 10; + } + if (s1 == s2 && ss1 == ss2 && flag1 && flag2) //如果没有0的话,是否乘积和和都相等 + return true; + else if ((!flag1 && !flag2) && s1 == s2 && ss1 == ss2) //如果有0的话,是否乘积都相等 + return true; + return false; +} + +bool judge3(int i, int j) //判断两个数中是否全是不同的数 +{ + int a[4]; + int ans = 0; + while (i) + { + a[ans] = i % 10; + i /= 10; + ans++; + } + while (j) + { + a[ans] = j % 10; + j /= 10; + ans++; + } + for (i = 0; i < 3; i++) + { + for (j = i + 1; j < 4; j++) + if (a[i] == a[j]) //如果有相等的话返回false + return false; + } + return true; +} + +int main() +{ + //freopen("data.txt","r",stdin); + int i, j; + int ans = 0; + for (i = 1; i < 10; i++) + { //一位数乘以三位数 + for (j = 123; j < 1000; j++) + { + if (judge1(i * j) && judge2(i, j) && judge3(i, j)) + ans++; + } + } + for (i = 10; i < 100; i++) + { //两位数乘以两位数 + for (j = i + 1; j < 100; j++) + { + if (judge1(i * j) && judge2(i, j) && judge3(i, j)) + ans++; + } + } + cout << ans; + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\247\273\345\212\250\350\267\235\347\246\273/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\247\273\345\212\250\350\267\235\347\246\273/desc.md" index e69de29bb..02474dba4 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\247\273\345\212\250\350\267\235\347\246\273/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\247\273\345\212\250\350\267\235\347\246\273/desc.md" @@ -0,0 +1,32 @@ +X星球居民小区的楼房全是一样的,并且按矩阵样式排列。其楼房的编号为1,2,3... +当排满一行时,从下一行相邻的楼往反方向排号。 +比如:当小区排号宽度为6时,开始情形如下: +``` +1 2 3 4 5 6 +12 11 10 9 8 7 +13 14 15 ..... +``` +我们的问题是:已知了两个楼号m和n,需要求出它们之间的最短移动距离(不能斜线方向移动) + +输入为3个整数w m n,空格分开,都在1到10000范围内 +w为排号宽度,m,n为待计算的楼号。 +要求输出一个整数,表示m n 两楼间最短移动距离。 + +例如: +#### 用户输入: +``` +6 8 2 +``` +则,程序应该输出: +``` +4 +``` +再例如: +#### 用户输入: +``` +4 7 20 +``` +则,程序应该输出: +``` +5 +``` \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\247\273\345\212\250\350\267\235\347\246\273/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\247\273\345\212\250\350\267\235\347\246\273/solution.cpp" index e69de29bb..0c4309195 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\247\273\345\212\250\350\267\235\347\246\273/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\247\273\345\212\250\350\267\235\347\246\273/solution.cpp" @@ -0,0 +1,21 @@ +#include +#include +int main() +{ + int w, m, n, x1, y1, x2, y2; + scanf("%d%d%d", &w, &m, &n); + x1 = (m - 1) / w + 1; + y1 = m % w; + if (y1 == 0) + y1 = m; + if (x1 % 2 == 0) + y1 = w + 1 - y1; + x2 = (n - 1) / w + 1; + y2 = n % w; + if (y2 == 0) + y2 = n; + if (x2 % 2 == 0) + y2 = w + 1 - y2; + printf("%d\n", abs(x1 - y1) + abs(x2 - y2)); + return 0; +} \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\253\213\346\226\271\345\217\230\350\207\252\350\272\253/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\253\213\346\226\271\345\217\230\350\207\252\350\272\253/desc.md" index e69de29bb..7d244fa70 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\253\213\346\226\271\345\217\230\350\207\252\350\272\253/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\253\213\346\226\271\345\217\230\350\207\252\350\272\253/desc.md" @@ -0,0 +1,8 @@ +观察下面的现象,某个数字的立方,按位累加仍然等于自身。 +``` +1^3 = 1 +8^3 = 512 5+1+2=8 +17^3 = 4913 4+9+1+3=17 +… +``` +请你计算包括1,8,17在内,符合这个性质的正整数一共有多少个? \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\253\213\346\226\271\345\217\230\350\207\252\350\272\253/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\253\213\346\226\271\345\217\230\350\207\252\350\272\253/solution.cpp" index e69de29bb..50c6ea1ec 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\253\213\346\226\271\345\217\230\350\207\252\350\272\253/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\253\213\346\226\271\345\217\230\350\207\252\350\272\253/solution.cpp" @@ -0,0 +1,23 @@ +#include +#include +using namespace std; +int main() +{ + + int sum = 0, ans; + for (int i = 1; i <= 1000; i++) + { + ans = 0; + double m = pow(i, 3); //pow double型 + m = (int)m; + while (m) + { + ans += (int)m % 10; + m /= 10; + } + if (ans == i) + sum++; + } + cout << sum << endl; + return 0; +} \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\254\25439\347\272\247\345\217\260\351\230\266/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\254\25439\347\272\247\345\217\260\351\230\266/desc.md" index e69de29bb..32d1740ed 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\254\25439\347\272\247\345\217\260\351\230\266/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\254\25439\347\272\247\345\217\260\351\230\266/desc.md" @@ -0,0 +1,7 @@ +小明刚刚看完电影《第39级台阶》,离开电影院的时候,他数了数礼堂前的台阶数,恰好是39级! + +站在台阶前,他突然又想着一个问题: + +如果我每一步只能迈上1个或2个台阶。先迈左脚,然后左右交替,最后一步是迈右脚,也就是说一共要走偶数步。那么,上完39级台阶,有多少种不同的上法呢? + +请你利用计算机的优势,帮助小明寻找答案。 diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\254\25439\347\272\247\345\217\260\351\230\266/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\254\25439\347\272\247\345\217\260\351\230\266/solution.cpp" index e69de29bb..d697b3661 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\254\25439\347\272\247\345\217\260\351\230\266/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\254\25439\347\272\247\345\217\260\351\230\266/solution.cpp" @@ -0,0 +1,20 @@ +#include +#define LEFT 0 +#define RIGHT 1 +using namespace std; +int stage[40][2]; +int main() +{ + int i; + stage[1][LEFT] = 1; + stage[1][RIGHT] = 0; + stage[2][LEFT] = 1; + stage[2][RIGHT] = 1; + for (i = 3; i <= 39; i++) + { + stage[i][LEFT] = stage[i - 1][RIGHT] + stage[i - 2][RIGHT]; + stage[i][RIGHT] = stage[i - 1][LEFT] + stage[i - 2][LEFT]; + } + cout << stage[39][RIGHT] << endl; + return 0; +} \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\254\254\345\207\240\344\270\252\345\271\270\350\277\220\346\225\260/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\254\254\345\207\240\344\270\252\345\271\270\350\277\220\346\225\260/desc.md" index e69de29bb..b08aeb42e 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\254\254\345\207\240\344\270\252\345\271\270\350\277\220\346\225\260/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\254\254\345\207\240\344\270\252\345\271\270\350\277\220\346\225\260/desc.md" @@ -0,0 +1,12 @@ +到x星球旅行的游客都被发给一个整数,作为游客编号。 +x星的国王有个怪癖,他只喜欢数字3,5和7。 +国王规定,游客的编号如果只含有因子:3,5,7,就可以获得一份奖品。 + +我们来看前10个幸运数字是: +3 5 7 9 15 21 25 27 35 45 +因而第11个幸运数字是:49 + +小明领到了一个幸运数字 59084709587505,他去领奖的时候,人家要求他准确地说出这是第几个幸运数字,否则领不到奖品。 + +请你帮小明计算一下,59084709587505是第几个幸运数字。 + diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\254\254\345\207\240\344\270\252\345\271\270\350\277\220\346\225\260/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\254\254\345\207\240\344\270\252\345\271\270\350\277\220\346\225\260/solution.cpp" index e69de29bb..12b7b1c88 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\254\254\345\207\240\344\270\252\345\271\270\350\277\220\346\225\260/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\254\254\345\207\240\344\270\252\345\271\270\350\277\220\346\225\260/solution.cpp" @@ -0,0 +1,35 @@ +#include +#include +#include +#include +using namespace std; +int main() +{ + set st; + priority_queue, greater> pq; + const int ok[3] = {3, 5, 7}; + st.insert(1); + pq.push(1); + int times = 0; + while (true) + { + long long lucky = pq.top(); + pq.pop(); + if (lucky == 59084709587505) + { //49 + cout << times << endl; + return 0; + } + times++; + for (int i = 0; i < 3; i++) + { + long long b = lucky * ok[i]; + if (!st.count(b)) + { + st.insert(b); + pq.push(b); + } + } + } + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\254\254\345\207\240\345\244\251/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\254\254\345\207\240\345\244\251/desc.md" index e69de29bb..ad2434f35 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\254\254\345\207\240\345\244\251/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\254\254\345\207\240\345\244\251/desc.md" @@ -0,0 +1,19 @@ +y年m月d日是哪一年的第几天。 +比如y年的1月1日是那一年的第一天,那么y年m月d日是哪一年的第几天。 + +#### 输入 +``` +y m d +``` +#### 输出 +输出一个整数 + +### 样例 +#### 输入 +``` +2000 7 7 +``` +#### 输出 +``` +189 +``` diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\254\254\345\207\240\345\244\251/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\254\254\345\207\240\345\244\251/solution.cpp" index e69de29bb..bd9593605 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\254\254\345\207\240\345\244\251/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\254\254\345\207\240\345\244\251/solution.cpp" @@ -0,0 +1,32 @@ +#include +using namespace std; +bool is_leap(int year) +{ + return (year % 4 == 0 && year % 100 != 0) || year % 400 == 0; +} +int main() +{ + int y, m, d, ans = 0; + cin >> y >> m >> d; + int L_m_d[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; + int nonL_m_d[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; + + if (is_leap(y)) //判断闰年 + { + for (int i = 0; i < (m - 1); i++) //记录1-(m-1)月天数 + { + ans += L_m_d[i]; + } + ans += d; + } + else + { + for (int i = 0; i < (m - 1); i++) + { + ans += nonL_m_d[i]; + } + ans += d; + } + cout << ans << endl; + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\255\211\345\267\256\346\225\260\345\210\227/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\255\211\345\267\256\346\225\260\345\210\227/desc.md" index e69de29bb..3a9cb2b23 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\255\211\345\267\256\346\225\260\345\210\227/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\255\211\345\267\256\346\225\260\345\210\227/desc.md" @@ -0,0 +1,37 @@ +#### 题目描述 +数学老师给小明出了一道等差数列求和的题目。 + +但是粗心的小明忘记了一部分的数列,只记得其中 N 个整数。 + +现在给出这 N 个整数,小明想知道包含这 N 个整数的最短的等差数列有几项? + +#### 输入格式 +输入的第一行包含一个整数 N。 + +第二行包含 N 个整数 A1,A2,⋅⋅⋅,AN。(注意 A1∼AN 并不一定是按等差数 +列中的顺序给出) + +#### 输出格式 +输出一个整数表示答案。 + +#### 数据范围 +``` +2≤N≤100000, +0≤Ai≤109 +1 +2 +``` +#### 输入样例: +``` +5 +2 6 4 10 20 +1 +2 +``` +#### 输出样例: +``` +10 +1 +``` +#### 样例解释 +包含 2、6、4、10、20 的最短的等差数列是 2、4、6、8、10、12、14、16、18、20。 diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\255\211\345\267\256\346\225\260\345\210\227/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\255\211\345\267\256\346\225\260\345\210\227/solution.cpp" index e69de29bb..82f01d50d 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\255\211\345\267\256\346\225\260\345\210\227/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\255\211\345\267\256\346\225\260\345\210\227/solution.cpp" @@ -0,0 +1,32 @@ +#include +#include + +using namespace std; +const int N = 1e5 + 10; +int a[N]; + +int gcd(int a, int b) //辗转相除法 在两个数中求得最大公约数,当一方为0时,返回另一方。 +{ + return b ? gcd(b, a % b) : a; +} + +int main() +{ + int n; + cin >> n; + for (int i = 0; i < n; i++) + cin >> a[i]; + + sort(a, a + n); //回复等差数列正常排序 + + int d = 0; + for (int i = 1; i < n; i++) + d = gcd(d, a[i] - a[0]); //求得数列中的最大公约数,又因为辗转相除,所以gcd(a,b)中a,b任意一个为零时,可以返回另一个数,再和下一个数求最大公约数。 + + if (d) + cout << (a[n - 1] - a[0]) / d + 1; //特判d为0!即有常数个,否则出现K/d时d==0逻辑错误Float Point Exception + else + cout << n; + + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\255\211\345\267\256\347\264\240\346\225\260\345\210\227/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\255\211\345\267\256\347\264\240\346\225\260\345\210\227/desc.md" index e69de29bb..3cf2aae12 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\255\211\345\267\256\347\264\240\346\225\260\345\210\227/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\255\211\345\267\256\347\264\240\346\225\260\345\210\227/desc.md" @@ -0,0 +1,11 @@ +#### 题目描述 +2,3,5,7,11,13,....是素数序列。 +类似:7,37,67,97,127,157 这样完全由素数组成的等差数列,叫等差素数数列。 +上边的数列公差为30,长度为6。 + +2004年,格林与华人陶哲轩合作证明了:存在任意长度的素数等差数列。 +这是数论领域一项惊人的成果! + +有这一理论为基础,请你借助手中的计算机,满怀信心地搜索: + +长度为10的等差素数列,其公差最小值是多少? diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\255\211\345\267\256\347\264\240\346\225\260\345\210\227/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\255\211\345\267\256\347\264\240\346\225\260\345\210\227/solution.cpp" index e69de29bb..c861ccd0e 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\255\211\345\267\256\347\264\240\346\225\260\345\210\227/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\255\211\345\267\256\347\264\240\346\225\260\345\210\227/solution.cpp" @@ -0,0 +1,66 @@ +#include +#include +#include +using namespace std; + +typedef long long LL; +set all; + +bool isPrimt(LL t) +{ //判断是否是素数 + for (int i = 2; i < t / 2; ++i) + { + if (t % i == 0) + return false; + } + return true; +} + +int f(LL a[], int n) +{ //寻找长度为10的等差素数列 + for (int i = 0; i < n; ++i) + { //枚举首项 + LL first = a[i]; + for (int delta = 1; delta < a[n - 1] - first; ++delta) + { //枚举公差 + int m = first; + for (int j = 1; j < 10; ++j) + { //枚举个数 + m += delta; + if (all.find(m) == all.end()) + break; //m不是素数 + if (m > a[n - 1]) + break; + if (j == 9) //已经找了10项 + return delta; + } + } + } + return -1; +} +const int N = 5000; + +int main() +{ + LL a[N]; + + a[0] = 2; + a[1] = 3; + all.insert(2); + all.insert(3); + + int index = 2; + LL t = 5; + while (index < N) + { //枚举5000位素数表 + if (isPrimt(t)) + { + a[index++] = t; + all.insert(t); + } + t++; + } + + printf("%d\n", f(a, N)); + return 0; +} \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\255\211\350\205\260\344\270\211\350\247\222\345\275\242/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\255\211\350\205\260\344\270\211\350\247\222\345\275\242/desc.md" index e69de29bb..e101bad15 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\255\211\350\205\260\344\270\211\350\247\222\345\275\242/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\255\211\350\205\260\344\270\211\350\247\222\345\275\242/desc.md" @@ -0,0 +1,30 @@ +本题目要求你在控制台输出一个由数字组成的等腰三角形。具体的步骤是: + +先用1,2,3,…的自然数拼一个足够长的串 +用这个串填充三角形的三条边。从上方顶点开始,逆时针填充。 +比如,当三角形高度是8时: +![](https://img-blog.csdnimg.cn/20190203174943179.png) + +输入,一个正整数n(3 +using namespace std; +string str; +stringstream ss; +int main() +{ + int n; + cin >> n; + int x = 2 * n - 1; + for (int i = 1; i <= 1500; i++) + { //先产生1到1500的字符串 + string str1; + ss << i; + ss >> str1; + str += str1; + ss.clear(); + } + int length = 4 * n - 4; //等腰三角形周长 + for (int i = 1; i <= n; i++) + { //一共n行 + if (i != n && i != 1) + { //除了这两行其余每行都只有两个数 + for (int j = 1; j <= n + i - 1; j++) + { + if (j == n - i + 1) + { //每一行左边的那个数 + cout << str[i - 1]; + } + else if (j == 2 * n - (n - i + 1)) + { //左右下标之和为2*n + cout << str[4 * n - 4 - (i - 1)] << endl; //每一行右边的数 ,每一行左边和右边的数应该输出的序号之和为4*n-4 + } + else + { + cout << '.'; + } + } + } + else if (i == 1) + { + for (int x = 1; x <= n; x++) + { //处理最后一行,最后一行有2*n-1个字符 + if (x == n) + { + cout << '1' << endl; + } + else + { + cout << '.'; + } + } + } + else + { + for (int m = 1; m <= 2 * n - 1; m++) + { //处理最后一行,最后一行有2*n-1个字符,从str[n-1]到str[3*n-1] + cout << str[n + (m - 2)]; + } + } + } + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\263\226\346\236\234/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\263\226\346\236\234/desc.md" index e69de29bb..67ba70922 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\263\226\346\236\234/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\263\226\346\236\234/desc.md" @@ -0,0 +1,25 @@ +糖果店的老板一共有M种口味的糖果出售。为了方便描述,我们将M种口味编号1~M。 +小明希望能品尝到所有口味的糖果。遗憾的是老板并不单独出售糖果,而是K颗一包整包出售。 +幸好糖果包装上注明了其中K颗糖果的口味,所以小明可以在买之前就知道每包内的糖果口味。 +给定包糖果,请你计算小明最少买几包,就可以品尝到所有口味的糖果。 +#### 输入 +第一行包含三个整数N、M 和K。 +接下来N 行每行K 这整数$T_1,T_2,…,T_K$,代表一包糖果的口味。 +1<=N<=100,1<=M<=20,1<=K<=20,1<=$T_i$<=M。 +#### 输出 +一个整数表示答案。如果小明无法品尝所有口味,输出-1。 + +#### 样例输入 +``` +6 5 3 +1 1 2 +1 2 3 +1 1 3 +2 3 5 +5 4 2 +5 1 2 +``` +#### 样例输出 +``` +2 +``` \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\263\226\346\236\234/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\263\226\346\236\234/solution.cpp" index e69de29bb..dd24ec510 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\263\226\346\236\234/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\263\226\346\236\234/solution.cpp" @@ -0,0 +1,37 @@ +#include +using namespace std; +int dp[1 << 20]; //dp[v]表示口味为v时所需要的最少糖果包数 +int ST[100]; //100包糖果 +int main() +{ + int n, m, k; + cin >> n >> m >> k; //输入n包糖果,m个口味,每包k个口味 + int tot = (1 << m) - 1; //表示所有m种口味各种组合方式 + memset(dp, -1, sizeof dp); //初始化dp全部为-1 + for (int i = 0; i < n; i++) //依次处理n包糖果 + { + int st = 0; + for (int j = 0; j < k; j++) //依次处理每颗糖果口味 + { + int x; + cin >> x; + st |= (1 << x - 1); //把第i包的第j颗糖果加入该包的口味st中 + } + dp[st] = 1; + ST[i] = st; + } + for (int i = 0; i <= tot; i++) //遍历所有口味组合方式 + { + if (dp[i] != -1) //表示已存在得到该口味的最少糖果包数量 + { + for (int j = 0; j < n; j++) //检查给定的n包糖果 + { + int st = ST[j]; + if (dp[i | st] == -1 || dp[i | st] > dp[i] + 1) //状态转移 + dp[i | st] = dp[i] + 1; + } + } + } + cout << dp[tot]; //得到所有口味tot的最少糖果包数 + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\272\252\345\277\265\346\227\245/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\272\252\345\277\265\346\227\245/desc.md" index e69de29bb..32142165a 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\272\252\345\277\265\346\227\245/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\272\252\345\277\265\346\227\245/desc.md" @@ -0,0 +1 @@ +请问从 1921 年 7 月 23 日中午 12 时到 2020 年 7 月 1 日中午 12 时一共包含多少分钟? \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\272\252\345\277\265\346\227\245/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\272\252\345\277\265\346\227\245/solution.cpp" index e69de29bb..bfe669175 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\272\252\345\277\265\346\227\245/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\272\252\345\277\265\346\227\245/solution.cpp" @@ -0,0 +1,23 @@ +#include + +using namespace std; + +int isYear(int n) +{ + if (n % 400 == 0 || n % 4 == 0 && n % 100 != 0) + return 366; + return 365; +} + +int main() +{ + + int res = 0; + for (int i = 1922; i <= 2020; i++) + res += isYear(i); + + res -= 22; + cout << res * 60 * 24; + + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\272\270\347\211\214\344\270\211\350\247\222\345\275\242/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\272\270\347\211\214\344\270\211\350\247\222\345\275\242/desc.md" index e69de29bb..09de5a1ab 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\272\270\347\211\214\344\270\211\350\247\222\345\275\242/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\272\270\347\211\214\344\270\211\350\247\222\345\275\242/desc.md" @@ -0,0 +1,12 @@ +A,2,3,4,5,6,7,8,9 共9张纸牌排成一个正三角形(A按1计算)。要求每个边的和相等。 +下面就是一种排法 +``` + A + 9 6 + 4 8 +3 7 5 2 +``` + +这样的排法可能会有很多。 + +如果考虑旋转、镜像后相同的算同一种,一共有多少种不同的排法呢? \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\272\270\347\211\214\344\270\211\350\247\222\345\275\242/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\272\270\347\211\214\344\270\211\350\247\222\345\275\242/solution.cpp" index e69de29bb..ed9e4cc3b 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\272\270\347\211\214\344\270\211\350\247\222\345\275\242/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\272\270\347\211\214\344\270\211\350\247\222\345\275\242/solution.cpp" @@ -0,0 +1,20 @@ +#include +#define ll long long +using namespace std; +int main() +{ + int a[9] = {1, 2, 3, 4, 5, 6, 7, 8, 9}; + int res = 0; + do + { + int x1 = a[0] + a[1] + a[2] + a[3]; + int x2 = a[3] + a[4] + a[5] + a[6]; + int x3 = a[6] + a[7] + a[8] + a[0]; + if (x1 == x2 && x2 == x3) + { + res++; + } + } while (next_permutation(a, a + 9)); //全排列 + cout << res / 3 / 2 << endl; //翻转除以3,镜像除以2 + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\273\204\345\220\210\346\225\260\351\227\256\351\242\230/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\273\204\345\220\210\346\225\260\351\227\256\351\242\230/desc.md" index e69de29bb..5f32da8bb 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\273\204\345\220\210\346\225\260\351\227\256\351\242\230/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\273\204\345\220\210\346\225\260\351\227\256\351\242\230/desc.md" @@ -0,0 +1,46 @@ +#### 问题描述 +给 n, m, k, 求有多少对(i, j)满足 1 ≤ i ≤ n, 0 ≤ j ≤ min(i, m) 且$C_i^j$≡0(mod k),k 是质数。其中$C_i^j$是组合数,表示从 i 个不同的数中选出 j 个组成一个集合的方案数。 +#### 输入格式 +第一行两个数 t, k,其中 t 代表该测试点包含 t 组询问,k 的意思与上文中相同。 +接下来 t 行每行两个整数 n, m,表示一组询问。 +#### 输出格式 +输出 t 行,每行一个整数表示对应的答案。由于答案可能很大,请输出答案除以 109 + 7 的余数。 +#### 样例输入 +``` +1 2 +3 3 +``` +#### 样例输出 +``` +1 +``` +#### 样例说明 +在所有可能的情况中,只有 $C_2^1$ 是 2 的倍数。 +#### 样例输入 +``` +2 5 +4 5 +6 7 +``` +#### 样例输出 +``` +0 +7 +``` +#### 样例输入 +``` +3 23 +23333333 23333333 +233333333 233333333 +2333333333 2333333333 +``` +#### 样例输出 +``` +851883128 +959557926 +680723120 +``` +#### 数据规模和约定 +``` +对于所有评测用例,1 ≤ k ≤ 108, 1 ≤ t ≤ 105, 1 ≤ n, m ≤ 1018,且 k 是质数。评测时将使用 10 个评测用例测试你的程序 +``` \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\273\204\345\220\210\346\225\260\351\227\256\351\242\230/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\273\204\345\220\210\346\225\260\351\227\256\351\242\230/solution.cpp" index e69de29bb..bb40fb08f 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\273\204\345\220\210\346\225\260\351\227\256\351\242\230/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\273\204\345\220\210\346\225\260\351\227\256\351\242\230/solution.cpp" @@ -0,0 +1,50 @@ +#include +using namespace std; +#define modk(x) (((x) >= k) ? ((x)-k) : (x)) +const int maxn = 2005; +int c[maxn][maxn], n, m, k, T; +void init() +{ + ///预处理C(i,j) + c[0][0] = 1; + for (int i = 1; i < maxn; i++) + { + c[i][0] = 1 % k; + for (int j = 1; j <= i; j++) + { + c[i][j] = modk(c[i - 1][j] + c[i - 1][j - 1]); + } + } + ///处理C(i,j)是否为k 的倍数 + for (int i = 0; i < maxn; i++) + { + for (int j = 0; j <= i; j++) + { + if (c[i][j] == 0) + c[i][j] = 1; + else + c[i][j] = 0; + } + } + ///将二维数组C处理成区域前缀和 + for (int i = 1; i < maxn; i++) + { + int s = 0; + for (int j = 0; j < maxn; j++) + { + s += c[i][j]; + c[i][j] = c[i - 1][j] + s; + } + } +} +int main() +{ + scanf("%d%d", &T, &k); + init(); + while (T--) + { + scanf("%d%d", &n, &m); + printf("%d\n", c[n][m]); + } + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\273\204\351\230\237/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\273\204\351\230\237/desc.md" index e69de29bb..d902198fd 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\273\204\351\230\237/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\273\204\351\230\237/desc.md" @@ -0,0 +1,3 @@ +作为篮球队教练,你需要从以下名单中选出 1 号位至 5 号位各一名球员, 组成球队的首发阵容。 每位球员担任 1 号位至 5 号位时的评分如下表所示。请你计算首发阵容 1 号位至 5 号位的评分之和最大可能是多少? + +![](https://img-blog.csdnimg.cn/20200328201519748.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MzkxMDMyMA==,size_16,color_FFFFFF,t_70#pic_center) \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\273\204\351\230\237/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\273\204\351\230\237/solution.cpp" index e69de29bb..a496e560c 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\273\204\351\230\237/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\273\204\351\230\237/solution.cpp" @@ -0,0 +1,38 @@ +#include +using namespace std; + +int team[20][6]; +int max_sum; +bool st[20]; + +int max(int a, int b) { return a > b ? a : b; } + +void dfs(int u, int sum) //u当前选择团队的第几人,sum当前团队总值 +{ + if (u > 5) + { + max_sum = max(max_sum, sum); + return; + } //如果选完了,更新最大值,退出 + + for (int i = 0; i < 20; i++) //20人 + { + if (!st[i]) //如果当前人没有被选择 + { + st[i] = true; //被选 + dfs(u + 1, sum + team[i][u]); //选下一个人,队伍总值增加当前人的当前号位的值 + st[i] = false; //回溯 + } + } +} +int main() +{ + for (int i = 0; i < 20; i++) + for (int j = 0; j < 6; j++) + cin >> team[i][j]; //读队伍 + + dfs(1, 0); //从第一个人开始选,当前总和为0 + + cout << max_sum; + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\273\263\345\234\210/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\273\263\345\234\210/desc.md" index e69de29bb..8886112db 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\273\263\345\234\210/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\273\263\345\234\210/desc.md" @@ -0,0 +1,3 @@ +今有 100 根绳子,当然会有 200 个绳头。 +如果任意取绳头两两配对,把所有绳头都打结连接起来。最后会形成若干个绳圈(不考虑是否套在一起)。 +我们的问题是:请计算最后将形成多少个绳圈的概率最大? \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\273\263\345\234\210/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\273\263\345\234\210/solution.cpp" index e69de29bb..9d1f48353 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\273\263\345\234\210/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\273\263\345\234\210/solution.cpp" @@ -0,0 +1,36 @@ +#include +#define N 100 +using namespace std; + +double dp[N + 1][N + 1] = {0}; + +int main() +{ + dp[1][1] = 1; + for (int i = 2; i <= N; i++) + { + dp[i][1] = dp[i - 1][1] * (2 * i - 2) / (2 * i - 1); + dp[i][i] = dp[i - 1][i - 1] / (2 * i - 1); + } + + for (int i = 3; i <= N; i++) + { + for (int j = 2; j < i; j++) + { + dp[i][j] = dp[i - 1][j - 1] / (2 * i - 1) + dp[i - 1][j] * (2 * i - 2) / (2 * i - 1); + } + } + + int index = 0; + double maxR = 0; + for (int i = 1; i <= N; i++) + { + if (dp[N][i] > maxR) + { + index = i; + maxR = dp[N][i]; + } + } + cout << index << endl; + return 0; +} \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\275\221\345\217\213\345\271\264\351\276\204/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\275\221\345\217\213\345\271\264\351\276\204/desc.md" index e69de29bb..05f9d21e6 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\275\221\345\217\213\345\271\264\351\276\204/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\275\221\345\217\213\345\271\264\351\276\204/desc.md" @@ -0,0 +1,3 @@ +某君新认识一网友。 当问及年龄时,他的网友说: “我的年龄是个2位数,我比儿子大27岁, 如果把我的年龄的两位数字交换位置,刚好就是我儿子的年龄” +请你计算:网友的年龄一共有多少种可能情况? +提示:30岁就是其中一种可能哦. \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\275\221\345\217\213\345\271\264\351\276\204/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\275\221\345\217\213\345\271\264\351\276\204/solution.cpp" index e69de29bb..5421a20fd 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\275\221\345\217\213\345\271\264\351\276\204/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\275\221\345\217\213\345\271\264\351\276\204/solution.cpp" @@ -0,0 +1,19 @@ +#include +using namespace std; +int main() +{ + int x, y; + int count = 0; + for (int i = 27; i <= 100; i++) + { + x = i / 10; //十位数 + y = i % 10; //个位数 + if (i - (x + 10 * y) == 27) + { + cout << i << endl; + count++; + } + } + cout << count << endl; + return 0; +} \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\275\221\347\273\234\345\210\206\346\236\220/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\275\221\347\273\234\345\210\206\346\236\220/desc.md" index e69de29bb..fc78b7fe5 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\275\221\347\273\234\345\210\206\346\236\220/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\275\221\347\273\234\345\210\206\346\236\220/desc.md" @@ -0,0 +1,40 @@ +#### 问题描述 +小明正在做一个网络实验。 +他设置了 n 台电脑,称为节点,用于收发和存储数据。初始时,所有节点都是独立的,不存在任何连接。 +小明可以通过网线将两个节点连接起来,连接后两个节点就可以互相通信了。两个节点如果存在网线连接,称为相邻。 +小明有时会测试当时的网络,他会在某个节点发送一条信息,信息会发送到每个相邻的节点,之后这些节点又会转发到自己相邻的节点,直到所有直接或间接相邻的节点都收到了信息。所有发送和接收的节点都会将信息存储下来。 +一条信息只存储一次。 +给出小明连接和测试的过程,请计算出每个节点存储信息的大小。 + +#### 输入格式 +输入的第一行包含两个整数 n, m,分别表示节点数量和操作数量。节点从1 至 n 编号。 +接下来 m 行,每行三个整数,表示一个操作。 +如果操作为 1 a b,表示将节点 a 和节点 b 通过网线连接起来。当 a = b时,表示连接了一个自环,对网络没有实质影响。 +如果操作为 2 p t,表示在节点 p 上发送一条大小为 t 的信息。 + +#### 输出格式 +输出一行,包含 n 个整数,相邻整数之间用一个空格分割,依次表示进行完上述操作后节点 1 至节点 n 上存储信息的大小。 + +#### 样例输入 +``` +4 8 +1 1 2 +2 1 10 +2 3 5 +1 4 1 +2 2 2 +1 1 2 +1 2 4 +2 2 1 +``` +#### 样例输出 +``` +13 13 5 3 +``` +#### 评测用例规模与约定 +``` +对于 30% 的评测用例,1 ≤ n ≤ 20,1 ≤ m ≤ 100。 +对于 50% 的评测用例,1 ≤ n ≤ 100,1 ≤ m ≤ 1000。 +对于 70% 的评测用例,1 ≤ n ≤ 1000,1 ≤ m ≤ 10000。 +对于所有评测用例,1 ≤ n ≤ 10000,1 ≤ m ≤ 100000,1 ≤ t ≤ 100。 +``` diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\275\221\347\273\234\345\210\206\346\236\220/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\275\221\347\273\234\345\210\206\346\236\220/solution.cpp" index e69de29bb..75f8e7e13 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\275\221\347\273\234\345\210\206\346\236\220/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\275\221\347\273\234\345\210\206\346\236\220/solution.cpp" @@ -0,0 +1,52 @@ +#include +#include +#include + +using namespace std; +const int maxn = 10005; +int a[maxn][maxn]; +int dfs_vis[maxn]; +int n, m; + +struct Node +{ + int data; +} Point[maxn]; + +void DFS(int a[maxn][maxn], int x, int y) +{ + Point[x].data += y; + dfs_vis[x] = 1; + for (int i = 1; i <= n; i++) + { + if (a[x][i] == 1 && dfs_vis[i] == 0) + { + DFS(a, i, y); + } + } +} +int main() +{ + cin >> n >> m; + cin.get(); + + for (int i = 1; i <= m; i++) + { + int flag, x1, x2; + scanf("%d %d %d", &flag, &x1, &x2); + if (flag == 1) + { + a[x1][x2] = a[x2][x1] = 1; + } + else if (flag == 2) + { + memset(dfs_vis, 0, sizeof(dfs_vis)); + DFS(a, x1, x2); + } + } + for (int i = 1; i <= n; ++i) + { + cout << Point[i].data << " "; + } + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\277\273\347\241\254\345\270\201/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\277\273\347\241\254\345\270\201/desc.md" index e69de29bb..8405b1b4a 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\277\273\347\241\254\345\270\201/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\277\273\347\241\254\345\270\201/desc.md" @@ -0,0 +1,37 @@ +#### 问题描述 +小明正在玩一个“翻硬币”的游戏。 + +桌上放着排成一排的若干硬币。我们用 * 表示正面,用 o 表示反面(是小写字母,不是零)。 + +比如,可能情形是:```**oo***oooo``` + +如果同时翻转左边的两个硬币,则变为:```oooo***oooo``` + +现在小明的问题是:如果已知了初始状态和要达到的目标状态,每次只能同时翻转相邻的两个硬币,那么对特定的局面,最少要翻动多少次呢? + +我们约定:把翻动相邻的两个硬币叫做一步操作,那么要求: + +#### 输入格式 +两行等长的字符串,分别表示初始状态和要达到的目标状态。每行的长度<1000 + +#### 输出格式 +一个整数,表示最小操作步数。 + +#### 样例输入1 +``` +********** +o****o**** +``` +#### 样例输出1 +``` +5 +``` +#### 样例输入2 +``` +*o**o***o*** +*o***o**o*** +``` +#### 样例输出2 +``` +1 +``` \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\277\273\347\241\254\345\270\201/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\277\273\347\241\254\345\270\201/solution.cpp" index e69de29bb..4da90020d 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\277\273\347\241\254\345\270\201/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\277\273\347\241\254\345\270\201/solution.cpp" @@ -0,0 +1,30 @@ +#include +using namespace std; +int main() +{ + string a, b; + cin >> a >> b; + int a1 = a.size(), b1 = b.size(), ans = 0; + for (int i = 0; i < a1; i++) + { + if (a[i] == b[i]) + { + continue; + } + else + { + ans++; + a[i] = b[i]; + if (a[i + 1] == '*') + { + a[i + 1] = 'o'; + } + else + { + a[i + 1] = '*'; + } + } + } + cout << ans << endl; + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\200\220\346\221\224\346\214\207\346\225\260/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\200\220\346\221\224\346\214\207\346\225\260/desc.md" index e69de29bb..d840c7ce5 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\200\220\346\221\224\346\214\207\346\225\260/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\200\220\346\221\224\346\214\207\346\225\260/desc.md" @@ -0,0 +1,43 @@ +x星球的居民脾气不太好,但好在他们生气的时候唯一的异常举动是:摔手机。 +各大厂商也就纷纷推出各种耐摔型手机。x星球的质监局规定了手机必须经过耐摔测试,并且评定出一个耐摔指数来,之后才允许上市流通。 + +x星球有很多高耸入云的高塔,刚好可以用来做耐摔测试。塔的每一层高度都是一样的,与地球上稍有不同的是,他们的第一层不是地面,而是相当于我们的2楼。 + +如果手机从第7层扔下去没摔坏,但第8层摔坏了,则手机耐摔指数=7。 +特别地,如果手机从第1层扔下去就坏了,则耐摔指数=0。 +如果到了塔的最高层第n层扔没摔坏,则耐摔指数=n + +为了减少测试次数,从每个厂家抽样3部手机参加测试。 + +如果已知了测试塔的高度,并且采用最佳策略,在最坏的运气下最多需要测试多少次才能确定手机的耐摔指数呢? + +输入数据,一个整数n(3 +int main() +{ + int n, i = 0, sum = 0, sum2 = 0; + scanf("%d", &n); + while (sum2 <= n) + { + i++; + sum2 += sum + 1; + sum += i; + } + printf("%d", i); + return 0; +} \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\210\252\347\217\255\346\227\266\351\227\264/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\210\252\347\217\255\346\227\266\351\227\264/desc.md" index e69de29bb..6bab97c1f 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\210\252\347\217\255\346\227\266\351\227\264/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\210\252\347\217\255\346\227\266\351\227\264/desc.md" @@ -0,0 +1,77 @@ +#### 问题背景 + +小h前往美国参加了蓝桥杯国际赛。小h的女朋友发现小h上午十点出发,上午十二点到达美国,于是感叹到“现在飞机飞得真快,两小时就能到美国了”。 + +小h对超音速飞行感到十分恐惧。仔细观察后发现飞机的起降时间都是当地时间。由于北京和美国东部有12小时时差,故飞机总共需要14小时的飞行时间。 + +不久后小h的女朋友去中东交换。小h并不知道中东与北京的时差。但是小h得到了女朋友来回航班的起降时间。小h想知道女朋友的航班飞行时间是多少。 + +#### 问题描述 + +对于一个可能跨时区的航班,给定来回程的起降时间。假设飞机来回飞行时间相同,求飞机的飞行时间。 + +#### 输入格式 + +从标准输入读入数据。 + +一个输入包含多组数据。 + +输入第一行为一个正整数T,表示输入数据组数。 + +每组数据包含两行,第一行为去程的 起降 时间,第二行为回程的 起降 时间。 + +起降时间的格式如下: +``` +h1:m1:s1 h2:m2:s2 或 h1:m1:s1 h3:m3:s3 (+1) 或 h1:m1:s1 h4:m4:s4 (+2) +``` +表示该航班在当地时间h1时m1分s1秒起飞, + +第一种格式表示在当地时间 当日 h2时m2分s2秒降落 + +第二种格式表示在当地时间 次日 h3时m3分s3秒降落。 + +第三种格式表示在当地时间 第三天 h4时m4分s4秒降落。 + +对于此题目中的所有以 h:m:s 形式给出的时间, 保证 ( 0<=h<=23, 0<=m,s<=59 ). + +#### 输出格式 + +输出到标准输出。 + +对于每一组数据输出一行一个时间hh:mm:ss,表示飞行时间为hh小时mm分ss秒。 + +注意,当时间为一位数时,要补齐前导零。如三小时四分五秒应写为03:04:05。 + +#### 样例输入 +``` +3 + +17:48:19 21:57:24 + +11:05:18 15:14:23 + +17:21:07 00:31:46 (+1) + +23:02:41 16:13:20 (+1) + +10:19:19 20:41:24 + +22:19:04 16:41:09 (+1) +``` +#### 样例输出 +``` +04:09:05 + +12:10:39 + +14:22:05 +``` +#### 限制与约定 + +保证输入时间合法,飞行时间不超过24小时。 + +#### 资源约定: + +峰值内存消耗(含虚拟机)< 256M + +CPU消耗 < 1000ms diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\210\252\347\217\255\346\227\266\351\227\264/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\210\252\347\217\255\346\227\266\351\227\264/solution.cpp" index e69de29bb..1fb0800ac 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\210\252\347\217\255\346\227\266\351\227\264/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\210\252\347\217\255\346\227\266\351\227\264/solution.cpp" @@ -0,0 +1,30 @@ +#include + +using namespace std; + +int getse(int h, int m, int s) { return h * 3600 + m * 60 + s; } +int gettime() +{ + string line; + getline(cin, line); + + if (line.back() != ')') + line += "(+0)"; //判断末尾是否有异日情况 无则加上(+0)方便格式化算时间 + int h1, h2, m1, m2, s1, s2, d; + sscanf(line.c_str(), "%d:%d:%d %d:%d:%d (+%d)", &h1, &m1, &s1, &h2, &m2, &s2, &d); //c_str 放入string字符串 实际是string 到const char* 同时我们读入起降两个时间 和 day + return getse(h2, m2, s2) - getse(h1, m1, s1) + d * 3600 * 24; +} +int main() +{ + int n; + cin >> n; + + getchar(); //吞掉int 与 string 中间的回车 + + while (n--) + { + int time = (gettime() + gettime()) / 2; + printf("%02d:%02d:%02d\n", time / 3600, time % 3600 / 60, time % 60); //02d没有两位则用0补足 + } + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\215\222\345\262\233\346\216\242\346\265\213/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\215\222\345\262\233\346\216\242\346\265\213/desc.md" index e69de29bb..57465fb7e 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\215\222\345\262\233\346\216\242\346\265\213/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\215\222\345\262\233\346\216\242\346\265\213/desc.md" @@ -0,0 +1,39 @@ +科学家小蓝来到了一个荒岛,准备对这个荒岛进行探测考察。 + +小蓝使用了一个超声定位设备来对自己进行定位。为了使用这个设备,小蓝需要在不同的点分别安装一个固定的发射器和一个固定的接收器。小蓝手中还有一个移动设备。定位设备需要从发射器发射一个信号到移动设备,移动设备收到后马上转发,最后由接收器接收,根据这些设备之间传递的时间差就能计算出移动设备距离发射器和接收器的两个距离,从而实现定位。 + +小蓝在两个位置已经安装了发射器和接收器,其中发射器安装在坐标($x_A$, $y_A$),接收器安装在坐标($x_B$, $y_B$)。小蓝的发射器和接收器可能在岛上,也可能不在岛上。 + +小蓝的定位设备设计有些缺陷,当发射器到移动设备的距离加上移动设备到接收器的距离之和大于L 时,定位设备工作不正常。当和小于等于L时,定位设备工作正常。为了安全,小蓝只在定位设备工作正常的区域探测考察。 + +已知荒岛是一个三角形,三个顶点的坐标分别为($x_1$, $y_1$),($x_2$, $y_2$),($x_3$, $y_3$) + +请计算,小蓝在荒岛上可以探测到的面积有多大? + +#### 输入格式 +输入的第一行包含五个整数,分别为 $x_A$,$y_A$,$x_B$,$y_B$,L +第二行包含六个整数,分别为 $x_1$,$y_1$,$x_2$,$y_2$,$x_3$,$y_3$ 。 + +#### 输出格式 +输出一行,包含一个实数,四舍五入保留2位小数,表示答案。 +考虑到计算中的误差,只要你的输出与参考输出相差不超过0.01即可。 +#### 样例输入 +``` +10 6 4 12 12 +0 2 13 2 13 15 +``` +#### 输出样例 +``` +39.99 +``` +#### 样例说明 +荒岛的形状和定位设备工作正常的区域如下图所示,蓝色的三角形表示荒岛,红色的曲线围成的区域为定位设备工作正常的区域。  +![](https://img-blog.csdnimg.cn/20210402235557403.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0NKTF9hc0xvbmc3Mg==,size_16,color_FFFFFF,t_70#pic_center) + +当输出为 39.98、39.99 或 40.00 时可以得分。 + +#### 评测用例规模与约定 +对于所有评测用例,保证发射器的两个坐标不同,$ -1000 \leq x_A,y_A,x_B,y_B\leq 1000$,$ -1000 \leq x_1,y_1,x_2,y_2,x_3,y_3\leq 1000$, $ -1000 \leq L \leq 1000 $。 + + + diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\215\222\345\262\233\346\216\242\346\265\213/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\215\222\345\262\233\346\216\242\346\265\213/solution.cpp" index e69de29bb..c2ff15ac4 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\215\222\345\262\233\346\216\242\346\265\213/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\215\222\345\262\233\346\216\242\346\265\213/solution.cpp" @@ -0,0 +1,108 @@ +#include +using namespace std; +typedef long long LL; +const double pi = acos(-1); +const double eps = 1e-8; +double xa, ya, xb, yb, l, x[5], y[5], _y[5], res = 0, site; +double dis(double a, double b, double c, double d) +{ + return sqrt((c - a) * (c - a) + (d - b) * (d - b)); +} +bool findtuo(double now) +{ + double jx = (xa + xb) / 2, jy = (ya + yb) / 2; + double aa = l / 2; + double cc = dis(xa, ya, xb, yb) / 2; + double bb = sqrt(aa * aa - cc * cc); + double mid = 1.0 - (now - jx) * (now - jx) / (aa * aa); + if (mid <= 0) + return 0; + mid = sqrt(mid) * bb; + _y[1] = jy - mid, _y[2] = jy + mid; + return 1; +} +double check(double now, int pos1, int pos2) +{ + if (fabs(x[pos1] - x[pos2]) <= eps && fabs(x[pos1] - now) <= eps) + return 1001.0; + if (now <= min(x[pos1], x[pos2]) || now >= max(x[pos1], x[pos2])) + return 1001.0; + double k = (y[pos2] - y[pos1]) / (x[pos2] - x[pos1]); + return k * (now - x[pos2]) + y[pos2]; +} +bool findsan(double now) +{ + int cnt = 2; + for (int i = 1; i <= 3; i++) + { + int nx = i + 1; + if (nx == 4) + nx = 1; + double mid = check(now, i, nx); + if (mid >= 1000.5) + continue; + if (cnt == 3 && fabs(mid - _y[cnt]) <= eps) + continue; + _y[++cnt] = mid; + } + if (cnt != 4) + return 0; + return 1; +} +//1 0 0 1 2 -1 0 1 0 0 1.732 +double anglee(double a, double b, double c, double d) +{ + double now = acos((c - a) / dis(a, b, c, d)); + if (d - b < 0) + return pi + pi - now; + return now; +} +void zhuan(int pos) +{ + double sitepos = anglee(0, 0, x[pos], y[pos]); + double val = dis(0, 0, x[pos], y[pos]); + double diff = sitepos - site; + x[pos] = val * cos(diff); + y[pos] = val * sin(diff); + //printf("%lf %lf\n",x[pos],y[pos]); +} +void zhuantuo() +{ + double sitepos1 = anglee(0, 0, xa, ya), sitepos2 = anglee(0, 0, xb, yb); + double val1 = dis(0, 0, xa, ya), val2 = dis(0, 0, xb, yb); + double diff1 = sitepos1 - site, diff2 = sitepos2 - site; + //printf("%lf %lf %lf\n",site,sitepos1,sitepos2); + xa = val1 * cos(diff1); + ya = val1 * sin(diff1); + xb = val2 * cos(diff2); + yb = val2 * sin(diff2); + //printf("%lf %lf %lf %lf\n",xa,ya,xb,yb); +} +double solve(double now) +{ + if (findtuo(now) == 0) + return 0; + if (findsan(now) == 0) + return 0; + double mx = max(min(_y[1], _y[2]), min(_y[3], _y[4])); + double mn = min(max(_y[1], _y[2]), max(_y[3], _y[4])); + //printf("%.4lf %.4lf %.4lf %.4lf %.4lf %.4lf\n",now,_y[1],_y[2],_y[3],_y[4],mn-mx); + if (mn - mx <= eps) + return 0; + return mn - mx; +} + +int main() +{ + scanf("%lf%lf%lf%lf%lf", &xa, &ya, &xb, &yb, &l); + site = anglee(xa, ya, xb, yb); + for (int i = 1; i <= 3; i++) + scanf("%lf%lf", &x[i], &y[i]), zhuan(i); + zhuantuo(); + if (l <= eps || dis(xa, ya, xb, yb) >= l) + return 0 * printf("0.00\n"); + for (double i = -1000; i <= 1000; i += 0.001) + res += solve(i) * 0.001; + printf("%.2lf\n", res); + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\232\202\350\232\201\346\204\237\345\206\222/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\232\202\350\232\201\346\204\237\345\206\222/desc.md" index e69de29bb..1754e9f49 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\232\202\350\232\201\346\204\237\345\206\222/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\232\202\350\232\201\346\204\237\345\206\222/desc.md" @@ -0,0 +1,50 @@ +#### 题目描述 +长 100 厘米的细长直杆子上有 n 只蚂蚁。 + +它们的头有的朝左,有的朝右。 + +每只蚂蚁都只能沿着杆子向前爬,速度是 1 厘米/秒。 + +当两只蚂蚁碰面时,它们会同时掉头往相反的方向爬行。 + +这些蚂蚁中,有 1 只蚂蚁感冒了。 + +并且在和其它蚂蚁碰面时,会把感冒传染给碰到的蚂蚁。 + +请你计算,当所有蚂蚁都爬离杆子时,有多少只蚂蚁患上了感冒。 + +#### 输入格式 +第一行输入一个整数 n, 表示蚂蚁的总数。 + +接着的一行是 n 个用空格分开的整数 Xi, Xi 的绝对值表示蚂蚁离开杆子左边端点的距离。 + +正值表示头朝右,负值表示头朝左,数据中不会出现 0 值,也不会出现两只蚂蚁占用同一位置。 + +其中,第一个数据代表的蚂蚁感冒了。 + +#### 输出格式 +输出1个整数,表示最后感冒蚂蚁的数目。 + +#### 数据范围 +``` +1 +using namespace std; + +int main() +{ + int n; + cin >> n; + int a[n]; + for (int i = 0; i < n; i++) + { + cin >> a[i]; + } + int x = a[0]; //第一只蚂蚁的位置 + if (x > 0) //向右 + { + int ans = 1; //记录蚂蚁感冒的数量 + for (int i = 0; i < n; i++) + { + if (a[i] < 0 && -a[i] > x) //右侧从右向左,蚂蚁对向而来且位置在其右边 + ans++; + } + if (ans != 1) //有从右向左的蚂蚁 + { + for (int i = 0; i < n; i++) + { + if (a[i] > 0 && a[i] < x) //在第一只蚂蚁后面且向右的蚂蚁也会被传染 + ans++; + } + } + cout << ans << endl; + } + if (x < 0) //向左 + { + int ans = 1; + for (int i = 0; i < n; i++) + { + if (a[i] > 0 && a[i] < -x) //左侧从左向右,蚂蚁对向而来且位置在其左边 + ans++; + } + if (ans != 1) //如果有从左向右的蚂蚁 + { + for (int i = 0; i < n; i++) + { + if (a[i] < 0 && -a[i] > -x) //在第一只蚂蚁后面且向左的蚂蚁也会被感染 + ans++; + } + } + cout << ans << endl; + } + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\233\207\345\275\242\345\241\253\346\225\260/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\233\207\345\275\242\345\241\253\346\225\260/desc.md" index e69de29bb..bc504b703 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\233\207\345\275\242\345\241\253\346\225\260/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\233\207\345\275\242\345\241\253\346\225\260/desc.md" @@ -0,0 +1,3 @@ +如下图所示,小明用从1 开始的正整数“蛇形”填充无限大的矩阵。 +![](https://img-blog.csdnimg.cn/20210221154521571.png) +容易看出矩阵第二行第二列中的数是5。请你计算矩阵中第20 行第20 列的数是多少? diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\233\207\345\275\242\345\241\253\346\225\260/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\233\207\345\275\242\345\241\253\346\225\260/solution.cpp" index e69de29bb..0659026b9 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\233\207\345\275\242\345\241\253\346\225\260/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\233\207\345\275\242\345\241\253\346\225\260/solution.cpp" @@ -0,0 +1,26 @@ +#include +#include + +int main() +{ + int map[50][50]; + int i, j, cnt = 1; + int nowi, nowj; + for (i = 1; i <= 40; i++) + { + if (i & 1) + { //若为奇数轮的时候,是从左下角到右上角 + nowi = i, nowj = 1; + for (j = 0; j < i; j++) + map[nowi - j][nowj + j] = cnt++; + } + else + { //若为偶数轮的时候,是从右上角到左下角 + nowi = 1, nowj = i; + for (j = 0; j < i; j++) + map[nowi + j][nowj - j] = cnt++; + } + } + printf("%d", map[20][20]); //答案:761 + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\236\272\346\227\213\346\212\230\347\272\277/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\236\272\346\227\213\346\212\230\347\272\277/desc.md" index e69de29bb..c9da5745b 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\236\272\346\227\213\346\212\230\347\272\277/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\236\272\346\227\213\346\212\230\347\272\277/desc.md" @@ -0,0 +1,27 @@ +如图所示的螺旋折线经过平面上所有整点恰好一次。 +对于整点(X, Y),我们定义它到原点的距离dis(X, Y)是从原点到(X, Y)的螺旋折线段的长度。 + +例如```dis(0, 1)=3, dis(-2, -1)=9``` + +给出整点坐标(X, Y),你能计算出dis(X, Y)吗? + +#### 输入格式 +``` +X和Y + +对于40%的数据,-1000 <= X, Y <= 1000 +对于70%的数据,-100000 <= X, Y <= 100000 +对于100%的数据, -1000000000 <= X, Y <= 1000000000 +``` +#### 输出格式 +``` +输出dis(X, Y) +``` +#### 样例输入 +``` +0 1 +``` +#### 样例输出 +``` +3 +``` \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\236\272\346\227\213\346\212\230\347\272\277/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\236\272\346\227\213\346\212\230\347\272\277/solution.cpp" index e69de29bb..edce08c1c 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\236\272\346\227\213\346\212\230\347\272\277/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\236\272\346\227\213\346\212\230\347\272\277/solution.cpp" @@ -0,0 +1,24 @@ +#include +#include +using namespace std; + +int main() +{ + int x, y; + cin >> x >> y; + long long sum = 0; + + if ((y < x) && (-y <= x)) + { + sum += x > 1 ? (long long)(4 * (2 + (abs(x) - 1) * (abs(x) - 2))) : 0; //求前n个正方形周长的等差数列和 + sum += (long long)x > 0 ? (4 * x + (x - y)) : (y - x); + } + else + { + sum += y > 1 ? (long long)(4 * (2 + (abs(y) - 1) * (abs(y) - 2))) : 0; //求前n个正方形周长的等差数列和 + sum += (long long)y > 0 ? (2 * y + y + x) : (6 * y - y - x); + } + + cout << sum << endl; + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\243\205\351\245\260\347\217\240/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\243\205\351\245\260\347\217\240/desc.md" index e69de29bb..e9e9a46f0 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\243\205\351\245\260\347\217\240/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\243\205\351\245\260\347\217\240/desc.md" @@ -0,0 +1,46 @@ +#### 题目描述 +在怪物猎人这一款游戏中,玩家可以通过给装备镶嵌不同的装饰珠来获取 相应的技能,以提升自己的战斗能力。 + +已知猎人身上一共有 6 件装备,每件装备可能有若干个装饰孔,每个装饰孔有各自的等级,可以镶嵌一颗小于等于自身等级的装饰珠 (也可以选择不镶嵌)。 + +装饰珠有 M 种,编号 1 至 M,分别对应 M 种技能,第 i 种装饰珠的等级为 $L_i$,只能镶嵌在等级大于等于 $L_i$ 的装饰孔中。 +对第 i 种技能来说,当装备相应技能的装饰珠数量达到 $K_i$个时,会产生$W_i$($K_i$)的价值,镶嵌同类技能的数量越多,产生的价值越大,即$W_i$($K_{i-1}$)<$W_i$($K_i$)。但每个技能都有上限$P_i$(1≤$P_i$≤7),当装备的珠子数量超过$P_i$时,只会产生$W_i$($P_i$)的价值。 + +对于给定的装备和装饰珠数据,求解如何镶嵌装饰珠,使得 6 件装备能得到的总价值达到最大。 + +#### 输入描述 +输入的第 1 至 6 行,包含 6 件装备的描述。其中第i行的第一个整数Ni表示第i件装备的装饰孔数量。后面紧接着Ni个整数,分别表示该装备上每个装饰孔的等级L(1≤ L ≤4)。 +第 7 行包含一个正整数 M,表示装饰珠 (技能) 种类数量。 +第 8 至 M + 7 行,每行描述一种装饰珠 (技能) 的情况。每行的前两个整数$L_j$(1≤ $L_j$ ≤4)和$P_j$(1≤ $P_j$ ≤7)分别表示第 j 种装饰珠的等级和上限。接下来$P_j$个整数,其中第 k 个数表示装备该中装饰珠数量为 k 时的价值$W_j$(k)。 +其中$1 ≤ N_i ≤ 50,1 ≤ M ≤ 10^4,1 ≤ W_j(k) ≤ 10^4。$ + +#### 输出描述 +输出一行包含一个整数,表示能够得到的最大价值。 +#### 输入 +``` +1 1 +2 1 2 +1 1 +2 2 2 +1 1 +1 3 +3 +1 5 1 2 3 5 8 +2 4 2 4 8 15 +3 2 5 10 +``` +#### 输出 +``` +20 +``` +#### 样例说明 +按照如下方式镶嵌珠子得到最大价值 20,括号内表示镶嵌的装饰珠的种类编号: +``` +1: (1) +2: (1) (2) +3: (1) +4: (2) (2) +5: (1) +6: (2) +``` +4 颗技能 1 装饰珠,4 颗技能 2 装饰珠 $W_1(4) + W_2(4) = 5 + 15 = 20。W_1(4)+W_2(4)=5+15=20$。 \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\243\205\351\245\260\347\217\240/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\243\205\351\245\260\347\217\240/solution.cpp" index e69de29bb..c120430f0 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\243\205\351\245\260\347\217\240/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\243\205\351\245\260\347\217\240/solution.cpp" @@ -0,0 +1,68 @@ +#include +#include +using namespace std; +int Solution() +{ + int n, sum = 0, L[5] = {0}, m, M, W[5][10] = {0}, le, P, res = 0; + for (int i = 0; i < 6; i++) + { + cin >> n; + sum += n; + for (int j = 0; j < n; j++) + { + cin >> m; + L[m]++; + } + } + cin >> M; + int ww; + for (int i = 0; i < M; i++) + { + cin >> le >> P; + for (int j = 1; j <= P; j++) + { + cin >> ww; + if (ww > W[le][j]) + W[le][j] = ww; + if ((j + 1 > P) && P < 7) + for (int k = j + 1; k <= 7; k++) + W[le][k] = W[le][k - 1]; + } + } + for (int i = 0; i <= L[4]; i++) + { + for (int j = 0; j <= (sum - L[1] - L[2] - i); j++) + { + for (int k = 0; k <= (sum - L[1] - (i + j)); k++) + { + for (int s = 0; s <= (sum - (i + j + k)); s++) + { + int a, b, c, d; + if (i > 7) + a = 7; + else + a = i; + if (j > 7) + b = 7; + else + b = j; + if (k > 7) + c = 7; + else + c = k; + if (s > 7) + d = 7; + else + d = s; + res = max(res, W[4][a] + W[3][b] + W[2][c] + W[1][d]); + } + } + } + } + return res; +} +int main() +{ + cout << Solution(); + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\247\243\345\257\206/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\247\243\345\257\206/desc.md" index e69de29bb..3f671183a 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\247\243\345\257\206/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\247\243\345\257\206/desc.md" @@ -0,0 +1,10 @@ +#### 问题描述 +RSA 是一种经典的加密算法。它的基本加密过程如下。 +首先生成两个质数 p, q,令 n = p · q,设 d 与 (p − 1) · (q − 1) 互质,则可找到 e 使得 d · e 除 (p − 1) · (q − 1) 的余数为 1。 +n, d, e 组成了私钥,n, d 组成了公钥。 +当使用公钥加密一个整数 X 时(小于 n),计算 C = Xd mod n,则 C 是加密后的密文。 +当收到密文 C 时,可使用私钥解开,计算公式为 X = Ce mod n。 +例如,当 p = 5, q = 11, d = 3 时,n = 55, e = 27。 +若加密数字 24,得 243 mod 55 = 19。 +解密数字 19,得 1927 mod 55 = 24。 +现在你知道公钥中 n = 1001733993063167141, d = 212353,同时你截获了别人发送的密文 C = 20190324,请问,原文是多少? diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\247\243\345\257\206/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\247\243\345\257\206/solution.cpp" index e69de29bb..762d11343 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\247\243\345\257\206/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\247\243\345\257\206/solution.cpp" @@ -0,0 +1,82 @@ +#include +using namespace std; +typedef long long num; + +/*(a*b)%mod*/ +num fast_mul(num a, num b, num mod) +{ + num ans = 0; + a = a % mod, b = b % mod; + while (b != 0) + { + if (b & 1) + { + ans = (ans + a) % mod; + } + b >>= 1; + a = (a + a) % mod; + } + return ans; +} + +/*a^b%mod*/ +num fast_pow(num a, num b, num mod) +{ + num ans = 1; + num fns = a; + while (b != 0) + { + if (b & 1) + ans = fast_mul(ans, fns, mod); + fns = fast_mul(fns, fns, mod); + b >>= 1; + } + return ans; +} + +/*eular function*/ +num euler(num n) +{ + num ans = n; + for (num i = 2; (i * i) <= n; i++) + { + if (n % i == 0) + { + ans = ans / i * (i - 1); + while (n % i == 0) + n = n / i; + } + } + if (n > 1) + ans = ans / n * (n - 1); + return ans; +} + +num find_q(num n) +{ + for (num i = 2; i < n; i++) + { + if (n % i == 0) + return i; + } +} + +int main() +{ + num n = 1001733993063167141, d = 212353, C = 20190324; /*known*/ + num i, j, k; + num q, p, e, X; /*unknown*/ + + /*get q ,p ,k*/ + q = find_q(n); + p = n / q; + k = (p - 1) * (q - 1); + + /*get e*/ + e = fast_pow(d, euler(k) - 1, k); + + /*find x*/ + X = fast_pow(C, e, n); + cout << X; + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\247\243\347\240\201/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\247\243\347\240\201/desc.md" index e69de29bb..5eea933d8 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\247\243\347\240\201/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\247\243\347\240\201/desc.md" @@ -0,0 +1,28 @@ +#### 问题描述 + +小明有一串很长的英文字母,可能包含大写和小写。在这串字母中,有很多连续的是重复的。小明想了一个办法将这串字母表达得更短:将连续的几个相同字母写成字母 + 出现次数的形式。 + +例如,连续的 5 个 a,即 aaaaa,小明可以简写成 a5(也可能简写成 a4a、aa3a 等)。对于这个例子:HHHellllloo,小明可以简写成 H3el5o2。为了方便表达,小明不会将连续的超过 9 个相同的字符写成简写的形式。 +现在给出简写后的字符串,请帮助小明还原成原来的串。 + +#### 输入格式 + +输入一行包含一个字符串。 + +#### 输出格式 + +输出一个字符串,表示还原后的串。 + +#### 样例输入 +``` +H3el5o2 +``` +#### 样例输出 +``` +HHHellllloo +``` +#### 评测用例规模与约定 + +对于所有评测用例,字符串由大小写英文字母和数字组成,长度不超过100。 + +请注意原来的串长度可能超过 100。 \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\247\243\347\240\201/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\247\243\347\240\201/solution.cpp" index e69de29bb..4e9fe079e 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\247\243\347\240\201/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\247\243\347\240\201/solution.cpp" @@ -0,0 +1,29 @@ +#include +using namespace std; +char s2[100000]; +int main() +{ + char s1[150]; + cin >> s1; + + int top = 0; + for (int i = 0; s1[i] != '\0'; i++) + { + if ((s1[i] >= 'A' && s1[i] <= 'Z') || (s1[i] >= 'a' && s1[i] <= 'z')) + { + s2[top++] = s1[i]; + } + else + { + while (s1[i] != '1') + { + s2[top++] = s1[i - 1]; + s1[i] = s1[i] - 1; + } + } + } + s2[top] = '\0'; + + cout << s2; + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\264\255\347\211\251\345\215\225/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\264\255\347\211\251\345\215\225/desc.md" index e69de29bb..454eb1a26 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\264\255\347\211\251\345\215\225/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\264\255\347\211\251\345\215\225/desc.md" @@ -0,0 +1,61 @@ +小明刚刚找到工作,老板人很好,只是老板夫人很爱购物。老板忙的时候经常让小明帮忙到商场代为购物。小明很厌烦,但又不好推辞。这不,XX大促销又来了!老板夫人开出了长长的购物单,都是有打折优惠的。小明也有个怪癖,不到万不得已,从不刷卡,直接现金搞定。现在小明很心烦,请你帮他计算一下,需要从取款机上取多少现金,才能搞定这次购物。取款机只能提供100元面额的纸币。小明想尽可能少取些现金,够用就行了。你的任务是计算出,小明最少需要取多少现金。 + +``` +以下是让人头疼的购物单,为了保护隐私,物品名称被隐藏了。 +----------------- +**** 180.90 88折 +**** 10.25 65折 +**** 56.14 9折 +**** 104.65 9折 +**** 100.30 88折 +**** 297.15 半价 +**** 26.75 65折 +**** 130.62 半价 +**** 240.28 58折 +**** 270.62 8折 +**** 115.87 88折 +**** 247.34 95折 +**** 73.21 9折 +**** 101.00 半价 +**** 79.54 半价 +**** 278.44 7折 +**** 199.26 半价 +**** 12.97 9折 +**** 166.30 78折 +**** 125.50 58折 +**** 84.98 9折 +**** 113.35 68折 +**** 166.57 半价 +**** 42.56 9折 +**** 81.90 95折 +**** 131.78 8折 +**** 255.89 78折 +**** 109.17 9折 +**** 146.69 68折 +**** 139.33 65折 +**** 141.16 78折 +**** 154.74 8折 +**** 59.42 8折 +**** 85.44 68折 +**** 293.70 88折 +**** 261.79 65折 +**** 11.30 88折 +**** 268.27 58折 +**** 128.29 88折 +**** 251.03 8折 +**** 208.39 75折 +**** 128.88 75折 +**** 62.06 9折 +**** 225.87 75折 +**** 12.89 75折 +**** 34.28 75折 +**** 62.16 58折 +**** 129.12 半价 +**** 218.37 半价 +**** 289.69 8折 +-------------------- +``` +需要说明的是,88折指的是按标价的88%计算,而8折是按80%计算,余者类推。 +特别地,半价是按50%计算。 +请提交小明要从取款机上提取的金额,单位是元。 +答案是一个整数,类似4300的样子,结尾必然是00,不要填写任何多余的内容。 \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\264\255\347\211\251\345\215\225/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\264\255\347\211\251\345\215\225/solution.cpp" index e69de29bb..605cbe035 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\264\255\347\211\251\345\215\225/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\264\255\347\211\251\345\215\225/solution.cpp" @@ -0,0 +1,12 @@ +#include +using namespace std; +double num[100][2] = { + {180.90, 88}, {10.25, 65}, {56.14, 90}, {104.65, 90}, {100.30, 88}, {297.15, 50}, {26.75, 65}, {130.62, 50}, {240.28, 58}, {270.62, 80}, {115.87, 88}, {247.34, 95}, {73.21, 90}, {101.00, 50}, {79.54, 50}, {278.44, 70}, {199.26, 50}, {12.97, 90}, {166.30, 78}, {125.50, 58}, {84.98, 90}, {113.35, 68}, {166.57, 50}, {42.56, 90}, {81.90, 95}, {131.78, 80}, {255.89, 78}, {109.17, 90}, {146.69, 68}, {139.33, 65}, {141.16, 78}, {154.74, 80}, {59.42, 80}, {85.44, 68}, {293.70, 88}, {261.79, 65}, {11.30, 88}, {268.27, 58}, {128.29, 88}, {251.03, 80}, {208.39, 75}, {128.88, 75}, {62.06, 90}, {225.87, 75}, {12.89, 75}, {34.28, 75}, {62.16, 58}, {129.12, 50}, {218.37, 50}, {289.69, 80}}; +int main() +{ + double ans = 0.0; + for (int i = 0; i < 50; ++i) + ans += num[i][0] * num[i][1] / 100; + cout << ans << endl; + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\265\260\346\226\271\346\240\274/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\265\260\346\226\271\346\240\274/desc.md" index e69de29bb..7fdf6bf45 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\265\260\346\226\271\346\240\274/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\265\260\346\226\271\346\240\274/desc.md" @@ -0,0 +1,27 @@ +#### 问题描述 +在平面上有一些二维的点阵。这些点的编号就像二维数组的编号一样,从上到下依次为第 1 至第 n 行,从左到右依次为第 1 至第 m 列,每一个点可以用行号和列号来表示。现在有个人站在第 1 行第 1 列,要走到第 n 行第 m 列。只能向右或者向下走。注意,如果行号和列数都是偶数,不能走入这一格中。问有多少种方案。 + +#### 输入格式 +输入一行包含两个整数 n, m。 + +#### 输出格式 +输出一个整数,表示答案。 + +#### 样例输入 +``` +3 4 +``` +#### 样例输出 +``` +2 +``` +#### 样例输入 +``` +6 6 +``` +#### 样例输出 +``` +0 +``` +#### 测试数据 +对于所有评测用例,1 ≤ n ≤ 30, 1 ≤ m ≤ 30。 diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\265\260\346\226\271\346\240\274/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\265\260\346\226\271\346\240\274/solution.cpp" index e69de29bb..b9ae351b2 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\265\260\346\226\271\346\240\274/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\265\260\346\226\271\346\240\274/solution.cpp" @@ -0,0 +1,43 @@ +#include +using namespace std; +int chess[55][55], book[55][55]; +int n, m, cnt = 0; +int dx[4] = {1, 0}; +int dy[4] = {0, 1}; + +int judge(int x, int y) +{ + if (x % 2 == 0 && y % 2 == 0) + return 0; + return 1; +} + +void dfs(int x, int y) +{ + if (x == n && y == m) + { + cnt++; + return; + } + + book[1][1] = 1; + for (int i = 0; i < 2; i++) + { + int tx = x + dx[i]; + int ty = y + dy[i]; + if (tx >= 1 && tx <= n && ty >= 1 && ty <= m && judge(tx, ty) && book[tx][ty] == 0) + { + book[tx][ty] = 1; + dfs(tx, ty); + book[tx][ty] = 0; + } + } +} + +int main() +{ + cin >> n >> m; + dfs(1, 1); + cout << cnt; + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\267\221\346\255\245\350\256\255\347\273\203/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\267\221\346\255\245\350\256\255\347\273\203/desc.md" index e69de29bb..9a69aa3f4 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\267\221\346\255\245\350\256\255\347\273\203/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\267\221\346\255\245\350\256\255\347\273\203/desc.md" @@ -0,0 +1,4 @@ +小明要做一个跑步训练。 +初始时,小明充满体力,体力值计为 10000 。如果小明跑步,每分钟损耗 600的体力。如果小明休息,每分钟增加 300 的体力。体力的损耗和增加都是均匀变化的。 +小明打算跑一分钟、休息一分钟、再跑一分钟、再休息一分钟……如此循环。如果某个时刻小明的体力到达 0 ,他就停止锻炼。 +请问小明在多久后停止锻炼。为了使答案为整数,请以秒为单位输出答案 diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\267\221\346\255\245\350\256\255\347\273\203/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\267\221\346\255\245\350\256\255\347\273\203/solution.cpp" index e69de29bb..06f136761 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\267\221\346\255\245\350\256\255\347\273\203/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\267\221\346\255\245\350\256\255\347\273\203/solution.cpp" @@ -0,0 +1,44 @@ +#include +using namespace std; + +int slove(int n) +{ + int m = 0; + while (true) + { + // 体力大于600,还能进行下次循环 + if (n > 600) + { + n -= 600; // 跑1分钟消耗600体力 + } + else + { + // 600/60 每秒钟消耗的体力 + // n / (600 / 60) n体力能够跑的时间 + return m + n / (600 / 60); + } + + n += 300; // 休息1分钟提升300体力 + m = m + 2 * 60; // 一个循环2分钟 + } +} + +// 递归算法 +int slove_d(int n) +{ + //体力不大于600,结束递归 + if (n <= 600) + { + return n / (600 / 60); + } + + // 每次循环2分钟, 消耗300体力 + return 60 * 2 + slove_d(n - 300); +} + +int main() +{ + cout << slove(10000) << endl; + cout << slove_d(10000) << endl; + return 0; +} \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\267\221\346\255\245\351\224\273\347\202\274/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\267\221\346\255\245\351\224\273\347\202\274/desc.md" index e69de29bb..69a544275 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\267\221\346\255\245\351\224\273\347\202\274/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\267\221\346\255\245\351\224\273\347\202\274/desc.md" @@ -0,0 +1,3 @@ +小蓝每天都锻炼身体。 +正常情况下,小蓝每天跑1千米。如果某天是周一或者月初(1日),为了激励自己,小蓝要跑2千米。如果同时是周一或月初,小蓝也是跑2千米。 +小蓝跑步已经坚持了很长时间,从2000年1月1日周六(含)到2020年10月1日周四(含)。请问这段时间小蓝总共跑步多少千米? \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\267\221\346\255\245\351\224\273\347\202\274/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\267\221\346\255\245\351\224\273\347\202\274/solution.cpp" index e69de29bb..56cb2473b 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\267\221\346\255\245\351\224\273\347\202\274/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\267\221\346\255\245\351\224\273\347\202\274/solution.cpp" @@ -0,0 +1,30 @@ +#include +using namespace std; +int M[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; +int main() +{ + int y = 2000, m = 1, d = 1, w = 6, ans = 2; + while (y != 2020 || m != 10 || d != 1) + { + if ((y % 4 == 0 && y % 100 != 0) || y % 400 == 0) + M[2] = 29; + else + M[2] = 28; + d++; + w = (w + 1) % 7; + if (d > M[m]) + { + d = 1; + m++; + if (m > 12) + { + y++; + m = 1; + } + } + if (d == 1 || w == 1) + ans++; + ans++; + } + cout << ans; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\267\263\350\232\261\350\234\242/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\267\263\350\232\261\350\234\242/desc.md" index e69de29bb..5867dbe89 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\267\263\350\232\261\350\234\242/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\267\263\350\232\261\350\234\242/desc.md" @@ -0,0 +1,11 @@ +有 9 只盘子,排成 1 个圆圈。 + +其中 8 只盘子内装着 8 只蚱蜢,有一个是空盘,我们把这些蚱蜢顺时针编号为 1 ~ 8 + +每只蚱蜢都可以跳到相邻的空盘中,也可以再用点力,越过一个相邻的蚱蜢跳到空盘中。 + +请你计算一下,如果要使得蚱蜢们的队形改为按照逆时针排列, + +并且保持空盘的位置不变(也就是 1-8 换位,2-7 换位,…),至少要经过多少次跳跃? + +![](https://img-blog.csdnimg.cn/20200530104930106.png) \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\267\263\350\232\261\350\234\242/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\267\263\350\232\261\350\234\242/solution.cpp" index e69de29bb..a65346d14 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\267\263\350\232\261\350\234\242/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\267\263\350\232\261\350\234\242/solution.cpp" @@ -0,0 +1,44 @@ +#include +#include +#include +using namespace std; + +int dir[] = {1, -1, 2, -2}; +unordered_map dist; +string S = "12345678X", T = "87654321X"; + +int bfs() +{ + queue q; + q.push(S); + dist[S] = 0; + + while (q.size()) + { + string t = q.front(); + q.pop(); + + if (t == T) + return dist[t]; + + int k = t.find('X'), distance = dist[t]; + for (int i = 0; i < 4; i++) + { + swap(t[k], t[(k + dir[i] + 9) % 9]); + if (!dist.count(t)) + { + q.push(t); + dist[t] = distance + 1; + } + swap(t[k], t[(k + dir[i] + 9) % 9]); + } + } + + return -1; +} + +int main() +{ + cout << bfs() << endl; + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\277\236\345\217\267\345\214\272\351\227\264\346\225\260/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\277\236\345\217\267\345\214\272\351\227\264\346\225\260/desc.md" index e69de29bb..9dd38c893 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\277\236\345\217\267\345\214\272\351\227\264\346\225\260/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\277\236\345\217\267\345\214\272\351\227\264\346\225\260/desc.md" @@ -0,0 +1,31 @@ +#### 问题描述 +小明这些天一直在思考这样一个奇怪而有趣的问题: +在1~N的某个全排列中有多少个连号区间呢?这里所说的连号区间的定义是: +如果区间[L, R] 里的所有元素(即此排列的第L个到第R个元素)递增排序后能得到一个长度为R-L+1的“连续”数列,则称这个区间连号区间。 +当N很小的时候,小明可以很快地算出答案,但是当N变大的时候,问题就不是那么简单了,现在小明需要你的帮助。 + +#### 输入格式 +第一行是一个正整数N (1 <= N <= 50000), 表示全排列的规模。 +第二行是N个不同的数字Pi(1 <= Pi <= N), 表示这N个数字的某一全排列。 + +#### 输出格式 +输出一个整数,表示不同连号区间的数目。 + +#### 样例输入1 +``` +4 +3 2 4 1 +``` +#### 样例输出1 +``` +7 +``` +#### 样例输入2 +``` +5 +3 4 2 5 1 +``` +#### 样例输出2 +``` +9 +``` \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\277\236\345\217\267\345\214\272\351\227\264\346\225\260/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\277\236\345\217\267\345\214\272\351\227\264\346\225\260/solution.cpp" index e69de29bb..d464d0292 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\277\236\345\217\267\345\214\272\351\227\264\346\225\260/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\277\236\345\217\267\345\214\272\351\227\264\346\225\260/solution.cpp" @@ -0,0 +1,33 @@ +#include +using namespace std; + +int n; +int arr[50000]; +int ans = 0; + +int main() +{ + cin >> n; + for (int i = 0; i < n; i++) + { + cin >> arr[i]; + } + + for (int i = 0; i < n; i++) + { + int min = arr[i]; + int max = arr[i]; + for (int j = i; j < n; j++) + { + + if (arr[j] > max) + max = arr[j]; + if (arr[j] < min) + min = arr[j]; + if (max - min + 1 == j - i + 1) + ans++; + } + } + cout << ans; + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\277\267\345\256\253/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\277\267\345\256\253/desc.md" index e69de29bb..153a74bcd 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\277\267\345\256\253/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\277\267\345\256\253/desc.md" @@ -0,0 +1,44 @@ +#### 问题描述 +下图给出了一个迷宫的平面图,其中标记为 1 的为障碍,标记为 0 的为可 以通行的地方。 +``` +010000 +000100 +001001 +110000 +``` +迷宫的入口为左上角,出口为右下角,在迷宫中,只能从一个位置走到这 个它的上、下、左、右四个方向之一。 对于上面的迷宫,从入口开始,可以按DRRURRDDDR 的顺序通过迷宫, 一共 10 步。其中 D、U、L、R 分别表示向下、向上、向左、向右走。 对于下面这个更复杂的迷宫(30 行 50 列),请找出一种通过迷宫的方式, 其使用的步数最少,在步数最少的前提下,请找出字典序最小的一个作为答案。 请注意在字典序中D +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; + +#define N 30 +#define M 50 + +char map[N][M]; +int dir[4][2] = {{1, 0}, {0, -1}, {0, 1}, {-1, 0}}; //D q; + point p(0, 0); + p.road = ""; + q.push(p); + vis[0][0] = 1; + while (!q.empty()) + { + point t = q.front(); + q.pop(); + if (t.x == N - 1 && t.y == M - 1) + { + cout << t.road << endl; + break; + } + for (int i = 0; i < 4; i++) + { + int dx = t.x + dir[i][0]; + int dy = t.y + dir[i][1]; + if (dx >= 0 && dx < N && dy >= 0 && dy < M) + { + if (map[dx][dy] == '0' && !vis[dx][dy]) + { + point tt(dx, dy); + tt.road = t.road + ch[i]; //记录路径 + q.push(tt); + vis[dx][dy] = 1; + } + } + } + } +} + +int main() +{ + for (int i = 0; i < N; i++) + { + for (int j = 0; j < M; j++) + scanf("%c", &map[i][j]); + getchar(); //读掉回车 + } + bfs(); + return 0; +} \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\200\206\346\263\242\345\205\260\350\241\250\350\276\276\345\274\217/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\200\206\346\263\242\345\205\260\350\241\250\350\276\276\345\274\217/desc.md" index e69de29bb..e0bb51c54 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\200\206\346\263\242\345\205\260\350\241\250\350\276\276\345\274\217/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\200\206\346\263\242\345\205\260\350\241\250\350\276\276\345\274\217/desc.md" @@ -0,0 +1,14 @@ +正常的表达式称为中缀表达式,运算符在中间,主要是给人阅读的,机器求解并不方便。 +例如:3 + 5 * (2 + 6) - 1 +而且,常常需要用括号来改变运算次序。 +相反,如果使用逆波兰表达式(前缀表达式)表示,上面的算式则表示为: +``` +- + 3 * 5 + 2 6 1 +``` +不再需要括号,机器可以用递归的方法很方便地求解。 +为了简便,我们假设: +1. 只有 $ + - * $ 三种运算符 +2. 每个运算数都是一个小于10的非负整数 + +下面的程序对一个逆波兰表示串进行求值。 +其返回值为一个数组:其中第一元素表示求值结果,第二个元素表示它已解析的字符数。 diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\200\206\346\263\242\345\205\260\350\241\250\350\276\276\345\274\217/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\200\206\346\263\242\345\205\260\350\241\250\350\276\276\345\274\217/solution.cpp" index e69de29bb..e342a718c 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\200\206\346\263\242\345\205\260\350\241\250\350\276\276\345\274\217/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\200\206\346\263\242\345\205\260\350\241\250\350\276\276\345\274\217/solution.cpp" @@ -0,0 +1,46 @@ +#include +using namespace std; + +struct EV +{ + int result; //计算结果 + int n; //消耗掉的字符数 +}; + +struct EV evaluate(char *x) +{ + struct EV ev = {0, 0}; + struct EV v1; + struct EV v2; + + if (*x == 0) + return ev; + + if (x[0] >= '0' && x[0] <= '9') + { + ev.result = x[0] - '0'; //字符转数字 + ev.n = 1; + return ev; + } + + v1 = evaluate(x + 1); + v2 = evaluate(x + v1.n + 1); + + if (x[0] == '+') + ev.result = v1.result + v2.result; + if (x[0] == '*') + ev.result = v1.result * v2.result; + if (x[0] == '-') + ev.result = v1.result - v2.result; + ev.n = 1 + v1.n + v2.n; + + return ev; +} + +int main(int argc, char **argv) +{ + string str = "-+3*5+261"; + const EV &ev = evaluate((char *)(str.c_str())); + cout << ev.result << endl; + return 0; +} \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\200\222\345\242\236\344\270\211\345\205\203\347\273\204/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\200\222\345\242\236\344\270\211\345\205\203\347\273\204/desc.md" index e69de29bb..616ac8923 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\200\222\345\242\236\344\270\211\345\205\203\347\273\204/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\200\222\345\242\236\344\270\211\345\205\203\347\273\204/desc.md" @@ -0,0 +1,31 @@ +给定三个整数数组 +A = [A1, A2, ... AN], +B = [B1, B2, ... BN], +C = [C1, C2, ... CN], +请你统计有多少个三元组(i, j, k) 满足: +1. 1 <= i, j, k <= N +2. Ai < Bj < Ck + +#### 输入格式 +第一行包含一个整数N。 +第二行包含N个整数A1, A2, ... AN。 +第三行包含N个整数B1, B2, ... BN。 +第四行包含N个整数C1, C2, ... CN。 + +对于30%的数据,1 <= N <= 100 +对于60%的数据,1 <= N <= 1000 +对于100%的数据,1 <= N <= 100000 0 <= Ai, Bi, Ci <= 100000 + +#### 输出格式 +一个整数表示答案 +#### 样例输入 +``` +3 +1 1 1 +2 2 2 +3 3 3 +``` +#### 样例输出 +``` +27 +``` diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\200\222\345\242\236\344\270\211\345\205\203\347\273\204/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\200\222\345\242\236\344\270\211\345\205\203\347\273\204/solution.cpp" index e69de29bb..4e66800ec 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\200\222\345\242\236\344\270\211\345\205\203\347\273\204/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\200\222\345\242\236\344\270\211\345\205\203\347\273\204/solution.cpp" @@ -0,0 +1,42 @@ +#include +#include + +using namespace std; + +typedef long long LL; + +const int N = 1e5 + 10; +int a[N], b[N], c[N], sa[N], sc[N], s[N]; //sa是用来记录ab[i]的前缀和,s是临时数组。 + +int main() +{ + int n; + cin >> n; + for (int i = 0; i < n; i++) + cin >> a[i], a[i]++; //++操作是为了防止输入为0,a[i]++使得s[a[i]]++不可能为0,使得s[i]+=s[i-1]可以计算,又因为且所有增大相当于所有不增大。 + for (int i = 0; i < n; i++) + cin >> b[i], b[i]++; + for (int i = 0; i < n; i++) + cin >> c[i], c[i]++; + + for (int i = 0; i < n; i++) + s[a[i]]++; //a[i]出现数字的次数被统计。 + for (int i = 1; i < N; i++) + s[i] += s[i - 1]; //1到i为止的出现的总次数 + for (int i = 0; i < n; i++) + sa[i] = s[b[i] - 1]; //1-b[i]的从次数 + + memset(s, 0, sizeof s); + + for (int i = 0; i < n; i++) + s[c[i]]++; + for (int i = 1; i < N; i++) + s[i] += s[i - 1]; + for (int i = 0; i < n; i++) + sc[i] = s[N - 1] - s[b[i]]; //n到b[i]的总次数 + + LL res = 0; + for (int i = 0; i <= n; i++) + res += (LL)sa[i] * sc[i]; + cout << res; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\224\246\346\240\207\350\265\233/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\224\246\346\240\207\350\265\233/desc.md" index e69de29bb..910382e04 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\224\246\346\240\207\350\265\233/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\224\246\346\240\207\350\265\233/desc.md" @@ -0,0 +1,13 @@ +如果要在n个数据中挑选出第一大和第二大的数据(要求输出数据所在位置和值),使用什么方法比较的次数最少?我们可以从体育锦标赛中受到启发。 + +如图所示,8个选手的锦标赛,先两两捉对比拼,淘汰一半。优胜者再两两比拼...直到决出第一名。 + +第一名输出后,只要对黄色标示的位置重新比赛即可。 + +![](https://img-blog.csdn.net/20180325224626876) + +下面的代码实现了这个算法(假设数据中没有相同值)。 + +代码中需要用一个数组来表示图中的树(注意,这是个满二叉树,不足需要补齐)。它不是存储数据本身,而是存储了数据的下标。 + +第一个数据输出后,它所在的位置被标识为-1 diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\224\246\346\240\207\350\265\233/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\224\246\346\240\207\350\265\233/solution.cpp" index e69de29bb..3ed1fa9b9 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\224\246\346\240\207\350\265\233/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\224\246\346\240\207\350\265\233/solution.cpp" @@ -0,0 +1,100 @@ +#include +#include +#include +//重新决出k号位置,v为已输出值 +void pk(int *a, int *b, int n, int k, int v) +{ + //左子树 + int k1 = k * 2 + 1; + //右子树 + int k2 = k1 + 1; + + if (k1 >= n || k2 >= n) + { + b[k] = -1; + return; + } + + if (b[k1] == v) + pk(a, b, n, k1, v); + else + pk(a, b, n, k2, v); + + //重新比较 + if (b[k1] < 0) + { + if (b[k2] >= 0) + b[k] = b[k2]; + else + b[k] = -1; + return; + } + + if (b[k2] < 0) + { + if (b[k1] >= 0) + b[k] = b[k1]; + else + b[k] = -1; + return; + } + + if (b[k1] > b[k2]) //填空 + b[k] = b[k1]; + else + b[k] = b[k2]; +} + +//对a中数据,输出最大,次大元素位置和值 +void f(int *a, int len) +{ + int n = 1; + while (n < len) + n *= 2; + + int *b = (int *)malloc(sizeof(int *) * (2 * n - 1)); + int i; + for (i = 0; i < n; i++) + { + if (i < len) + b[n - 1 + i] = i; + else + b[n - 1 + i] = -1; + } + + //从最后一个向前处理 + for (i = 2 * n - 1 - 1; i > 0; i -= 2) + { + if (b[i] < 0) + { + if (b[i - 1] >= 0) + b[(i - 1) / 2] = b[i - 1]; + else + b[(i - 1) / 2] = -1; + } + else + { + if (a[b[i]] > a[b[i - 1]]) + b[(i - 1) / 2] = b[i]; + else + b[(i - 1) / 2] = b[i - 1]; + } + } + + //输出树根 + printf("%d : %d\n", b[0], a[b[0]]); + + //值等于根元素的需要重新pk + pk(a, b, 2 * n - 1, 0, b[0]); + + //再次输出树根 + printf("%d : %d\n", b[0], a[b[0]]); + + free(b); +} + +int main() +{ + int a[] = {54, 55, 18, 16, 122, 17, 30, 9, 58}; + f(a, 9); +} \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\227\250\347\211\214\345\210\266\344\275\234/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\227\250\347\211\214\345\210\266\344\275\234/desc.md" index e69de29bb..203fdd491 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\227\250\347\211\214\345\210\266\344\275\234/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\227\250\347\211\214\345\210\266\344\275\234/desc.md" @@ -0,0 +1,4 @@ +小蓝要为一条街的住户制作门牌号。 +这条街一共有 2020 位住户,门牌号从 1 到 2020 编号。 +小蓝制作门牌的方法是先制作 0 到 9 这几个数字字符,最后根据需要将字符粘贴到门牌上,例如门牌 1017 需要依次粘贴字符 1、0、1、7,即需要 1 个字符 0,2 个字符 1,1 个字符 7。 +请问要制作所有的 1 到 2020 号门牌,总共需要多少个字符 2? diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\227\250\347\211\214\345\210\266\344\275\234/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\227\250\347\211\214\345\210\266\344\275\234/solution.cpp" index e69de29bb..1e8513c82 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\227\250\347\211\214\345\210\266\344\275\234/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\227\250\347\211\214\345\210\266\344\275\234/solution.cpp" @@ -0,0 +1,24 @@ +#include +using namespace std; + +int ans; +int cal(int n) +{ + int sum = 0; + while (n) + { + if (n % 10 == 2) + sum++; + n /= 10; + } + return sum; +} +int main() +{ + for (int i = 1; i <= 2020; i++) + { + ans += cal(i); + } + cout << ans << endl; + return 0; +} \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\242\240\345\200\222\347\232\204\344\273\267\347\211\214/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\242\240\345\200\222\347\232\204\344\273\267\347\211\214/desc.md" index e69de29bb..dde4ebd4c 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\242\240\345\200\222\347\232\204\344\273\267\347\211\214/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\242\240\345\200\222\347\232\204\344\273\267\347\211\214/desc.md" @@ -0,0 +1,10 @@ +小李的店里专卖其它店中下架的样品电视机,可称为:样品电视专卖店。 +其标价都是4位数字(即千元不等)。 +小李为了标价清晰、方便,使用了预制的类似数码管的标价签,只要用颜色笔涂数字就可以了(参见图片)。 +![](https://img-blog.csdnimg.cn/20200315215554485.png) +这种价牌有个特点,对一些数字,倒过来看也是合理的数字。如:1 2 5 6 8 9 0 都可以。这样一来,如果牌子挂倒了,有可能完全变成了另一个价格,比如:1958 倒着挂就是:8561,差了几千元啊!! +当然,多数情况不能倒读,比如,1110 就不能倒过来,因为0不能作为开始数字。 +有一天,悲剧终于发生了。某个店员不小心把店里的某两个价格牌给挂倒了。并且这两个价格牌的电视机都卖出去了! +庆幸的是价格出入不大,其中一个价牌赔了2百多,另一个价牌却赚了8百多,综合起来,反而多赚了558元。 + +请根据这些信息计算:赔钱的那个价牌正确的价格应该是多少? diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\242\240\345\200\222\347\232\204\344\273\267\347\211\214/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\242\240\345\200\222\347\232\204\344\273\267\347\211\214/solution.cpp" index e69de29bb..7f775b8b9 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\242\240\345\200\222\347\232\204\344\273\267\347\211\214/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\242\240\345\200\222\347\232\204\344\273\267\347\211\214/solution.cpp" @@ -0,0 +1,84 @@ +#include +#include +#include +using namespace std; + +void i2s(int num, string &str) +{ //将数字转换为字符串 + stringstream ss; //用法类似于cout + ss << num; //>>是将那个num传入到stringstream中 + ss >> str; //用stringstream 类的函数str() 将对象所包含的内容赋给一个string对象。 +} + +void s2i(string &str, int &num) +{ + stringstream ss; //将字符串反转为数字 + ss << str; + ss >> num; +} +char to(char x) +{ //字符的翻转 + if (x == '6') + return '9'; + else if (x == '9') + return '6'; + else + return x; //x:指0,1,2,5,8,这几个数字反转后还是本身 +} + +string reserve(const string &str) +{ //reserve作用类似旋转180° + string ans; //结果 + for (int i = 3; i >= 0; i--) + { //扫描,从最后一位开始转换之后 + ans.insert(ans.end(), to(str[i])); //把最后一个字符插入 + } + return ans; +} +struct price +{ //定义一个价格的结构体 + int a, b, c; //a:原始价格 ,b:翻转颠倒价格,c:原始价格与颠倒价格的差 +}; +vector v1; //存储-200多的 +vector v2; //存储+800多的 +int main() +{ + cout << reserve << endl; //在这个地方可以测试原题中给出的数据 + //枚举所有可以颠倒的四位数 + // 将其颠倒过来,与原来的数值做差,将-200多与800多记录下来,分别记录在两个集合中 + //遍历两个集合,-200多和800多两两求和,结果为558的即为正确答案 + for (int i = 1000; i < 10000; i++) + { + string str; + i2s(i, str); + if (str.find('3') != string::npos || str.find('4') != string::npos || str.find('7') != string::npos || str.rfind('0') == 3) + //str里面是i的字符串形式,里面的3,4,7,还有最后一位也就是数组第4位不能为0 + continue; + string r = reserve(str); //翻转的字符 + int r_int; + s2i(r, r_int); //r_int就是翻转后的价格,i是原始价格 + int plus = r_int - i; //plus就是价格差 + if (plus > -300 && plus < -200) + { //价格范围 + price p = {i, r_int, plus}; + v1.push_back(p); + } + else if (plus > 800 && plus < 900) + { //价格范围 + price p = {i, r_int, plus}; + v2.push_back(p); + } + //此时v1存储-200多的价格,v2存储+800多 + for (int i = 0; i < v1.size(); i++) + { + for (int j = 0; j < v2.size(); j++) + { + if (v1[i].c + v2[j].c == 558) + { + printf("%d %d %d %d %d %d\n", v1[i].a, v1[i].b, v1[i].c, v2[j].a, v2[j].b, v2[j].c); + } + } + } + } + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\245\256\346\226\231\346\215\242\350\264\255/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\245\256\346\226\231\346\215\242\350\264\255/desc.md" index e69de29bb..0f3ca923a 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\245\256\346\226\231\346\215\242\350\264\255/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\245\256\346\226\231\346\215\242\350\264\255/desc.md" @@ -0,0 +1,24 @@ +乐羊羊饮料厂正在举办一次促销优惠活动。乐羊羊C型饮料,凭3个瓶盖可以再换一瓶C型饮料,并且可以一直循环下去(但不允许暂借或赊账)。 + +请你计算一下,如果小明不浪费瓶盖,尽量地参加活动,那么,对于他初始买入的n瓶饮料,最后他一共能喝到多少瓶饮料。 + +输入:一个整数n,表示开始购买的饮料数量(0 +int main() +{ + int n, t; + scanf("%d", &n); + int pin = n, gai = n; //p为瓶数 g为盖数 + while (gai / 3 != 0) + { + pin = pin + (gai / 3); + t = gai; + gai = (gai % 3) + (gai / 3); //换取的陪瓶子加上上次剩余的瓶盖 + } + printf("%d", pin); + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\253\230\346\226\257\346\227\245\350\256\260/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\253\230\346\226\257\346\227\245\350\256\260/desc.md" index e69de29bb..46068ea51 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\253\230\346\226\257\346\227\245\350\256\260/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\253\230\346\226\257\346\227\245\350\256\260/desc.md" @@ -0,0 +1,19 @@ +大数学家高斯有个好习惯:无论如何都要记日记。 + +他的日记有个与众不同的地方,他从不注明年月日,而是用一个整数代替,比如:4210 + + +后来人们知道,那个整数就是日期,它表示那一天是高斯出生后的第几天。这或许也是个好习惯,它时时刻刻提醒着主人:日子又过去一天,还有多少时光可以用于浪费呢? + + +高斯出生于:1777年4月30日。 + +在高斯发现的一个重要定理的日记上标注着:5343,因此可算出那天是:1791年12月15日。 + + +高斯获得博士学位的那天日记上标着:8113 + + +请你算出高斯获得博士学位的年月日。 +#### 输出格式 +提交答案的格式是:yyyy-mm-dd, 例如:1980-03-21 \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\253\230\346\226\257\346\227\245\350\256\260/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\253\230\346\226\257\346\227\245\350\256\260/solution.cpp" index e69de29bb..2517e3bee 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\253\230\346\226\257\346\227\245\350\256\260/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\253\230\346\226\257\346\227\245\350\256\260/solution.cpp" @@ -0,0 +1,48 @@ +#include + +using namespace std; + +int y = 1777, m = 4, d = 30; +int days = 8113 - 1; + +int leap(int n) +{ + return n % 400 == 0 || n % 100 != 0 && n % 4 == 0; +} + +int main() +{ + while (days--) + { + d++; + if (m == 12 && d == 32) + { + y++, m = 1, d = 1; + continue; + } + if ((m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10) && d == 32) + { + m++, d = 1; + continue; + } + if ((m == 4 || m == 6 || m == 9 || m == 11) && d == 31) + { + m++, d = 1; + continue; + } + if (m == 2 && leap(y) && d == 30) + { + m++, d = 1; + continue; + } + if (m == 2 && !leap(y) && d == 29) + { + m++, d = 1; + continue; + } + } + + cout << y << " " << m << " " << d << endl; + + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\255\224\346\226\271\346\250\241\346\213\237/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\255\224\346\226\271\346\250\241\346\213\237/desc.md" index e69de29bb..e5943c92e 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\255\224\346\226\271\346\250\241\346\213\237/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\255\224\346\226\271\346\250\241\346\213\237/desc.md" @@ -0,0 +1,53 @@ +魔方可以对它的6个面自由旋转。 +我们来操作一个2阶魔方(如图所示): + +为了描述方便,我们为它建立了坐标系。 + +各个面的初始状态如下: +``` +x轴正向:绿 +x轴反向:蓝 +y轴正向:红 +y轴反向:橙 +z轴正向:白 +z轴反向:黄 +``` +假设我们规定,只能对该魔方进行3种操作。分别标记为: +``` +x 表示在x轴正向做顺时针旋转 +y 表示在y轴正向做顺时针旋转 +z 表示在z轴正向做顺时针旋转 +``` +xyz 则表示顺序执行x,y,z 3个操作 +![](https://img-blog.csdn.net/20170113214548029) + +![](https://img-blog.csdn.net/20170113214552070) + +![](https://img-blog.csdn.net/20170113214558404) + +![](https://img-blog.csdn.net/20170113214602149) + +题目的要求是: +从标准输入获得一个串,表示操作序列。 +程序输出:距离我们最近的那个小方块的3个面的颜色。 +顺序是:x面,y面,z面。 + +例如:在初始状态,应该输出: +绿红白 + +初始状态下,如果用户输入: +``` +x +``` +则应该输出: +``` +绿白橙 +``` +初始状态下,如果用户输入: +``` +zyx +``` +则应该输出: +``` +红白绿 +``` \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\255\224\346\226\271\346\250\241\346\213\237/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\255\224\346\226\271\346\250\241\346\213\237/solution.cpp" index e69de29bb..cc3a03f0d 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\255\224\346\226\271\346\250\241\346\213\237/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\255\224\346\226\271\346\250\241\346\213\237/solution.cpp" @@ -0,0 +1,108 @@ +#include +#include +#include +#include +using namespace std; +int a[6][4]; +int b[6][4]; +void init() +{ + for (int i = 0; i < 6; ++i) + for (int j = 0; j < 4; ++j) + b[i][j] = a[i][j]; +} +void color(int c) //根据数字输出颜色 +{ + switch (c) + { + case 0: + cout << "绿"; + break; + case 1: + cout << "蓝"; + break; + case 2: + cout << "红"; + break; + case 3: + cout << "橙"; + break; + case 4: + cout << "白"; + break; + case 5: + cout << "黄"; + break; + } +} +void solveX() //x旋转 +{ + a[2][0] = b[4][0]; + a[2][1] = b[4][1]; + a[3][0] = b[5][3]; + a[3][1] = b[5][2]; + a[4][0] = b[3][0]; + a[4][1] = b[3][1]; + a[5][2] = b[2][1]; + a[5][3] = b[2][0]; + + a[0][0] = b[0][1]; + a[0][1] = b[0][3]; + a[0][2] = b[0][0]; + a[0][3] = b[0][2]; +} +void solveY() //y旋转 +{ + a[1][1] = b[4][1]; + a[1][3] = b[4][3]; + a[4][1] = b[0][1]; + a[4][3] = b[0][3]; + a[0][1] = b[5][1]; + a[0][3] = b[5][3]; + a[5][1] = b[1][1]; + a[5][3] = b[1][3]; + + a[2][0] = b[2][1]; + a[2][1] = b[2][3]; + a[2][2] = b[2][0]; + a[2][3] = b[2][2]; +} +void solveZ() //z旋转 +{ + a[0][2] = b[2][0]; + a[0][3] = b[2][2]; + a[2][0] = b[1][1]; + a[2][2] = b[1][0]; + a[1][0] = b[3][1]; + a[1][1] = b[3][3]; + a[3][1] = b[0][3]; + a[3][3] = b[0][2]; + + a[4][0] = b[4][1]; + a[4][1] = b[4][3]; + a[4][2] = b[4][0]; + a[4][3] = b[4][2]; +} + +int main() +{ + for (int i = 0; i < 6; ++i) //初始化颜色 + for (int j = 0; j < 4; ++j) + a[i][j] = i; + string s; + cin >> s; + for (int i = 0; i < s.size(); ++i) + { + init(); //b数组存储的颜色是a旋转前的颜色 + if (s[i] == 'x') + solveX(); + else if (s[i] == 'y') + solveY(); + else if (s[i] == 'z') + solveZ(); + } + color(a[0][3]); + color(a[2][0]); + color(a[4][1]); + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\255\224\346\226\271\347\212\266\346\200\201/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\255\224\346\226\271\347\212\266\346\200\201/desc.md" index e69de29bb..a7e608771 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\255\224\346\226\271\347\212\266\346\200\201/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\255\224\346\226\271\347\212\266\346\200\201/desc.md" @@ -0,0 +1,20 @@ +二阶魔方就是只有2层的魔方,只由8个小块组成。 + +小明很淘气,他只喜欢3种颜色,所有把家里的二阶魔方重新涂了颜色,如下: +``` +前面:橙色 + +右面:绿色 + +上面:黄色 + +左面:绿色 + +下面:橙色 + +后面:黄色 +``` +请你计算一下,这样的魔方被打乱后,一共有多少种不同的状态? +如果两个状态经过魔方的整体旋转后,各个面的颜色都一致,则认为是同一状态。 + +![](https://img-blog.csdnimg.cn/20201110192355364.png#pic_center) \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\255\224\346\226\271\347\212\266\346\200\201/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\255\224\346\226\271\347\212\266\346\200\201/solution.cpp" index e69de29bb..27b9c769d 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\255\224\346\226\271\347\212\266\346\200\201/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\255\224\346\226\271\347\212\266\346\200\201/solution.cpp" @@ -0,0 +1,160 @@ +#include +using namespace std; +typedef char st[8][7]; +st state[2000000]; +set all; +st begin = {{"oybbgb"}, {"oygbbb"}, {"bygbby"}, {"bybbgy"}, {"obbogb"}, {"obgobb"}, {"bbgoby"}, {"bbbogy"}}; +//st begin={{"oooooo"},{"oooooo"},{"oooooo"},{"oooooo"},{"oooooo"},{"oooooo"},{"oooooo"},{"oooooo"}}; +//只有一个颜色的魔方 ans=1 +//st begin={{"rykkbk"},{"rygkkk"},{"kygkko"},{"kykkbo"},{"rkkwbk"},{"rkgwkk"},{"kkgwko"},{"kkkwbo"}}; +//正常2阶魔方状态 r红 y黄 b蓝 g绿 w白 o橙 k黑(红对橙,白对黄,蓝对绿,颜色相近的相对)这里白为底 前为红 +//需要将state大小改为4000000 +//这个测试用例跑了20分钟左右 560M内存 ans=3674160 与实际二阶魔方状态数相同 见下截图 +int front, tail; +void ucell(char *a) +{ + swap(a[0], a[2]); + swap(a[2], a[5]); + swap(a[5], a[4]); +} +void rcell(char *a) +{ + swap(a[1], a[0]); + swap(a[0], a[3]); + swap(a[3], a[5]); +} +void fcell(char *a) +{ + swap(a[2], a[1]); + swap(a[1], a[4]); + swap(a[4], a[3]); +} +void u(st &s) //顶层顺时针旋转 +{ + ucell(s[0]); + ucell(s[1]); + ucell(s[2]); + ucell(s[3]); + swap(s[1], s[0]); + swap(s[2], s[1]); + swap(s[3], s[2]); +} +void uwhole(st &s) //整个魔方从顶部看 顺时针转 用于判重 +{ + u(s); + ucell(s[4]); + ucell(s[5]); + ucell(s[6]); + ucell(s[7]); + swap(s[5], s[4]); + swap(s[6], s[5]); + swap(s[7], s[6]); +} +void f(st &s) //前面一层 顺时针转 +{ + fcell(s[0]); + fcell(s[1]); + fcell(s[4]); + fcell(s[5]); + swap(s[1], s[5]); + swap(s[0], s[1]); + swap(s[4], s[0]); +} +void fwhole(st &s) //整个魔方从前面看 顺时针转 用于判重 +{ + f(s); + fcell(s[2]); + fcell(s[6]); + fcell(s[7]); + fcell(s[3]); + swap(s[2], s[6]); + swap(s[3], s[2]); + swap(s[7], s[3]); +} +void r(st &s) //魔方右层顺时针转 +{ + rcell(s[1]); + rcell(s[2]); + rcell(s[6]); + rcell(s[5]); + swap(s[2], s[1]); + swap(s[5], s[1]); + swap(s[6], s[5]); +} +void rwhole(st &s) //整个魔方从右边看 顺时针转 用于判重 +{ + r(s); + rcell(s[0]); + rcell(s[3]); + rcell(s[4]); + rcell(s[7]); + swap(s[3], s[7]); + swap(s[0], s[3]); + swap(s[4], s[0]); +} +string convert(st &s) //魔方状态二维字符数组 转化为string +{ + string ss; + for (int i = 0; i < 8; i++) + ss += s[i]; + return ss; +} +bool try_to_insert(int tail) //判重 +{ + st k; + memcpy((void *)k, (void *)state[tail], sizeof(state[tail])); + for (int i = 0; i < 4; i++) + { + fwhole(k); + for (int j = 0; j < 4; j++) + { + uwhole(k); + for (int q = 0; q < 4; q++) + { + rwhole(k); + if (all.count(convert(k)) == 1) + { + return false; + } + } + } + } + all.insert(convert(k)); + return true; +} +int main() +{ + front = 0, tail = 1; + all.insert(convert(begin)); + memcpy((void *)state[0], (void *)begin, sizeof(begin)); + while (front != tail) + { + //对当前状态分别模拟三种操作U R F 然后判重 + for (int i = 0; i < 3; i++) + { + memcpy((void *)state[tail], (void *)state[front], sizeof(state[front])); + if (i == 0) + { + u(state[tail]); + if (try_to_insert(tail)) + tail++; + } + else if (i == 1) + { + r(state[tail]); + if (try_to_insert(tail)) + tail++; + } + else if (i == 2) + { + f(state[tail]); + if (try_to_insert(tail)) + tail++; + } + } + front++; + } + cout << front << endl; + return 0; +} +//ans 229878 \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\273\204\351\207\221\350\277\236\345\210\206\346\225\260/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\273\204\351\207\221\350\277\236\345\210\206\346\225\260/desc.md" index e69de29bb..c0cf045c1 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\273\204\351\207\221\350\277\236\345\210\206\346\225\260/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\273\204\351\207\221\350\277\236\345\210\206\346\225\260/desc.md" @@ -0,0 +1,27 @@ +黄金分割数0.61803… 是个无理数,这个常数十分重要,在许多工程问题中会出现。有时需要把这个数字求得很精确。 +对于某些精密工程,常数的精度很重要。也许你听说过哈勃太空望远镜,它首次升空后就发现了一处人工加工错误,对那样一个庞然大物,其实只是镜面加工时有比头发丝还细许多倍的一处错误而已,却使它成了“近视眼”!! +言归正传,我们如何求得黄金分割数的尽可能精确的值呢?有许多方法。 +比较简单的一种是用连分数: +``` + 1 + 黄金数 = --------------------- + 1 + 1 + ----------------- + 1 + 1 + ------------- + 1 + 1 + --------- + 1 + ... + +``` + +这个连分数计算的“层数”越多,它的值越接近黄金分割数。 +请你利用这一特性,求出黄金分割数的足够精确值,要求四舍五入到小数点后100位。 +小数点后3位的值为:0.618 +小数点后4位的值为:0.6180 +小数点后5位的值为:0.61803 +小数点后7位的值为:0.6180340 +(注意尾部的0,不能忽略) +你的任务是:写出精确到小数点后100位精度的黄金分割值。 +注意:尾数的四舍五入! 尾数是0也要保留! +显然答案是一个小数,其小数点后有100位数字 diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\273\204\351\207\221\350\277\236\345\210\206\346\225\260/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\273\204\351\207\221\350\277\236\345\210\206\346\225\260/solution.cpp" index e69de29bb..2983c51b8 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\273\204\351\207\221\350\277\236\345\210\206\346\225\260/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\273\204\351\207\221\350\277\236\345\210\206\346\225\260/solution.cpp" @@ -0,0 +1,25 @@ +#include +using namespace std; + +typedef long long LL; + +void div(LL a, LL b, int end, int begin) //模拟手工除法 +{ + if (begin > end) + return; + int tmpans = a / b; + cout << tmpans; + div((a % b) * 10, b, end, begin + 1); +} + +int main() +{ + unsigned long long f[500] = {0, 1}; + + for (int i = 2; i < 100; i++) + f[i] = f[i - 1] + f[i - 2]; + + div(f[48], f[49], 100, 0); + + return 0; +} -- GitLab