你最好别复制 : )
T1
#include <bits/stdc++.h>
using namespace std;
int a[100005];
bool good[100005];
int main()
{
freopen("discuss.in", "r", stdin);
freopen("discuss.out", "w", stdout);
int t, n;
cin >> t;
while (t--)
{
cin >> n;
memset(good, 0, sizeof(good));
for (int i = 1; i <= n; i++)
{
cin >> a[i];
if (i > 1 && a[i] == a[i - 1] || i > 2 and a[i] == a[i - 2])
good[a[i]] = 1;
}
bool at_least_one = 0;
for (int i = 1; i <= n; i++)
{
if (good[i])
{
at_least_one = 1;
cout << i << " ";
}
}
if (!at_least_one)
cout << -1;
cout << '\n';
}
}
T2
#include <bits/stdc++.h>
using namespace std;
int dp[32][32];
int n, m;
int main()
{
freopen("ball.in", "r", stdin);
freopen("ball.out", "w", stdout);
cin >> n >> m;
dp[n][1] = 1;
dp[2][1] = 1;
for (int j = 2; j <= m; j++)
{
for (int i = 1; i <= n; i++)
{
int l = i - 1, r = i + 1;
if (l == 0)
l = n;
if (r == n + 1)
r = 1;
dp[i][j] = dp[l][j - 1] + dp[r][j - 1];
}
}
cout << dp[1][m];
return 0;
}
T3
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll N = (ll)2e5 + 5;
ll mns, add, n, a[N];
int main()
{
freopen("land.in", "r", stdin);
freopen("land.out", "w", stdout);
cin >> n;
for (int i = 1; i <= n; i++)
scanf("%lld", &a[i]);
for (int i = 1; i <= n; i++)
{
ll tmp = a[i] - mns + add - a[i - 1];
if (tmp > 0)
mns += tmp;
else
add += -tmp;
}
cout << mns + add;
return 0;
}
T4
#include <bits/stdc++.h>
using namespace std;
int main()
{
freopen("jump.in","r",stdin);
freopen("jump.out","w",stdout);
int n, x;
cin >> n >> x;
vector<pair<int, int>> pad(n + 1);
vector<bool> vis(n + 1);
for (int i = 1; i <= n; ++i)
cin >> pad[i].first >> pad[i].second;
int dir = 1, power = 1, ans = 0;
for (int reps = 0; reps < 5000000 && 1 <= x && x <= n; ++reps)
{
if (pad[x].first == 1 && power >= pad[x].second && !vis[x])
{
vis[x] = true;
++ans;
}
if (pad[x].first == 0)
{
dir *= -1;
power += pad[x].second;
}
x += dir * power;
}
cout << ans << "\n";
return 0;
}