补一下题解
A
AC code
#include<iostream>
using namespace std;
int a[105], b[105];
void solve() {
int n; cin >> n;
for (int i = 1; i <= n; i++)cin >> a[i] >> b[i];
for (int i = 2; i <= n; i++) {
if (a[i] >= a[1]) {
if (b[i] >= b[1]) {
cout << -1 << '\n';
return;
}
}
}
cout << a[1] << '\n';
}
int main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t; cin >> t;
while (t--) {
solve();
}
return 0;
}
B
AC code
#include<iostream>
#include<vector>
#include<climits>
#include<cmath>
using namespace std;
using ll = long long;
void solve() {
int n; cin >> n;
vector <ll>a(n + 3), b(n + 3);
for (int i = 0; i < n + 3; i++) { a[i] = 0; b[i] = 0; }
for (int i = 1; i <= n; i++)cin >> a[i];
for (int i = 1; i <= n; i++)cin >> b[i];
ll ami = INT_MAX; ll bmi = ami;
ll asum = 0; ll bsum = 0;
for (int i = 1; i <= n; i++) {
asum += a[i]; bsum += b[i];
ami = min(ami, a[i]);
bmi = min(bmi, b[i]);
}
cout << min(asum + n * bmi, bsum + n * ami) << '\n';
}
int main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t; cin >> t;
while (t--) {
solve();
}
return 0;
}
C
思路
显然第一个空很简单,累加重复的数量,每组重复减1即可,第二个空涉及到了数学,组合数
关键点在于题目中条件:至少有一个操作所选择的整数 i 是不同的,那么这两个操作序列就是不同的
每一组n个,选出n-1个,每组都乘起来
共有m组,m组全排列,乘到后面
ACcode
#include<iostream>
#include<string>
using namespace std;
using ll = long long;
const int M = 2e5 + 9;
ll p[M];
const int MOD = 998244353;
void init() {
p[0] = 1;
for (int i = 1; i <= 2e5; i++)p[i] = p[i - 1] * i % MOD;
}
void solve() {
string str; cin >> str;
ll n = str.size();
ll b = 1; ll c = 1; ll ans = 0;
for (int i = 1; i < n; i++) {
if (str[i] == str[i - 1])b++;
else if (b > 1) {
ans += b - 1;
c = (c * b) % MOD;
b = 1;
}
}
if (b > 1) {
ans += b - 1;
c = (c * b) % MOD;
b = 1;
}
if (ans == 0)c = 1;
else {
c = c * p[ans] % MOD;
}
cout << ans << ' ' << c << '\n';
}
int main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t; cin >> t;
init();
while (t--) {
solve();
}
return 0;
}