只能滑水3题。
A
#include<iostream>
using namespace std;
int main()
{
char s[105];
int n;
scanf("%d%s",&n,s);
for(int i=0;i<n;i++){
if(s[i]=='o'){
int j;
for(j=2;j<n;j+=2){
if(s[i+j]=='o'&&s[i+j-1]=='g') continue;
else break;
}
if(j==2) printf("%c",s[i]);
else {printf("***");i=i+j-2;}
}
else printf("%c",s[i]);
}
printf("\n");
}
B
#include<iostream>
using namespace std;
const int maxn=1000+5;
int map[maxn][maxn];
int u[maxn][maxn],d[maxn][maxn],l[maxn][maxn],r[maxn][maxn];
int main()
{
int n,m;
scanf("%d%d",&n,&m);
for(int i=0;i<n;i++) for(int j=0;j<m;j++) {
scanf("%d",&map[i][j]);
}
for(int i=0;i<n;i++) for(int j=0;j<m;j++) {
if(map[i][j]==1) {
l[i][j]=u[i][j]=1;
l[i][j+1]=u[i+1][j]=1;
}
else{
if(j>0) l[i][j]=l[i][j-1];
if(i>0) u[i][j]=u[i-1][j];
}
}
for(int i=n-1;i>=0;i--) for(int j=m-1;j>=0;j--) {
if(map[i][j]==1){
r[i][j]=d[i][j]=1;
if(j>0) r[i][j-1]=1;
if(i>0) d[i-1][j]=1;
}
else{
r[i][j]=r[i][j+1];
d[i][j]=d[i+1][j];
}
}
int cnt=0;
for(int i=0;i<n;i++) for(int j=0;j<m;j++) {
if(map[i][j]==0){
if(u[i][j]) cnt++;
if(d[i][j]) cnt++;
if(l[i][j]) cnt++;
if(r[i][j]) cnt++;
}
}
cout<<cnt<<endl;
}
C
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long LL;
const int maxn=2*100000+5;
const LL inf=1000000000000;
LL pos[maxn];
LL c[maxn],v[maxn];
LL n,k,s,t;
bool test(LL mid)
{
LL ti=0;
for(int i=1;i<=k+1;i++){
LL r=pos[i]-pos[i-1];
LL tmp=2*r-mid;
if(tmp>r) return false;
LL tt=max((LL)0,tmp);
ti+=tt*2+(r-tt);
}
if(ti<=t) return true;
return false;
}
int main()
{
scanf("%I64d%I64d%I64d%I64d",&n,&k,&s,&t);
LL l=1,r=-1;
for(int i=0;i<n;i++)
scanf("%I64d%I64d",&c[i],&v[i]),r=max(r,v[i]);
for(int i=1;i<=k;i++) scanf("%I64d",&pos[i]);
sort(pos+1,pos+1+k);
pos[0]=0;pos[k+1]=s;
LL tmp=inf;
while(l<=r){
LL mid=l+(r-l+1)/2;
if(test(mid)) {tmp=mid;r=mid-1;}else l=mid+1;
}
LL ans=inf;
for(int i=0;i<n;i++) {
if(v[i]>=tmp) ans=min(ans,c[i]);
}
printf("%I64d\n",ans==inf?-1:ans);
}