20261007 CSP-J模拟赛
chenjinxi2014 · · 个人记录
1 连续档案 (game) (100/100)
:::info[连续档案-题面] ::: 水题,模拟即可
#include<bits/stdc++.h>
using namespace std;
int main() {
freopen("game.in","r",stdin);
freopen("game.out","w",stdout);
ios::sync_with_stdio(false);
cin.tie(0);
long long n,c[1005],sum=0;
memset(c,0,sizeof(c));
c[1]=1;
string a="",b;
cin >> n;
for (int i=1;i<=n;i++) {
cin >> b;
if (a==b) {
c[i]=c[i-1]+1;
} else {
c[i]=1;
}
sum+=c[i];
a=b;
}
cout << sum << endl;
return 0;
}
2 星图压缩(throw) (20/100)
:::info[星图压缩-题面] ::: 显然,题目没读清,没考虑首位进位然后就挂了,其实很简单
#include<bits/stdc++.h>
using namespace std;
int t,k;
string n;
int main() {
freopen("throw.in","r",stdin);
freopen("throw.out","w",stdout);
ios::sync_with_stdio(false);
cin.tie(0);
cin >> t;
for (int i=1;i<=t;i++) {
cin >> k;
cin >> n;
cout << n;
bool f=0;
for (int i=k-1;i>=1;i--) {
if (n[i]>='5') {
int cnt=i-1;
n[cnt]++;
while (n[cnt]>'9' && cnt>0) {
n[cnt]-=10;
cnt--;
n[cnt]++;
}
if (n[cnt]>'9' && cnt==0) {
n[cnt]-=10;
f=1;
}
}
n[i]='0';
if (i<k-1) {
n[i+1]='0';
}
cout << " -> ";
if (f==1) {
cout << 1;
}
cout << n;
}
cout << endl;
}
}
3 双色信标(wait) (35/100)
:::info[双色信标-题面]
:::
直接暴力可以拿
#include<bits/stdc++.h>
using namespace std;
long long n,sum[2000005],dir[4000010],ans=0,con=0;
bool ac[4000010];
int main() {
freopen("wait.in","r",stdin);
freopen("wait.out","w",stdout);
ios::sync_with_stdio(false);
cin.tie(0);
string s;
cin >> n;
cin >> s;
dir[2000005]=-1;
ac[2000005]=1;
for (int i=0;i<n;i++) {
if (s[i]=='l') {
sum[i+1]=sum[i]+1;
} else {
sum[i+1]=sum[i]-1;
}
if (ac[sum[i+1]+2000005]==0) {
ac[sum[i+1]+2000005]=1;
dir[sum[i+1]+2000005]=i;
} else {
con=i-dir[sum[i+1]+2000005];
if (con>ans) {
ans=con;
}
}
}
cout << ans << endl;
return 0;
}
:::info[典礼席位-题面] ::: :::info[典礼席位-标程] :::