A
#include <iostream>
#include <algorithm>
using namespace std;
int gcd(int a, int b)
{
if(a < b) swap(a, b);
while(b)
{
int t = a % b;
a = b;
b = t;
}
return a;
}
int main()
{
int t; cin >> t;
while(t --)
{
int x; cin >> x;
int sum = -1, y = 1;
for (int i = 1; i < x; i ++)
{
if(gcd(x, i) + i > sum)
{
sum = gcd(x, i) + i;
y = i;
}
}
cout << y << endl;
}
}
B
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
using namespace std;
int n, m;
string a, b;
int solve()
{
int i = 0, j = 0;
for (;i < n && j < m; j ++)
{
if(a[i] != b[j]) continue;
else i ++;
}
return i ;
}
int main()
{
int t; cin >> t;
while(t --)
{
cin >> n >> m;
cin >> a >> b;
cout << solve() << endl;
}
}
C 推公式
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
using namespace std;
const int N = 510;
int a[N], x[N];
typedef long long LL;
int n;
int main()
{
int t; cin >> t;
while(t --)
{
cin >> n;
n --;
for (int i = 1; i <= n; i ++) cin >> x[i];
a[0] = x[1] + 1;
for (int i = 1; i < n; i ++)
{
for (int j = 0; ; j ++)
{
int t = a[i-1] * j + x[i];
if(t > x[i+1])
{
a[i] = t; break;
}
}
}
a[n] = a[n-1] + x[n];
for (int i = 0; i <= n; i ++) cout << a[i] << " ";
cout << endl;
}
return 0;
}
D 本质是停在哪个位置收益最大,之前有过类似题目
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
using namespace std;
int n, k, pb, ps;
const int N = 200010;
int p[N], a[N];
typedef long long LL;
int main()
{
int t; cin >> t;
while(t --)
{
cin >> n >> k >> pb >> ps;
for (int i = 1; i <= n; i ++) cin >> p[i];
for (int i = 1; i <= n; i ++) cin >> a[i];
LL sumb = 0, sums = 0;
vector<int> b;
vector<int> s;
vector<int> op(n + 1, false);
for (int i = pb; op[i] == false; i = p[i])
{
b.push_back(a[i]);
op[i] = true;
}
for (int i = 0; i < n + 1; i ++) op[i] = false;
for(int i = ps; op[i] == false; i = p[i])
{
s.push_back(a[i]);
op[i] = true;
}
LL j = 0;
for (int i = 0; i < (int)b.size(); i ++)
{
if(k - i == 0) break;
sumb = max(sumb, (LL)(k - i) * b[i] + j);
j += b[i];
}
j = 0;
for (int i = 0; i < (int)s.size(); i ++)
{
if(k - i == 0) break;
sums = max(sums, (LL)(k - i) * s[i] + j);
j += s[i];
}
if(sumb > sums) cout << "Bodya" << endl ;
else if(sumb == sums) cout << "Draw" << endl ;
else cout << "Sasha" << endl ;
}
return 0;
}