'commit'
This commit is contained in:
23
TangDou/LanQiaoBei/ZhongGaoJi/LanQiao15STEMA202312/10.cpp
Normal file
23
TangDou/LanQiaoBei/ZhongGaoJi/LanQiao15STEMA202312/10.cpp
Normal file
@@ -0,0 +1,23 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
int k;
|
||||
string kill(string s) {
|
||||
int p = s[s.size() - 1]; // 最后一位是默认值
|
||||
for (int i = 0; i < s.size() - 1; i++)
|
||||
if (s[i + 1] > s[i]) {
|
||||
p = i;
|
||||
break;
|
||||
}
|
||||
string res;
|
||||
for (int i = 0; i < s.size(); i++)
|
||||
if (i != p) res += s[i];
|
||||
return res;
|
||||
}
|
||||
|
||||
int main() {
|
||||
string s;
|
||||
cin >> s >> k;
|
||||
for (int i = 1; i <= k; i++) s = kill(s);
|
||||
cout << s << endl;
|
||||
return 0;
|
||||
}
|
||||
46
TangDou/LanQiaoBei/ZhongGaoJi/LanQiao15STEMA202312/11.cpp
Normal file
46
TangDou/LanQiaoBei/ZhongGaoJi/LanQiao15STEMA202312/11.cpp
Normal file
@@ -0,0 +1,46 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
const int N = 100010;
|
||||
vector<int> g[N]; // 邻接表,一个正图,一个反图
|
||||
int c[N]; // 每个树洞中松鼠的数量
|
||||
/*
|
||||
测试用例
|
||||
4
|
||||
5
|
||||
3
|
||||
6
|
||||
1
|
||||
1 2
|
||||
1 3
|
||||
2 4
|
||||
2
|
||||
*/
|
||||
int dfs(int u, int fa, int k) {
|
||||
if (k == 0) return c[u];
|
||||
int sum = c[u];
|
||||
for (int i = 0; i < g[u].size(); i++) {
|
||||
if (g[u][i] == fa) continue;
|
||||
sum += dfs(g[u][i], u, k - 1);
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
int main() {
|
||||
int n; // 树洞的数量
|
||||
cin >> n;
|
||||
|
||||
for (int i = 1; i <= n; i++) cin >> c[i]; // 每个树洞中松鼠的数量
|
||||
|
||||
for (int i = 1; i < n; i++) {
|
||||
int a, b; // 表示两个树洞相连接
|
||||
cin >> a >> b;
|
||||
g[a].push_back(b); // 用邻接表保存一下某个树洞与哪两个其它树洞相连接
|
||||
g[b].push_back(a);
|
||||
}
|
||||
|
||||
int k;
|
||||
cin >> k;
|
||||
for (int i = 1; i <= n; i++)
|
||||
cout << dfs(i, -1, k) << endl;
|
||||
return 0;
|
||||
}
|
||||
9
TangDou/LanQiaoBei/ZhongGaoJi/LanQiao15STEMA202312/11.in
Normal file
9
TangDou/LanQiaoBei/ZhongGaoJi/LanQiao15STEMA202312/11.in
Normal file
@@ -0,0 +1,9 @@
|
||||
4
|
||||
5
|
||||
3
|
||||
6
|
||||
1
|
||||
1 2
|
||||
1 3
|
||||
2 4
|
||||
2
|
||||
14
TangDou/LanQiaoBei/ZhongGaoJi/LanQiao15STEMA202312/5.cpp
Normal file
14
TangDou/LanQiaoBei/ZhongGaoJi/LanQiao15STEMA202312/5.cpp
Normal file
@@ -0,0 +1,14 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
int func(int x, int y, int z) {
|
||||
if (x == 1 || y == 1 || z == 1) return 1;
|
||||
if (x < y && x < z)
|
||||
return func(x, y - 1, z) + func(x, y, z - 1);
|
||||
if (y < x && y < z)
|
||||
return func(x - 1, y, z) + func(x, y, z - 1);
|
||||
return func(x - 1, y, z) + func(x, y - 1, z);
|
||||
}
|
||||
int main() {
|
||||
cout << func(3, 3, 2);
|
||||
return 0;
|
||||
}
|
||||
36
TangDou/LanQiaoBei/ZhongGaoJi/LanQiao15STEMA202312/5.md
Normal file
36
TangDou/LanQiaoBei/ZhongGaoJi/LanQiao15STEMA202312/5.md
Normal file
@@ -0,0 +1,36 @@
|
||||
```cpp {.line-numbers}
|
||||
int func( int x, int y, int z )
|
||||
{
|
||||
if( x == 1 || y == 1 || z == 1 ) return 1;
|
||||
if( x < y && x < z )
|
||||
return func( x, y - 1, z ) + func( x, y, z - 1 );
|
||||
if( y < x && y < z )
|
||||
return func( x - 1, y, z ) + func( x, y, z - 1 );
|
||||
return func( x - 1, y, z ) + func( x, y - 1, z );
|
||||
}
|
||||
int main()
|
||||
{
|
||||
cout << func( 3, 3, 2 );
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
将$func()$简写成$f()$
|
||||
|
||||
人脑模拟电脑
|
||||
|
||||
$f(3,3,2)=f(2,3,2)+f(3,2,2)$
|
||||
|
||||
其中
|
||||
$f(2,3,2)=f(1,3,2)+f(2,2,2)$ ①
|
||||
$f(3,2,2)=f(2,2,2)+f(3,1,2)$ ②
|
||||
|
||||
最终$res=①+②$
|
||||
|
||||
$f(1,3,2)=1$
|
||||
$f(2,2,2)=f(1,2,2)+f(2,1,2)=1+1=2$
|
||||
|
||||
$\therefore$ ①=3
|
||||
|
||||
②=3
|
||||
|
||||
①+②=6
|
||||
21
TangDou/LanQiaoBei/ZhongGaoJi/LanQiao15STEMA202312/7.cpp
Normal file
21
TangDou/LanQiaoBei/ZhongGaoJi/LanQiao15STEMA202312/7.cpp
Normal file
@@ -0,0 +1,21 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
|
||||
bool check(int x) {
|
||||
int sum = 0;
|
||||
while (x) {
|
||||
int a = x % 10;
|
||||
x /= 10;
|
||||
sum += a;
|
||||
}
|
||||
return sum % 2 == 0;
|
||||
}
|
||||
|
||||
int main() {
|
||||
int n, m;
|
||||
cin >> n >> m;
|
||||
for (int i = n; i <= m; i++)
|
||||
if (check(i))
|
||||
cout << i << endl;
|
||||
return 0;
|
||||
}
|
||||
26
TangDou/LanQiaoBei/ZhongGaoJi/LanQiao15STEMA202312/9.cpp
Normal file
26
TangDou/LanQiaoBei/ZhongGaoJi/LanQiao15STEMA202312/9.cpp
Normal file
@@ -0,0 +1,26 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
string s;
|
||||
cin >> s;
|
||||
|
||||
int m;
|
||||
cin >> m;
|
||||
m--;
|
||||
|
||||
while (m--) {
|
||||
string t;
|
||||
for (int i = 0; i < s.size(); i++) {
|
||||
int c = 1;
|
||||
while (i + 1 < s.size() && s[i + 1] == s[i]) {
|
||||
c++;
|
||||
i++;
|
||||
}
|
||||
t = t + to_string(c) + s[i];
|
||||
}
|
||||
s = t;
|
||||
}
|
||||
cout << s << endl;
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
const int N = 110;
|
||||
struct Node {
|
||||
int x, y;
|
||||
int c[10];
|
||||
} a[N];
|
||||
|
||||
int main() {
|
||||
a[0].x = 1;
|
||||
a[0].y = 2;
|
||||
a[0].c[0] = 3;
|
||||
return 0;
|
||||
}
|
||||
19
TangDou/LanQiaoBei/ZhongGaoJi/LanQiao15STEMA202312/G2.cpp
Normal file
19
TangDou/LanQiaoBei/ZhongGaoJi/LanQiao15STEMA202312/G2.cpp
Normal file
@@ -0,0 +1,19 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
string s;
|
||||
int n;
|
||||
int main() {
|
||||
cin >> s >> n;
|
||||
n--;
|
||||
while(n--){
|
||||
string t;
|
||||
for (int i = 0; i < s.size(); i++){
|
||||
int cnt = 1;
|
||||
while (i + 1 < s.size() && s[i + 1]==s[i]) cnt++, i++;
|
||||
t += to_string(cnt) + s[i];
|
||||
}
|
||||
s = t;
|
||||
}
|
||||
cout << s << endl;
|
||||
return 0;
|
||||
}
|
||||
30
TangDou/LanQiaoBei/ZhongGaoJi/LanQiao15STEMA202312/TD.cpp
Normal file
30
TangDou/LanQiaoBei/ZhongGaoJi/LanQiao15STEMA202312/TD.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
const int N = 100010;
|
||||
vector<int> g[N];
|
||||
int c[N];
|
||||
int dfs(int u, int fa, int k) {
|
||||
if (k == 0) return c[u];
|
||||
int sum = c[u];
|
||||
for (int i = 0; i < g[u].size(); i++) {
|
||||
if (g[u][i] == fa) continue;
|
||||
sum += dfs(g[u][i], u, k - 1);
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
int main() {
|
||||
int n;
|
||||
cin >> n;
|
||||
for (int i = 1; i <= n; i++) cin >> c[i];
|
||||
for (int i = 1; i < n; i++){
|
||||
int a, b;
|
||||
cin >> a >> b;
|
||||
g[a].push_back(b);
|
||||
g[b].push_back(a);
|
||||
}
|
||||
int k;
|
||||
cin >> k;
|
||||
for (int i = 1; i <= n; i++)
|
||||
cout << dfs(i, -1, k) << endl;
|
||||
return 0;
|
||||
}
|
||||
21
TangDou/LanQiaoBei/ZhongGaoJi/LanQiao15STEMA202312/sg.cpp
Normal file
21
TangDou/LanQiaoBei/ZhongGaoJi/LanQiao15STEMA202312/sg.cpp
Normal file
@@ -0,0 +1,21 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
const int N=110;
|
||||
struct Node {
|
||||
int id;
|
||||
int fen;
|
||||
bool operator<(const Node &t) {
|
||||
if (fen == t.fen) return id < t.id;
|
||||
return fen > t.fen;
|
||||
}
|
||||
} a[N];
|
||||
|
||||
|
||||
int main() {
|
||||
int n;
|
||||
cin >> n;
|
||||
for (int i = 1; i <= n; i++) cin >> a[i].id >> a[i].fen;
|
||||
sort(a+1, a + n+1);
|
||||
for (int i = 1; i <= n; i++) cout << a[i].id << " " << a[i].fen << endl;
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
https://tiku.scratchor.com/paper/view/z8k4y0xsf0ue8xlh
|
||||
|
||||
|
||||
https://tiku.scratchor.com/paper/view/gjfvsjrgtpm30v3f
|
||||
Reference in New Issue
Block a user