- 袁野老师 的博客
2026北京普及强化Day5比赛Code
- @ 2026-2-11 15:11:41
A
# include <bits/stdc++.h>
using namespace std;
char s[1010];
int l,r;
int main() {
scanf("%s",s);
for (int i=0; s[i]!='\0'; ++i) {
if (s[i] == '(') l++;
if (s[i] == ')') r++;
}
if (l == r) cout << "yes";
else cout << "no";
}
B
#include<bits/stdc++.h>
using namespace std;
struct node{
int num,p;
bool operator < (const node& nd) const {
if(num==nd.num) return p<nd.p;
return num<nd.num;
}
}b[8005];
int t[8005],n,q,a[8005];
void qsort() {
for (int i=1; i<=n; ++i)
b[i].num=a[i], b[i].p=i;
sort(b+1,b+n+1);
for (int i=1; i<=n; ++i) t[b[i].p]=i;
}
void upd(int x,int y) {
b[t[x]].num=y;
for (int i=1; i<=n+1; ++i) {
if (b[t[x]]<b[i]) {
if(i < t[x]) {
for (int j=t[x]; j>i; --j) {
b[j] = b[j-1];
}
b[i].num=y, b[i].p=x;
}
else {
for (int j=t[x]; j<i-1; ++j) {
b[j] = b[j+1];
}
b[i-1].num=y,b[i-1].p=x;
}
break;
}
}
for (int i=1; i<=n; ++i) t[b[i].p]=i;
}
int main() {
cin >> n >> q;
for (int i=1; i<=n; ++i) cin >> a[i];
qsort();
b[n+1].num=0x3f3f3f3f, b[n+1].p=n+1;
while(q--) {
int op,x,y;
cin >> op;
if(op==1) {
cin >> x >> y;
a[x]=y;
upd(x,y);
}
else {
cin >> x;
cout << t[x] << "\n";
}
}
return 0;
}
C
#include<bits/stdc++.h>
using namespace std;
int n,c,ans,x,a[1010];
int main() {
cin >> n >> c;
for (int i=1; i<=n; ++i) cin >> a[i];
for (int i=1; i<=n; ++i){
int tot = 0,cc = c;
for (int j=i; j<=n; ++j) {
if (cc >= a[j]) cc -= a[j], tot++;
}
ans = max(ans, tot);
}
cout << ans;
return 0;
}
D
#include<bits/stdc++.h>
using namespace std;
int n,p,op,st[1010],top,x;
int main() {
cin >> n;
for (int i=1; i<=n; ++i) {
cin >> op;
if (op == 1) cin >> x, st[++top] = x;
else {
if (!top) {
cout << "impossible!";
return 0;
} else {
top--;
}
}
}
if (top) cout << st[top] << "\n";
else cout << "impossible!";
return 0;
}
E
#include<bits/stdc++.h>
using namespace std;
char s[110];
int ans;
int main() {
cin >> s+1;
int l = strlen(s+1);
for (int i=1, j=l; i<j; ++i,--j) {
if (s[i] != s[j]) ans++;
}
cout << ans;
return 0;
}
F
#include<bits/stdc++.h>
using namespace std;
int n,k,x;
bool t[100010];
vector <int> ans;
int main() {
cin >> n >> k;
for (int i=1; i<=n; ++i) {
cin >> x;
if (!t[x]) t[x] = 1, ans.push_back(i), k--;
if (!k) break;
}
if (k) cout << "No";
else for (auto x:ans) cout << x << " ";
return 0;
}
G
#include<bits/stdc++.h>
using namespace std;
string s;
int ans;
int main() {
cin >> s;
for (int i=1; i<s.length(); ++i) {
if (s[i] != s[i-1]) ans++;
}
if (s[s.length()-1] == '0') ans++;
cout << ans;
return 0;
}
H
#include<bits/stdc++.h>
using namespace std;
int n,s;
int a[5010],b[5010],c[5010];
int t[10010];
long long ans;
int main() {
cin >> n >> s;
for (int i=1; i<=n; ++i) cin >> a[i];
for (int i=1; i<=n; ++i) cin >> b[i];
for (int i=1; i<=n; ++i) cin >> c[i];
for (int i=1; i<=n; ++i)
for (int j=1; j<=n; ++j)
t[a[i]+b[j]]++;
for (int i=1; i<=n; ++i) {
for (int j=2; j<=s-c[i]; ++j)
ans += t[j];
}
cout << ans;
return 0;
}
I
using namespace std;
int n,m,p[110][110],q,x,y;
int main() {
cin >> n >> m;
for (int i=1; i<=n; ++i)
for (int j=1; j<=m; ++j) cin >> p[i][j];
cin >> q;
while (q--) {
cin >> x >> y;
int ans = 0;
for (int a=-1; a<=1; ++a)
for (int b=-1; b<=1; ++b) {
ans += p[x+a][y+b];
}
cout << ans - p[x][y] << "\n";
}
return 0;
}
J
#include<bits/stdc++.h>
using namespace std;
int n;
struct stu{
string s;
int m,d;
}a[5010];
bool cmp(stu x,stu y){
if (x.m != y.m) return x.m < y.m;
if (x.d != y.d) return x.d < y.d;
if (x.s.size() != y.s.size())
return x.s.size() < y.s.size();
return x.s < y.s;
}
int main(){
cin >> n;
for (int i=1; i<=n; i++) {
cin >> a[i].s >> a[i].m >> a[i].d;
}
sort(a+1, a+n+1, cmp);
for (int i=1; i<=n; i++){
cout << a[i].s << " " << a[i].m << " " << a[i].d << endl;
}
return 0;
}
K
#include<bits/stdc++.h>
using namespace std;
int n,x;
queue <int> qa, qb;
int main(){
cin >> n;
for (int i=1; i<=n; ++i) cin >> x, qa.push(x);
for (int i=1; i<=n; ++i) cin >> x, qb.push(x);
while (!qa.empty()) { // 两个队列情况一致,只需要判断一个非空,另一个就非空
cout << qa.front() << " ";
cout << qb.front() << " ";
qa.pop(); qb.pop();
if (!qa.empty())
qa.push(qa.front()), qa.pop(),
qb.push(qb.front()), qb.pop();
}
return 0;
}