Merge branch 'main' of http://www.wmarkj.com:3000/huanghai/python
commit
94518ff5a5
@ -0,0 +1,20 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
int main() {
|
||||
int n, m;
|
||||
cin >> n >> m;
|
||||
int cnt = 0;
|
||||
for (int i = n; i <= m; i++) {
|
||||
int x = i;
|
||||
bool flag = false;
|
||||
while (x) {
|
||||
int a = x % 10;
|
||||
if (a % 2 == 0) flag = true;
|
||||
x /= 10;
|
||||
}
|
||||
if (!flag) cnt++;
|
||||
}
|
||||
cout << cnt << endl;
|
||||
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
int main() {
|
||||
int n, cnt = 0;
|
||||
cin >> n;
|
||||
cnt = n / 3;
|
||||
if (n == 2)
|
||||
cnt = -1;
|
||||
else if (n == 4)
|
||||
cnt = 4;
|
||||
else if (n % 3 == 1)
|
||||
cnt += 1;
|
||||
else if (n % 3 == 2)
|
||||
cnt += 2;
|
||||
|
||||
cout << cnt << endl;
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
https://blog.csdn.net/qq_36230375/article/details/134725732
|
||||
|
||||
https://tiku.scratchor.com/paper/view/gjfvsjrgtpm30v3f
|
@ -0,0 +1,26 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
int k;
|
||||
string kill(string s) {
|
||||
int p = 0;
|
||||
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;
|
||||
|
||||
cin >> k;
|
||||
for (int i = 1; i <= k; i++) s = kill(s);
|
||||
cout << s << endl;
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
#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() {
|
||||
#ifndef ONLINE_JUDGE
|
||||
freopen("11.in", "r", stdin);
|
||||
#endif
|
||||
|
||||
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;
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
4
|
||||
5
|
||||
3
|
||||
6
|
||||
1
|
||||
1 2
|
||||
1 3
|
||||
2 4
|
||||
2
|
@ -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;
|
||||
}
|
@ -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
|
@ -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 @@
|
||||
https://tiku.scratchor.com/paper/view/z8k4y0xsf0ue8xlh
|
@ -1,27 +1,26 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
/**
|
||||
8
|
||||
4 2
|
||||
|
||||
1
|
||||
2 2
|
||||
3 3 3
|
||||
4 4 4 4
|
||||
*/
|
||||
int n, sum;
|
||||
int main() {
|
||||
cin >> n;
|
||||
for (int i = 1;; i++) {
|
||||
n -= i;
|
||||
if (n <= 0) {
|
||||
// cout << i << " " << i + n << endl;
|
||||
sum += i * (i + n); // 最后一行
|
||||
for (int j = 1; j < i; j++) sum += j * j;
|
||||
cout << sum << endl;
|
||||
break;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in new issue