A
#include <algorithm>
#include <iostream>
#include <cstring>
using namespace std;
int a[10];
int main()
{
int t;
cin >> t;
while (t --)
{
for (int i = 1; i <= 4; i ++ )
{
cin >> a[i];
}
int b = max(a[1], a[2]);
int c = max(a[3], a[4]);
sort(a + 1, a + 5);
if ((a[3] == b && a[4] == c) || (a[3] == c && a[4] == b))
cout << "YES" << endl;
else cout << "NO" << endl;
}
return 0;
}
B
1≤i<j≤n and gcd(ai,2aj)>1
#include <algorithm>
#include <iostream>
#include <cstring>
using namespace std;
int gcd(int a, int b)
{
return b?gcd(b, a % b):a;
}
const int N = 2e3 +10;
int a[N], b[N],n;
int main()
{
int t;
cin >> t;
while (t -- )
{
cin >> n;
int j = 1;
for (int i = 1; i <= n; i ++ ){
cin >> a[i];
if (a[i] % 2 == 0) b[j ++] = a[i];
}
int ans = 0;
for (int i = 1; i <= n; i ++)
{
if (a[i] % 2) b[j ++] = a[i];
}
for (int i = 1; i <= n; i ++ )
{
for (int k = i + 1; k <= n; k ++ )
{
if (gcd(b[i], 2 * b[k]) > 1) ans ++;
}
}
cout << ans << endl;
}
return 0;
}
C
连续0101,1010串
#include <algorithm>
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
typedef long long ll;
const int N = 2e5 + 10;
int f[N][3];
int main()
{
int t;
cin >> t;
while (t -- )
{
string a;
cin >> a;
memset(f, 0, sizeof f);
for (int i = 0; i < a.size(); i ++ )
{
if (a[i] != '1') f[i][0] = f[i - 1][1] + 1;
if (a[i] != '0') f[i][1] = f[i - 1][0] + 1;
}
ll ans = 0;
for (int i = 0; i < a.size(); i ++ ) ans += max(f[i][0], f[i][1]);
cout << ans << endl;
}
return 0;
}