2025年中北大学第二十届程序设计校赛_ACM/NOI/CSP/CCPC/ICPC算法编程高难度练习赛_牛客竞赛OJ
共有A~O15道题目,其中F L M N的题解暂时没有,(因为我不会还没有补题,可以催更)
A ICPC
略
B Wzr的签到题


//a[n]中奇数个数必须等于b[n]中偶数个数
//a[n]中偶数个数必须等于b[n]中奇数个数
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long LL;
int main()
{
LL n,a,b,cnt_a,cnt_b;
cin >> n;
for(LL i=0;i < n;i++)
{
cin >> a;
a = abs(a);
if(a)
a %= 2;
if(a == 1)
cnt_a ++;
}
for(LL i=0;i < n;i++)
{
cin >> b;
b = abs(b);
if(b)
b %= 2;
if(b == 0)
cnt_b++;
}
if(cnt_a == cnt_b)
cout << "YES" ;
else
cout << "NO";
return 0;
}
C 星际解码计划

//q在s[i]位置,统计q前面有多少个t,记为t[i],统计q后面有多少个w,记为w[i+1]
//实际上统计w的数量可以用动态数组,从后往前记录,t的数量不需要直接记录,边往前边记录,用DP的思想
#include <iostream>
#include <vector>
using namespace std;
int main() {
string s;
cin >> s;
int n = s.size();
vector<int> w(n + 1, 0);
for (int i = n - 1; i >= 0; --i) {
w[i] = w[i + 1] + (s[i] == 'w');
}
long long ans = 0;
long long t = 0;
for (int i = 0; i < n; ++i)
{
if (s[i] == 't')
{
t++;
}
else if (s[i] == 'q')
{
ans += t * w[i + 1];
}
}
cout << ans << endl;
return 0;
}
D yqw的珂学难题(easy)

#include<cstdio>
using namespace std;
long long gcd(long long a, long long b) {
while(b) a %= b, b ^= a ^= b ^= a;
return a;
}
int main() {
int n;
scanf("%d", &n);
long long s = (n+1LL)*(n+1LL);
long long d = 6;
long long g = gcd(s, d);
printf("%lld/%lld", s/g, d/g);
}
E yqw的珂学难题(hard)
#include<cstdio>
using namespace std;
long long gcd(long long a, long long b) {
while(b) a %= b, b ^= a ^= b ^= a;
return a;
}
int main() {
int n;
scanf("%d", &n);
long long s = (n+1LL)*(n+1LL);
long long d = 6;
long long g = gcd(s, d);
printf("%lld/%lld", s/g, d/g);
}
G fy的教科书
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
int n,a,b;
scanf("%d",&n);
long long s1=0,s2=0;
int mx1=0,mx2=0;
while(n--)
{
scanf("%d%d",&a,&b);
int mi=min(a,b),ma=max(a,b);
s1+=mi;
s2+=ma;
mx1=max(mx1,ma);
mx2=max(mx2,mi);
}
long long ans=min(s1+mx1,s2+mx2)*2;
printf("%lld",ans);
}
H 世界之大,想去看看(easy)
//暴力
#include<iostream>
using namespace std;
int main()
{
int X,a,b;
cin >> X >> a >> b;
for(int i=1;i <= 10000;i ++)
{
for(int j=1;j <= 10000;j++)
{
if(X == i * a + j * b)
{
cout << "YES" << endl;
return 0;
}
}
}
cout << "NO";
return 0;
}
I 世界之大,想去看看(hard)
世界之大,想去看看(hard)
#include <iostream>
#include <algorithm>
using namespace std;
long long gcd(long long a, long long b) {
while (b != 0) {
long long temp = b;
b = a % b;
a = temp;
}
return a;
}
int main() {
long long X, a, b;
cin >> X >> a >> b;
long long g = gcd(a, b);
if (X % g == 0) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
return 0;
}
//第一反应是按照排列组合将所有的种类先算出来,然后再开两个数组用高精度计算,但是数量太多太复杂了,要是把和算出来必然要爆
//所以一定是把它变成数学题目,找规律
//直接模拟,按照每一位的数字贡献值计算,分为非首位和首位
//规律:ave = (n+2)(19 * 10^2n - 1) / 36
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
long long di = 1;
for (int i = 0; i < 2 * n; ++i) {
di *= 10;
}
long long average;
average = (19 * di - 1) * (n + 2) / 36;
cout << average << endl;
return 0;
}
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
ll min_round;
void dfs(ll n, ll steps)
{
if (steps >= min_round) return;
if (n == 0) {
min_round = min(min_round, steps);
return;
}
if (steps + n < min_round)
min_round = steps + n;
// 技能3:青莲剑歌
if (n % 5 == 0) {
dfs(n / 5, steps + 1);
}
else
{ // 用技能1调整余数到5的倍数
ll cost = n % 5;
dfs((n - cost) / 5, steps + cost + 1);
}
// 技能2:将进酒
if (n % 2 == 0)
{
dfs(n / 2, steps + 1);
}
else
{ // 用技能1调整余数到2的倍数
ll cost = n % 2;
dfs((n - cost) / 2, steps + cost + 1);
}
}
int main() {
ll n;
cin >> n;
min_round = n; // 刮痧(狗头.jpg)
dfs(n, 0);
cout << min_round << endl;
return 0;
}
O 魔法大师
//二分查找
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,m;
scanf("%d%d",&n,&m);
vector<int> a(n);
for(int i=0;i<n;i++) scanf("%d",&a[i]);
sort(a.begin(),a.end());
int first=1;
while(m--)
{
int x;
scanf("%d",&x);
int l=-1,r=n;
while(l+1<r)
{
int mid=(l+r)/2;
if(a[mid]>=x) r=mid;
else l=mid;
}
if(!first) printf(" ");
first=0;
printf("%d",r<n?a[r]:-1);
}
printf("\n");
}