<?xml version='1.0' encoding='UTF-8'?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/" version="2.0"><channel><title>Wellwei's Blog</title><link>https://wellwei.github.io</link><description>Wellwei's Blog</description><copyright>Wellwei's Blog</copyright><docs>http://www.rssboard.org/rss-specification</docs><generator>python-feedgen</generator><image><url>https://gitee.com/wellme/photo/raw/master/data/avatar.3yeeq64kqg.webp</url><title>avatar</title><link>https://wellwei.github.io</link></image><lastBuildDate>Mon, 30 Dec 2024 11:04:51 +0000</lastBuildDate><managingEditor>Wellwei's Blog</managingEditor><ttl>60</ttl><webMaster>Wellwei's Blog</webMaster><item><title>C++实现红黑树（插入、查找、删除）</title><link>https://wellwei.github.io/post/6.html</link><description>## C++实现红黑树（插入、查找、删除）&#13;
&#13;
### 红黑树性质&#13;
&#13;
- **所有节点都是红或黑色**&#13;
- **根节点是黑色**&#13;
- **每个叶子节点（NIL节点，或NULL）都是黑色**&#13;
- **红色节点的两个子节点都是黑色**（不会出现相邻的两个红色节点）。</description><guid isPermaLink="true">https://wellwei.github.io/post/6.html</guid><pubDate>Mon, 30 Dec 2024 11:02:19 +0000</pubDate></item><item><title>2024CAS第一次月赛题解</title><link>https://wellwei.github.io/post/4.html</link><description>## 难度一览&#13;
&#13;
- 简单题：[A](##a)、[D](##d)、[L](##l)&#13;
- 中等题：[B](##b)、[G](##g)、[H](##h)、[I](##i)、[M](##m)&#13;
- 难题：[E](##e)、[F](##f)、[J](##j)、[K](##k)&#13;
&#13;
## A&#13;
&#13;
题意：找到矩形的长和宽、利用最大公约数化简。</description><guid isPermaLink="true">https://wellwei.github.io/post/4.html</guid><pubDate>Sun, 03 Nov 2024 12:45:16 +0000</pubDate></item><item><title>24CAS招新机考题解</title><link>https://wellwei.github.io/post/3.html</link><description>### 前言&#13;
&#13;
有些同学可能对于多组测试样例不熟悉，这里解释一下&#13;
&#13;
题目中说了有t组测试样例的只需要先输入一个t，然后循环t次解题过程即可，例如：&#13;
&#13;
```cpp&#13;
void solve() {	// 该函数为主要解题处&#13;
    // 你的解题代码&#13;
}&#13;
int main() {&#13;
    int t;&#13;
    scanf('%d', &amp;t);	// T 组测试&#13;
    while (t--) solve();&#13;
    return 0;&#13;
}&#13;
```&#13;
&#13;
不存在t就代表程序要求你读入数据直到数据文件尾，这里要自行了解scanf函数的返回值以及EOF常量，例：&#13;
&#13;
```cpp&#13;
int main() {&#13;
    int n;&#13;
    while (scanf('%d', &amp;n) != EOF) {	如果==EOF就代表已经读入完了&#13;
        // 你的解题代码&#13;
    }&#13;
    return 0;&#13;
}&#13;
```&#13;
&#13;
还存在其他的多组测试样例，但是输入格式中都有描述可自行理解&#13;
&#13;
&#13;
&#13;
另外观察到部分同学可能在学习C语言过程中会对一些输入输出操作添加提示信息，例如&#13;
&#13;
```cpp&#13;
void solve() {&#13;
    int a, b;&#13;
    printf('请输入两个整数\n');	// 语句1&#13;
    scanf('%d%d', &amp;a ,&amp;b);&#13;
    printf('两个整数分别是：%d %d', a, b);	//语句2&#13;
}&#13;
```&#13;
&#13;
上例中语句1以及语句2中的提示语部分在算法题目中都是不背允许的，每个题目都严格要求了输入输出的格式，题目要你输出什么就输出什么，其他的内容都不要输出，否则Wrong Answer&#13;
&#13;
&#13;
&#13;
&#13;
&#13;
### A&#13;
&#13;
这个题目只需要用一个if语句判断 'a + b == c' 或者 'a - b == c' 这两个条件是否成立即可&#13;
&#13;
```cpp&#13;
void solve() {&#13;
	int a, b, c;&#13;
    scanf('%d%d%d', &amp;a, &amp;b, &amp;c);&#13;
	if (a - b == c) cout &lt;&lt; '-' &lt;&lt; endl;&#13;
	else cout &lt;&lt; '+' &lt;&lt; endl;&#13;
}&#13;
&#13;
int main() {&#13;
	int t ;&#13;
    scanf('%d', &amp;t);&#13;
	while(t--) solve();&#13;
	return 0;&#13;
}&#13;
```&#13;
&#13;
&#13;
&#13;
### B&#13;
&#13;
这题只需要用if语句判断多个逻辑表达式是否成立即可&#13;
&#13;
```cpp&#13;
void solve() {&#13;
	int a, b, c;&#13;
    scanf('%d%d%d', &amp;a, &amp;b, &amp;c);&#13;
	if (a + b == c || a + c == b || b + c == a) &#13;
        printf('YES');&#13;
	else printf('NO');&#13;
}&#13;
&#13;
int main() {&#13;
	int t; &#13;
    scanf('%d', &amp;t);&#13;
	while(t--) solve();&#13;
	return 0;&#13;
}&#13;
```&#13;
&#13;
&#13;
&#13;
&#13;
&#13;
### C&#13;
&#13;
跟上面两题一样只需要if判断条件是否成立&#13;
&#13;
```cpp&#13;
void solve() {&#13;
	int a, b, c;&#13;
    scanf('%d%d%d', &amp;a, &amp;b, &amp;c);&#13;
	if (a &lt; b &amp;&amp; b &lt; c) printf('STAIR\n');&#13;
    else if (a &lt; b &amp;&amp; b &gt; c) printf('PEAK\n');&#13;
    else printf('NONE\n');&#13;
}&#13;
&#13;
int main() {&#13;
	int t;&#13;
    scanf('%d', &amp;t);&#13;
	while(t--) solve();&#13;
	return 0;&#13;
}&#13;
```&#13;
&#13;
&#13;
&#13;
&#13;
&#13;
### D&#13;
&#13;
只需要判断哪个数字没有出现即可&#13;
&#13;
```cpp&#13;
void solve() {&#13;
	int a, b;&#13;
    scanf('%d%d', &amp;a, &amp;b);&#13;
    if (a != 1 &amp;&amp; b != 1) printf('1\n');&#13;
    else if (a != 2 &amp;&amp; b != 2) printf('2\n');&#13;
    else printf('3\n');&#13;
}&#13;
&#13;
int main() {&#13;
	int t = 1;&#13;
	while(t--) solve();&#13;
	return 0;&#13;
}&#13;
```&#13;
&#13;
&#13;
&#13;
### E&#13;
&#13;
这个题目需要推一下公式，通过观察对称，可以发现 $ a[i][j] $ 与 $a[2 - i][2 - j]$  中心对称  (下标0-2)&#13;
&#13;
```cpp&#13;
void solve() {&#13;
    char a[3][3];&#13;
    scanf('%s%s%s', a[0], a[1], a[2]);&#13;
    for (int i = 0; i &lt; 3; i++) {&#13;
        for (int j = 0; j &lt; 3; j++) {&#13;
            if (a[i][j] != a[2 - i][2 - j]) {&#13;
                printf('NO\n');&#13;
                return;&#13;
            }&#13;
        }&#13;
    }&#13;
    printf('YES\n');&#13;
}&#13;
```&#13;
&#13;
&#13;
&#13;
&#13;
&#13;
### F&#13;
&#13;
观察到要牌数最小那么就只能用4，那么只需要对 $n/4$  向上取整即可&#13;
&#13;
```cpp&#13;
#include &lt;math.h&gt;&#13;
&#13;
void solve() {&#13;
    int n;&#13;
    scanf('%d', &amp;n);&#13;
    printf('%d\n', ceil(n / 4.0));		// ceil函数向上取整，可自行百度&#13;
    									// 也可以自己编码实现该功能&#13;
}&#13;
&#13;
int main() {&#13;
	int t;&#13;
    scanf('%d', &amp;t);&#13;
	while(t--) solve();&#13;
	return 0;&#13;
}&#13;
```&#13;
&#13;
&#13;
&#13;
&#13;
&#13;
### G&#13;
&#13;
该题涉及排序操作，根据id和总成绩进行双关键字排序然后循环查找id为1的输出即可（C语言的qsort、C++的sort都可轻松实现）&#13;
&#13;
```cpp&#13;
struct sc {&#13;
    int id;&#13;
    int sum;&#13;
} arr[1010];&#13;
&#13;
void selectionSort(int n) {     // 执行选择排序&#13;
    for (int i = 0; i &lt; n - 1; i++) {&#13;
        int maxIdx = i;&#13;
        for (int j = i + 1; j &lt; n; j++) {&#13;
            // 按总成绩降序排列，如果总成绩相同则按id升序排列&#13;
            if (arr[j].sum &gt; arr[maxIdx].sum || &#13;
                (arr[j].sum == arr[maxIdx].sum &amp;&amp; arr[j].id &lt; arr[maxIdx].id)) {&#13;
                maxIdx = j;&#13;
            }&#13;
        }&#13;
        // 交换当前元素和找到的最大元素&#13;
        if (maxIdx != i) {&#13;
            sc temp = arr[i];&#13;
            arr[i] = arr[maxIdx];&#13;
            arr[maxIdx] = temp;&#13;
        }&#13;
    }&#13;
}&#13;
&#13;
void solve() {&#13;
    int n;&#13;
    scanf('%d', &amp;n);&#13;
    int a, b, c, d;&#13;
    for (int i = 0; i &lt; n; i++) {&#13;
        scanf('%d%d%d%d', &amp;a, &amp;b, &amp;c, &amp;d);&#13;
        arr[i].id = i;&#13;
        arr[i].sum = a + b + c + d;&#13;
    }&#13;
    selectionSort(n);&#13;
    for (int i = 0; i &lt; n; i++) {&#13;
        if (arr[i].id == 0) {&#13;
            printf('%d\n', i + 1);&#13;
            break;&#13;
        }&#13;
    }&#13;
}&#13;
```&#13;
&#13;
&#13;
&#13;
&#13;
&#13;
### H&#13;
&#13;
关键的观察是 $i^i$ 的奇偶性与 $i$ 相同。</description><guid isPermaLink="true">https://wellwei.github.io/post/3.html</guid><pubDate>Mon, 07 Oct 2024 09:22:51 +0000</pubDate></item><item><title>CAS新同学须知</title><link>https://wellwei.github.io/post/2.html</link><description># CAS新同学须知&#13;
&#13;
亲爱的新同学们:&#13;
&#13;
欢迎了解加入我们的CAS协会!为了帮助大家更好地了解协会并开始学习,请仔细阅读以下重要信息:&#13;
&#13;
## 1. 群备注修改&#13;
&#13;
请所有大一新生将QQ群备注修改为:年级+专业+班级+姓名&#13;
例如:24网工一班何志宏&#13;
&#13;
这样可以方便我们统计作业情况。</description><guid isPermaLink="true">https://wellwei.github.io/post/2.html</guid><pubDate>Thu, 19 Sep 2024 14:45:00 +0000</pubDate></item></channel></rss>