2025.2.8——1400
1.2025.2.19——15002.11.23 周六3.11.24 周日4.11.25 周一日常5.2024.11.26 周二日常6.2024.11.27 周三7.2024.11.28周四8.2024.11.29 周五9.2024.11.30 周六10.2024.12.1 周日11.2024.12.2 周一12.2024.12.3 周二13.2024.12.4 周三14.2024.12.5 周四15.2024.12.7 周六16.2024.12.8 周日17.2024.12.9 周一18.2024.12.10 周二19.2024.12.11 周三20.2024.12.12 周四21.2024.12.13 周五22.2024.12.14 周六23.2024.12.16 周一24.2024.12.17 周二25.2024.12.18 周三26.2024.12.19 周四27.2024.12.20 周五28.2024.12.21 周六29.2024.12.22 周日30.2024.12.23 周一31.2024.12.24 周四32.2024.12.25 周三33.2024.12.26 周四34.2024.12.27 周五35.2024.12.28 周六36.2024.12.29 周日37.2024.12.30 周一38.2025.1.5——120039.2025.1.12——120040.2025.1.14——120041.2025.1.15——120042.2025.1.16——120043.2025.1.17——120044.2025.1.18——130045.2025.1.19——130046.2025.1.20——130047.2025.1.21——130048.2025.1.22——130049.2025.1.24——140050.2025.1.26——1400
51.2025.2.8——1400
52.2025.2.9——140053.2025.2.10——140054.2025.2.14——140055.2025.2.15——140056.2025.2.17——14002025.2.8——1400
A 1400
B 1400
------------------------------------------------
-
思维+贪心。
A
- 入手点是考虑每行/列之和为多少。
B
- 较难的贪心。
- 入手点是转化问题分析方式:分割为两个数组理解为按顺序向两个空数组添加。
------------------------代码------------------------
A
#include <bits/stdc++.h>
#define int long long //
#define endl '\n' // attention: interactive/debug
#define el cout << endl
using namespace std;
#define bug(BUG) cout << "bug:# " << (BUG) << endl
#define bug2(BUG1, BUG2) cout << "bug:# " << (BUG1) << " " << (BUG2) << endl
#define bug3(BUG1, BUG2, BUG3) cout << "bug:# " << (BUG1) << ' ' << (BUG2) << ' ' << (BUG3) << endl
#define bugv(VEC, ST) \
{ \
for (int I = ST; I < VEC.size(); I++) \
cout << VEC[I] << ' '; \
el; \
}
void _();
signed main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cout << fixed << setprecision(10);
int T = 1;
cin >> T;
while (T--)
_();
return 0;
}
void _()
{
int n, m;
cin >> n >> m;
vector<vector<int>> a(n + 1, vector<int>(m + 1));
string order;
cin >> order;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
cin >> a[i][j];
auto rowsum = [&](int i)
{
int ans = 0;
for (int j = 1; j <= m; j++)
ans += a[i][j];
return ans;
};
auto colsum = [&](int j)
{
int ans = 0;
for (int i = 1; i <= n; i++)
ans += a[i][j];
return ans;
};
int sx = 1, sy = 1;
for (auto s : order)
{
if (s == 'D')
a[sx][sy] = -rowsum(sx);
else
a[sx][sy] = -colsum(sy);
if (s == 'D')
sx++;
else
sy++;
}
a[sx][sy] = -rowsum(n);
// bug2(sx, sy);
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= m; j++)
cout << a[i][j] << ' ';
el;
}
// for (int i = 1; i <= n; i++)
// bug(rowsum(i));
// for (int j = 1; j <= m; j++)
// bug(colsum(j));
}
// void _()
// {
// int n, m;
// cin >> n >> m;
// vector<vector<int>> a(n + 1, vector<int>(m + 1)), f(n + 1, vector<int>(m + 1)); // 1 2
// string order;
// cin >> order;
// for (int i = 1; i <= n; i++)
// for (int j = 1; j <= m; j++)
// cin >> a[i][j];
// auto rowsum = [&](int i)
// {
// int ans = 0;
// for (int j = 1; j <= m; j++)
// ans += a[i][j];
// return ans;
// };
// auto colsum = [&](int j)
// {
// int ans = 0;
// for (int i = 1; i <= n; i++)
// ans += a[i][j];
// return ans;
// };
// int sx = 1, sy = 1;
// f[sx][sy] = 1;
// int sum = order[0] == 'D' ? rowsum(1) : colsum(1);
// for (auto s : order)
// {
// if (s == 'D')
// sx++;
// else
// sy++;
// f[sx][sy] = 1;
// }
// for (int i = 1; i <= n; i++)
// for (int j = 1; j <= m; j++)
// if (f[i][j])
// {
// if ((j - 1 > 0 && f[i][j - 1]) || (j + 1 <= m && f[i][j + 1]))
// f[i][j] = 2;
// }
// for (int i = 1; i <= n; i++)
// for (int j = 1; j <= m; j++)
// if (f[i][j] == 1)
// a[i][j] = sum - rowsum(i);
// for (int i = 1; i <= n; i++)
// for (int j = 1; j <= m; j++)
// if (f[i][j] == 2)
// a[i][j] = sum - colsum(j);
// for (int i = 1; i <= n; i++)
// {
// for (int j = 1; j <= m; j++)
// cout << a[i][j] << ' ';
// el;
// }
// for (int i = 1; i <= n; i++)
// bug(rowsum(i));
// for (int j = 1; j <= m; j++)
// bug(colsum(j));
// }
B
#include <bits/stdc++.h>
#define int long long //
#define endl '\n' // attention: interactive/debug
#define el cout << endl
using namespace std;
#define bug(BUG) cout << "bug:# " << (BUG) << endl
#define bug2(BUG1, BUG2) cout << "bug:# " << (BUG1) << " " << (BUG2) << endl
#define bug3(BUG1, BUG2, BUG3) cout << "bug:# " << (BUG1) << ' ' << (BUG2) << ' ' << (BUG3) << endl
#define bugv(VEC, ST) \
{ \
for (int I = ST; I < VEC.size(); I++) \
cout << VEC[I] << ' '; \
el; \
}
void _();
signed main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cout << fixed << setprecision(10);
int T = 1;
cin >> T;
while (T--)
_();
return 0;
}
void _()
{
int n;
cin >> n;
int x = 1e12, y = 1e12, res = 0;
for (int i = 0; i < n; i++)
{
if (x > y)
swap(x, y);
int a;
cin >> a;
if (a <= x)
x = a;
else if (a > y)
x = a, res++;
else
y = a;
}
cout << res;
el;
}
// void _()
// {
// int n;
// cin >> n;
// vector<int> s, t;
// for (int i = 0; i < n; i++)
// {
// int x;
// cin >> x;
// if (!i)
// s.push_back(x);
// else
// {
// if (x > s.back())
// t.push_back(x);
// else
// s.push_back(x);
// }
// }
// int res = 0;
// for (int i = 1; i < s.size(); i++)
// res += s[i] > s[i - 1];
// for (int i = 1; i < s.size(); i++)
// res += s[i] > s[i - 1];
// for (int i = 1; i < t.size(); i++)
// res += t[i] > t[i - 1];
// cout << res;
// el;
// }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!