视频链接:
Codeforces Round 943 (Div. 3) A题_哔哩哔哩_bilibili
讲解都在视频里哦~
#include<bits/stdc++.h>
using namespace std;
int main()
{
int T;
cin >> T;
while (T--)
{
int x;
cin >> x;
int maxResult = INT_MIN, maxY;
for (int i = 1; i < x; i++)
{
int result = __gcd(x, i) + i;
if (result > maxResult)
maxY = i, maxResult = result;
}
cout << maxY << endl;
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
map<string, string> M;
int main()
{
int T;
cin >> T;
while (T--)
{
int n, m, k = 0;
string a, b;
cin >> n >> m;
cin >> a >> b;
int pos = 0;
string temp = b;
for (int i = 0; i <= n; i++)
{
temp = temp.substr(pos);
if (temp.find(a[i]) != string::npos)
pos = temp.find(a[i]) + 1, k++;
else
break;
}
cout << k << endl;
}
return 0;
}
#include <bits/stdc++.h>
using namespace std;
int main()
{
int T;
cin >> T;
while (T--)
{
int n;
cin >> n;
vector<int> ans(n), a(n, 0);
for (int i = 1; i < n; i++)
cin >> a[i];
ans[0] = 1000;
for (int i = 1; i < n; i++)
ans[i] = ans[i - 1] + a[i];
for (auto i : ans)
cout << i << ' ';
cout << endl;
}
return 0;
}
#include <bits/stdc++.h>
using namespace std;
#define int long long
int n, k, Pb, Ps;
int Calculate(vector<int>&a)
{
int n = a.size(), maxScore = 0;
vector<int> prefix(n);
prefix[0] = 0;
for (int i = 1; i < n; i++)
prefix[i] = prefix[i - 1] + a[i - 1];
for (int i = 0; i < n; i++)
{
if (i > k)
break;
maxScore = max(maxScore, prefix[i] + (k - i) * a[i]);
}
return maxScore;
}
signed main()
{
int T;
cin >> T;
while (T--)
{
cin >> n >> k >> Pb >> Ps;
Pb--, Ps--;
vector<int> p(n), a(n);
for (auto &i : p)
{
cin >> i;
i--;
}
for (auto &i : a)
cin >> i;
vector<int> ArrayB, ArrayS;
int temp = Pb;
ArrayB.push_back(a[temp]), temp = p[temp];
while (temp != Pb)
ArrayB.push_back(a[temp]), temp = p[temp];
temp = Ps;
ArrayS.push_back(a[temp]), temp = p[temp];
while (temp != Ps)
ArrayS.push_back(a[temp]), temp = p[temp];
int ScoreB(Calculate(ArrayB)), ScoreS(Calculate(ArrayS));
if (ScoreB > ScoreS)
cout << "Bodya\n";
else if (ScoreB < ScoreS)
cout << "Sasha\n";
else
cout << "Draw\n";
}
return 0;
}
#include <bits/stdc++.h>
using namespace std;
int main()
{
int T;
cin >> T;
while (T--)
{
int n;
cin >> n;
cout << "1 1\n2 1\n";
for (int i = 3; i <= n; i++)
printf("%d %d\n", i, i);
}
return 0;
}