'commit'
This commit is contained in:
BIN
TangDou/LanQiaoBei/LanQiao12XuanBaSaiZhongJi/3.jpg
Normal file
BIN
TangDou/LanQiaoBei/LanQiao12XuanBaSaiZhongJi/3.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 57 KiB |
24
TangDou/LanQiaoBei/LanQiao12XuanBaSaiZhongJi/3_1.cpp
Normal file
24
TangDou/LanQiaoBei/LanQiao12XuanBaSaiZhongJi/3_1.cpp
Normal file
@@ -0,0 +1,24 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
|
||||
// 数位递增数
|
||||
bool dzs(string s) {
|
||||
for (int i = 0; i < s.size() - 1; i++)
|
||||
if (s[i] > s[i + 1]) return false;
|
||||
return true;
|
||||
}
|
||||
/*
|
||||
25
|
||||
|
||||
答案:13
|
||||
*/
|
||||
int main() {
|
||||
int n;
|
||||
cin >> n;
|
||||
int cnt = 0;
|
||||
for (int i = 11; i <= n; i++)
|
||||
if (dzs(to_string(i))) cnt++;
|
||||
|
||||
printf("%d\n", cnt);
|
||||
return 0;
|
||||
}
|
||||
25
TangDou/LanQiaoBei/LanQiao12XuanBaSaiZhongJi/3_2.cpp
Normal file
25
TangDou/LanQiaoBei/LanQiao12XuanBaSaiZhongJi/3_2.cpp
Normal file
@@ -0,0 +1,25 @@
|
||||
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
// 123
|
||||
bool dzs(int x) {
|
||||
int p = 10;
|
||||
while (x) {
|
||||
if (x % 10 > p) return false;
|
||||
p = x % 10;
|
||||
x /= 10;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
int n, cnt;
|
||||
|
||||
int main() {
|
||||
cin >> n;
|
||||
for (int i = 11; i <= n; i++)
|
||||
if (dzs(i)) cnt++;
|
||||
|
||||
printf("%d\n", cnt);
|
||||
return 0;
|
||||
}
|
||||
34
TangDou/LanQiaoBei/LanQiao12XuanBaSaiZhongJi/4.cpp
Normal file
34
TangDou/LanQiaoBei/LanQiao12XuanBaSaiZhongJi/4.cpp
Normal file
@@ -0,0 +1,34 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
int w, m, n;
|
||||
/*
|
||||
测试用例:
|
||||
6 8 2
|
||||
答案:4
|
||||
*/
|
||||
//计算点的行号
|
||||
int row(int i) {
|
||||
if (i % w == 0) //值是宽度的倍数
|
||||
return i / w;
|
||||
else //值不是宽度的倍数
|
||||
return i / w + 1;
|
||||
}
|
||||
//计算点的列号
|
||||
int col(int i) {
|
||||
if (row(i) % 2 == 0) { //该值在偶数行
|
||||
if (i % w == 0) // 找规律可知,偶数行能被整除肯定在第一列
|
||||
return 1;
|
||||
//在偶数行(从大到小)但不能被整除,在倒数第j%w列,即正数第w-j%w+1列
|
||||
return w - i % w + 1;
|
||||
} else { //在奇数行
|
||||
if (i % w == 0) return w; //找规律可知,偶数行能被整除肯定在最后一列
|
||||
return i % w; //在奇数行(从小到大)但不能被整除,在第j%w列
|
||||
}
|
||||
}
|
||||
int main() {
|
||||
cin >> w >> m >> n;
|
||||
int s = abs(row(n) - row(m)) + abs(col(n) - col(m));
|
||||
printf("%d\n", s);
|
||||
return 0;
|
||||
}
|
||||
BIN
TangDou/LanQiaoBei/LanQiao12XuanBaSaiZhongJi/4.jpg
Normal file
BIN
TangDou/LanQiaoBei/LanQiao12XuanBaSaiZhongJi/4.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 40 KiB |
30
TangDou/LanQiaoBei/LanQiao12XuanBaSaiZhongJi/5.cpp
Normal file
30
TangDou/LanQiaoBei/LanQiao12XuanBaSaiZhongJi/5.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
int n, m;
|
||||
const int N = 110;
|
||||
int res;
|
||||
int a[N];
|
||||
|
||||
void dfs(int u) {
|
||||
if (u == n + 1) {
|
||||
int sum = 0;
|
||||
for (int i = 1; i <= n; i++) sum += a[i];
|
||||
if (sum == m) {
|
||||
res++;
|
||||
}
|
||||
return;
|
||||
}
|
||||
for (int i = a[u - 1]; i >= 1; i--) {
|
||||
a[u] += i;
|
||||
dfs(u + 1);
|
||||
a[u] -= i;
|
||||
}
|
||||
}
|
||||
int main() {
|
||||
cin >> n >> m;
|
||||
a[0] = m;
|
||||
dfs(1);
|
||||
cout << res << endl;
|
||||
return 0;
|
||||
}
|
||||
BIN
TangDou/LanQiaoBei/LanQiao12XuanBaSaiZhongJi/5.jpg
Normal file
BIN
TangDou/LanQiaoBei/LanQiao12XuanBaSaiZhongJi/5.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 24 KiB |
23
TangDou/LanQiaoBei/LanQiao12XuanBaSaiZhongJi/HuanYinLiao.cpp
Normal file
23
TangDou/LanQiaoBei/LanQiao12XuanBaSaiZhongJi/HuanYinLiao.cpp
Normal file
@@ -0,0 +1,23 @@
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
int n; // 换回来的饮料数量
|
||||
int sum; // 喝到总数
|
||||
int t; // 空瓶数量
|
||||
|
||||
int main() {
|
||||
cin >> n;
|
||||
|
||||
while (n) {
|
||||
//① 统计上轮结果
|
||||
sum += n; // 上轮换回来的可以喝到
|
||||
t += n; // 当前手中酒瓶 = 原空瓶数量+上轮换回
|
||||
|
||||
//② 本轮换取开始
|
||||
n = t / 3; // 换回来的饮料数量
|
||||
t %= 3; // 剩余空瓶
|
||||
}
|
||||
//输出
|
||||
printf("%d", sum);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
10
|
||||
75
TangDou/LanQiaoBei/LanQiao12XuanBaSaiZhongJi/HuanYinLiao.md
Normal file
75
TangDou/LanQiaoBei/LanQiao12XuanBaSaiZhongJi/HuanYinLiao.md
Normal file
@@ -0,0 +1,75 @@
|
||||
## 空瓶换饮料
|
||||
### 一、题目描述
|
||||
某饮料公司最近推出了一个 **空瓶换饮料** 的活动:如果你拥有$3$个空瓶就可以兑换一瓶饮料,初始你有 $n$ 瓶饮料,喝完后的空瓶可以继续用来兑换饮料。问总共可以喝到多少瓶饮料。
|
||||
|
||||
**输入格式**
|
||||
一行,$1$个整数$n$,表示初始饮料的数量($1 <= n <= 10^9$)。
|
||||
|
||||
**输出格式**
|
||||
一行,对应答案
|
||||
|
||||
**输入样例**
|
||||
$10$
|
||||
|
||||
**输出样例**
|
||||
$14$
|
||||
|
||||
### 二、解题思路
|
||||
人工描述测试用例,分析事情的步骤,再思考解决办法:
|
||||
|
||||
设 $sum$: 喝掉的总饮料数量
|
||||
|
||||
---
|
||||
- ① 手中有$10$瓶饮料,肯定要先喝掉$sum+=10$
|
||||
- ② 现在手中空瓶数量$10$,拿$10$个空瓶去换,$10/3=3$,可以换回$3$瓶饮料,剩余$10\%3=1$个空瓶
|
||||
|
||||
---
|
||||
- ③ 手中有$3$瓶饮料,肯定要先喝掉$sum+=3$
|
||||
- ④ 现在手中空瓶数量$1+3=4$,拿$4$个空瓶去换,$4/3=1$,可以换回$1$瓶饮料,剩余$4\%3=1$个空瓶
|
||||
|
||||
---
|
||||
|
||||
|
||||
- ⑤ 手中有$1$瓶饮料,肯定要先喝掉$sum+=1$
|
||||
|
||||
- 现在手中空瓶数量$1+1=2$,换不了了,结束
|
||||
**本质**:换回的数量为$0$时,结束。
|
||||
|
||||
#### 总结
|
||||
- 每轮发生的事情是一样的,可以把每轮的事情组装成一个循环的单元内容
|
||||
- 每轮的概念:
|
||||
- 换回的饮料数量 $n=n/3$ (可以直接喝掉)
|
||||
- 手中空瓶数量 $t=n\%3$
|
||||
- 对下轮影响:
|
||||
- 手中的空瓶可以转移到下轮
|
||||
|
||||
- 首次
|
||||
- 首次手中原有的数量,可以视为第$0$轮换回的数量
|
||||
- 首次手中空瓶的数量,可以视为$0$
|
||||
|
||||
### 三、实现代码
|
||||
```cpp {.line-numbers}
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
int n; // 换回来的饮料数量
|
||||
int sum; // 喝到总数
|
||||
int t; // 空瓶数量
|
||||
|
||||
int main() {
|
||||
cin >> n;
|
||||
|
||||
while (n) {
|
||||
//① 统计上轮结果
|
||||
sum += n; // 上轮换回来的可以喝到
|
||||
n += t; // 当前手中酒瓶 = 原空瓶数量+上轮换回
|
||||
|
||||
//② 本轮换取开始
|
||||
t = n % 3; // 剩余空瓶
|
||||
n /= 3; // 换回来的饮料数量
|
||||
}
|
||||
//输出
|
||||
printf("%d", sum);
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
BIN
TangDou/LanQiaoBei/LanQiao12XuanBaSaiZhongJi/HuanYinLiao.pdf
Normal file
BIN
TangDou/LanQiaoBei/LanQiao12XuanBaSaiZhongJi/HuanYinLiao.pdf
Normal file
Binary file not shown.
21
TangDou/LanQiaoBei/LanQiao12XuanBaSaiZhongJi/Pow2.cpp
Normal file
21
TangDou/LanQiaoBei/LanQiao12XuanBaSaiZhongJi/Pow2.cpp
Normal file
@@ -0,0 +1,21 @@
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
/*
|
||||
896
|
||||
|
||||
7
|
||||
*/
|
||||
int main() {
|
||||
int n;
|
||||
cin >> n;
|
||||
int b = 2;
|
||||
// n=8
|
||||
int cnt = 0;
|
||||
while (n % b == 0) {
|
||||
b *= 2;
|
||||
cnt++;
|
||||
}
|
||||
printf("%d", cnt);
|
||||
|
||||
return 0;
|
||||
}
|
||||
40
TangDou/LanQiaoBei/LanQiao12XuanBaSaiZhongJi/Pow2.md
Normal file
40
TangDou/LanQiaoBei/LanQiao12XuanBaSaiZhongJi/Pow2.md
Normal file
@@ -0,0 +1,40 @@
|
||||
## $2$的幂整除
|
||||
|
||||
### 一、题目描述
|
||||
给一个正整数$n$,计算它最多能被$2$的多少次幂整除
|
||||
|
||||
**输入格式**
|
||||
输入一个数 $n$
|
||||
|
||||
**输出格式**
|
||||
输出一个数
|
||||
|
||||
**输入样例**
|
||||
$896$
|
||||
|
||||
**输出样例**
|
||||
$7$
|
||||
|
||||
### 二、实现代码
|
||||
```cpp {.line-numbers}
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
/*
|
||||
896
|
||||
|
||||
7
|
||||
*/
|
||||
int main() {
|
||||
int n;
|
||||
cin >> n;
|
||||
int b = 2;
|
||||
int cnt = 0;
|
||||
while (n % b == 0) {
|
||||
b *= 2;
|
||||
cnt++;
|
||||
}
|
||||
printf("%d", cnt);
|
||||
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,23 @@
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
const int N = 110;
|
||||
int a[N], b[N];
|
||||
|
||||
int main() {
|
||||
int n;
|
||||
cin >> n;
|
||||
for (int i = 1; i <= n; i++)
|
||||
for (int j = 1; j <= n; j++) {
|
||||
int x;
|
||||
cin >> x;
|
||||
a[j] += x;
|
||||
b[i] += x;
|
||||
}
|
||||
for (int i = 1; i <= n; i++)
|
||||
if (a[i] != a[1] || b[i] != a[1]) {
|
||||
puts("NO");
|
||||
return 0;
|
||||
}
|
||||
puts("YES");
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
const int N = 110;
|
||||
int a[N][N];
|
||||
|
||||
int main() {
|
||||
int n;
|
||||
cin >> n;
|
||||
for (int i = 1; i <= n; i++)
|
||||
for (int j = 1; j <= n; j++)
|
||||
cin >> a[i][j];
|
||||
//首行累加和
|
||||
int s = 0;
|
||||
for (int i = 1; i <= n; i++) s += a[1][i];
|
||||
|
||||
//所有行进行判断
|
||||
for (int i = 1; i <= n; i++) {
|
||||
int t = 0;
|
||||
for (int j = 1; j <= n; j++) t += a[i][j];
|
||||
if (t != s) {
|
||||
puts("NO");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// 所有列进行判断
|
||||
for (int j = 1; j <= n; j++) {
|
||||
int t = 0;
|
||||
for (int i = 1; i <= n; i++) t += a[i][j];
|
||||
if (t != s) {
|
||||
puts("NO");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
puts("YES");
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
## 完美方阵
|
||||
|
||||
小明很喜欢矩阵,在他的心目中这样的矩阵能够被称为“完美方阵”:这个方阵的 $n$ 行与 $n$ 列当中,每行的数字之和必须相同,每列的数字之和也必须相同。
|
||||
|
||||
现在你找来一些方阵,你想知道小明是否愿称之为完美方阵。
|
||||
|
||||
**输入格式**
|
||||
第一行输入一个数 $n$ ,表示一个方阵的行列数;
|
||||
之后 $n$ 行,每行 $n$ 个数,表示方阵中的每个元素 ,以空格隔开;
|
||||
|
||||
**输出格式**
|
||||
若这个方阵是完美方阵,输出“$YES$”,否则输出“$NO$”。
|
||||
|
||||
**输入样例**
|
||||
```cpp {.line-numbers}
|
||||
3
|
||||
3 4 8
|
||||
7 2 6
|
||||
5 9 1
|
||||
```
|
||||
|
||||
**输出样例**
|
||||
```cpp {.line-numbers}
|
||||
YES
|
||||
```
|
||||
|
||||
|
||||
#### 原始AC版本
|
||||
```cpp {.line-numbers}
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
const int N = 110;
|
||||
int a[N][N];
|
||||
|
||||
int main() {
|
||||
int n;
|
||||
cin >> n;
|
||||
for (int i = 1; i <= n; i++)
|
||||
for (int j = 1; j <= n; j++)
|
||||
cin >> a[i][j];
|
||||
//首行累加和
|
||||
int s = 0;
|
||||
for (int i = 1; i <= n; i++) s += a[1][i];
|
||||
|
||||
//所有行进行判断
|
||||
for (int i = 1; i <= n; i++) {
|
||||
int t = 0;
|
||||
for (int j = 1; j <= n; j++) t += a[i][j];
|
||||
if (t != s) {
|
||||
puts("NO");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// 所有列进行判断
|
||||
for (int j = 1; j <= n; j++) {
|
||||
int t = 0;
|
||||
for (int i = 1; i <= n; i++) t += a[i][j];
|
||||
if (t != s) {
|
||||
puts("NO");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
puts("YES");
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
|
||||
#### 优化后版本
|
||||
```cpp {.line-numbers}
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
const int N = 110;
|
||||
int a[N], b[N];
|
||||
|
||||
int main() {
|
||||
int n;
|
||||
cin >> n;
|
||||
for (int i = 1; i <= n; i++)
|
||||
for (int j = 1; j <= n; j++) {
|
||||
int x;
|
||||
cin >> x;
|
||||
a[j] += x;
|
||||
b[i] += x;
|
||||
}
|
||||
for (int i = 1; i <= n; i++)
|
||||
if (a[i] != a[1] || b[i] != a[1]) {
|
||||
puts("NO");
|
||||
return 0;
|
||||
}
|
||||
puts("YES");
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
Reference in New Issue
Block a user