A
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
string a, b , c;
void work()
{
for(int i = 0;i < a.size();i ++)
{
if(c[i] != a[i] && c[i] != b[i])
{
cout << "NO" << endl;
return;
}
}
cout << "YES" << endl;
}
int main()
{
int t = 0;
cin >> t;
while(t--)
{
cin >> a >> b >> c;
work();
}
return 0;
}
B
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
const int N = 100005;
int arr[N], n;
void work()
{
int base = 0;
vector<int> v;
for(int i = 0;i < n - 1;i ++)
{
if(arr[i] == -1 && arr[i + 1] != -1)v.push_back(arr[i + 1]);
else if(arr[i] != -1 && arr[i + 1] == -1)v.push_back(arr[i]);
else if(arr[i] != -1 && arr[i + 1] != -1)base = max(base,abs(arr[i] - arr[i + 1]));
}
if(v.empty())
{
printf("0 0
");
return;
}
sort(v.begin(),v.end());
int k = (v.back() + *v.begin()) / 2;
printf("%d %d
",max({v.back() - k, k - v[0], base}),k);
return;
}
int main()
{
int t = 0;
cin >> t;
while(t--)
{
cin >> n;
for(int i = 0;i < n;i ++)
{
scanf("%d",&arr[i]);
}
work();
}
return 0;
}
C
排列组合 隔板法 尝试让0的分布尽可能均匀而不是只考虑1
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
ll n , m;
void work()
{
ll ans = (n + 1) * n / 2,cnt = (n - m)/(m + 1);
ans -= cnt * (cnt+1)/2*(m+1-(n-m)%(m+1)) + (cnt+1)*(cnt+2)/2*((n-m)%(m+1));
cout << ans << endl;
}
int main()
{
int t;
cin >> t;
while(t--)
{
scanf("%lld %lld",&n,&m);
work();
}
return 0;
}