A.上班
題意:


分析:
簽到題
代碼:
#include <bits/stdc++.h>
using namespace std;
int main()
{
int x, y, z;
cin >> x >> y >> z;
cout << x + min(y, z);
return 0;
}
B.崇拜
題意:


分析:
按知識點難度從大到小排序,然后計算按這個順序講解的最大崇拜值,
代碼:
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int a[N];
bool cmp(int A, int B)
{
return A > B;
}
int main()
{
std::ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int n, x, y;
cin >> n >> x >> y;
for (int i = 0; i < n; i ++)
cin >> a[i];
sort(a, a + n, cmp);
int res = 0, Max = -0x3f3f3f3f;
for (int i = 0; i < n; i ++)
{
if (a[i] > y)
res += 3;
else if (a[i] < x)
res --;
Max = max(Max, res);
}
cout << max(0, Max);
return 0;
}
C.方豆子
題意:



分析:
遞回模擬一下就行了,
代碼:
#include <bits/stdc++.h>
using namespace std;
const int N = 3 * 1024 + 5;
char a[N][N];
char good[7][7] = {"******", "******", "******", "***...", "***...", "***..."};
char bad[7][7] = {"......", "......", "......", "...***", "...***", "...***"};
void setGood(int x, int y)
{
for (int i = 0; i < 6; i ++)
for (int j = 0; j < 6; j ++)
a[x + i][y + j] = good[i][j];
}
void setBad(int x, int y)
{
for (int i = 0; i < 6; i ++)
for (int j = 0; j < 6; j ++)
a[x + i][y + j] = bad[i][j];
}
void create(int x, int y, bool flag, int n)
{
if (n == 1)
{
if (flag)
setGood(x, y);
else
setBad(x, y);
return;
}
int m = 3 * (1 << n);
create(x, y, !flag, n - 1);
create(x, y + m / 2, !flag, n - 1);
create(x + m / 2, y, !flag, n - 1);
create(x + m / 2, y + m / 2, flag, n - 1);
}
int main()
{
std::ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int n;
cin >> n;
create(0, 0, 1, n);
int m = 3 * (1 << n);
for (int i = 0; i < m; i ++)
{
for (int j = 0; j < m; j ++)
{
cout << a[i][j];
}
cout << endl;
}
return 0;
}
D.矩陣
題意:


分析:
由于只有相鄰的元素互異才能移動,如果元素相同則修改,因此最終的路徑一定是010101010……或者1010101010……交替,觀察前面兩種路徑,我們可以發現,(x, y)處的元素與起點的元素滿足一定條件:當哈夫曼距離為奇數時,(x,y)的元素與起點不同,當哈夫曼距離為偶數時,(x,y)的元素與起點相同,因此我們在搜索最短花費時,可以根據當前位置與起點的哈夫曼距離以及當前元素與起點元素是否相同來卻確定節點之間的邊權值,最后跑一邊dijkstra即可,
代碼:
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
const int N = 1010;
typedef pair<int, int> PII;
typedef pair<int, PII> PIPII;
char g[N][N];
int d[N][N], dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
bool st[N][N];
int n, m;
void dijkstra()
{
memset(d, 0x3f, sizeof d);
priority_queue<PIPII, vector<PIPII>, greater<PIPII>> heap;
d[0][0] = 0;
heap.push({0, {0, 0}});
while (heap.size())
{
auto t = heap.top();
heap.pop();
int dist = t.x;
PII ver = t.y;
int x1 = ver.x, y1 = ver.y;
if (st[x1][y1])
continue;
st[x1][y1] = true;
for (int i = 0; i < 4; i ++)
{
int x2 = x1 + dx[i], y2 = y1 + dy[i];
if (x2 < 0 || x2 >= n || y2 < 0 || y2 >= m)
continue;
int w;
if ((x2 + y2) & 1)
{
if (g[x2][y2] == g[0][0])
w = 2;
else
w = 1;
}
else
{
if (g[x2][y2] == g[0][0])
w = 1;
else
w = 2;
}
if (d[x2][y2] > dist + w)
{
d[x2][y2] = dist + w;
heap.push({d[x2][y2], {x2, y2}});
}
}
}
}
int main()
{
std::ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n >> m;
for (int i = 0; i < n; i ++)
cin >> g[i];
dijkstra();
cout << d[n - 1][m - 1];
return 0;
}
E.數數
題意:


分析:
動態規劃,
狀態定義:f[i][j]表示放置了i個數,且前i個數的和為i * j的方案數,
狀態轉移:f[i + 1][k] += f[i][j],對于任意j使得1 ≤ (i + 1) × k - i × j ≤ m,
答案:\(\sum_{i=1}^m\)f[n][i]
代碼:
#include <bits/stdc++.h>
using namespace std;
const int N = 2010, mod = 1e9 + 7;
typedef long long LL;
LL f[N][N];
int main()
{
std::ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int n, m;
cin >> n >> m;
for (int i = 1; i <= m; i ++)
f[1][i] = 1;
for (int i = 1; i < n; i ++)
{
for (int j = 1; j <= m; j ++)
{
for (int k = (i * j) / (i + 1) + 1; k <= m; k ++)
{
if ((i + 1) * k - i * j > m)
break;
f[i + 1][k] = (f[i + 1][k] + f[i][j]) % mod;
}
}
}
LL ans = 0;
for (int i = 1; i <= m; i ++)
ans = (ans + f[n][i]) % mod;
cout << ans;
return 0;
}
?
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/556476.html
標籤:其他
上一篇:HO引擎近況20230701
下一篇:返回列表
