概况
| 题目编号 | T1 | T2 | T3 | T4 |
|---|---|---|---|---|
| 题目难度 | 橙 | 黄 | 绿 | 蓝 |
| 考察知识 | 双指针 | DP | 栈 | 背包 |
分析
T1
Wrong Cause
虽然过了,但调参调了半小时
Solution
十分简单的大题思路:搞出来所有满足 全部一样的区间 ,选取答案最大值即可
纯粹枚举区间就是 ,不炸才怪。于是想到双指针选区间,简简单单
ACcode
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 2e5 + 10;
int t, n, a[N], b[N], dp[N], sum[N];
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> t;
while (t--)
{
cin >> n;
sum[0] = 0;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
sum[i] = 0;
sum[i] += sum[i - 1] + a[i];
}
for (int j = 1; j <= n; j++) cin >> b[j];
int l = 1, r = 1, jat = a[1] + b[1], mmax = -1;
for (int i = 2; i <= n; i++)
{
if (a[i] + b[i] == jat) r = i;
else
{
l = i;
r = i;
jat = a[i] + b[i];
}
mmax = max(mmax, (sum[r] - sum[l - 1]) * (r - l + 1));
}
cout << mmax << "\n";
}
return 0;
}T2
Wrong Cause
裸的DP没写出来!该死!该死!
Solution
暴力没必要讲,枚举区间 前缀和照样超时
想了想,既然模 ,那么问题就变成了:对每个 ,找到 ,使 最大。
设 , 。 , 。目标是最大化 此式的结果取决于 与 的关系:
- 若 :结果为 ,越小的 会使结果越大(如 , 时结果 , 时结果 )
- 若 :结果为 ,越接近 的 (即 越小且大于 )会使结果越大(如 , 时结果是 , 时结果 )
ACcode
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 2e5 + 10;
const int mod = 100;
int a[N], sum[N], mmax = -2e9, len = 2e9, cnt = 0, pre[100];
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n;
cin >> n;
for (int i = 0; i < 100; i++) pre[i] = -1;
pre[0] = 0;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
sum[i] = sum[i - 1] + a[i];
sum[i] = (sum[i] % mod + mod) % mod;
for (int j = 0; j < 100; j++)
if (pre[j] != -1)
if (mmax < ((sum[i] - j) % mod + mod) % mod)
mmax = ((sum[i] - j) % mod + mod) % mod;
if (pre[sum[i]] == -1) pre[sum[i]] = i;
}
cout << mmax << "\n";
return 0;
}T3
Wrong Cause
反了!处理反了!
Solution
思路不讲!
FU**
#include <bits/stdc++.h>
#define int long long
using namespace std;
int t;
string s;
stack<char> st;
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> t;
while (t--)
{
cin >> s;
for (int i = 0; i < s.size(); i++)
{
st.push(s[i]);
int cnt = 0;
while (st.size() > 1)
{
char a = st.top();
st.pop();
char b = st.top();
if (a == b)
{
st.pop();
if ('a' <= a && a <= 'z')
{
char c = a - 'a' + 'A';
st.push(c);
}
}
else
{
st.push(a);
cnt++;
if (cnt >= 2) break;
}
}
}
vector<char> ans;
while (!st.empty())
{
ans.push_back(st.top());
st.pop();
}
for (int i = ans.size() - 1; i >= 0; i--)
cout << ans[i];
cout << "\n";
}
return 0;
}