# 2015年北京师范大学新生程序设计竞赛题解

http://www.bnuoj.com/v3/contest_show.php?cid=7468

A. BQG's Programming Contest

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int a,b;
scanf("%d%d",&a,&b);
printf("%d\n",min(60000,max(1000,5*max(a,b))));
}
return 0;
}

B. BQG's Messy Code

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int x;
scanf("%d",&x);
printf("%d\n",-x);
}
return 0;
}

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
const int MAXN=1005;
struct hw
{
int a,b;
bool operator < (const hw &t)const
{
return a<t.a;
}
}s[MAXN];
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n;
scanf("%d",&n);
for(int i=0;i<n;i++)
scanf("%d%d",&s[i].a,&s[i].b);
sort(s,s+n);
int now=0;
for(int i=0;i<n;i++)
{
now=max(now,s[i].a);
now+=s[i].b;
}
printf("%d\n",now);
}
return 0;
}

D. BQG's Random String

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
const char t[4]="QAQ";
char s[100005];
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%s",s);
int n=strlen(s),res=0;
for(int i=0;i+2<n;i++)
{
bool isok=1;
for(int j=0;j<3;j++)
if(t[j]!=s[i+j])isok=0;
if(isok)res++;
}
printf("%d\n",res);
}
return 0;
}

E. BQG's Complexity Analysis

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
char s[55];
pair<int,int>c[5];
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
for(int i=0;i<2;i++)
{
scanf("%s",s);
int loc=0;
if(s[2]=='1')
{
c[i]=make_pair(0,0);
continue;
}
else if(s[2]=='n')
{
loc=3;
if(s[3]=='^')
{
int pp=0;
loc++;
while(s[loc]>='0' && s[loc]<='9')
pp=pp*10+s[loc++]-'0';
c[i].first=pp;
}
else c[i].first=1;
}
else c[i].first=0;
if(s[loc]==')')c[i].second=0;
else
{
int pp=0,len=strlen(s);
while(loc<len && (s[loc]<'0' || s[loc]>'9'))loc++;
while(loc<len && s[loc]>='0' && s[loc]<='9')
pp=pp*10+s[loc++]-'0';
if(pp==0)c[i].second=1;
else c[i].second=pp;
}
}
if(c[0]<c[1])printf("First\n");
else if(c[0]>c[1])printf("Second\n");
else printf("Both\n");
}
return 0;
}

F. BQG's Confusing Sequence

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll Mod=1000000007LL;
int ty[55];
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int a,b,n;
scanf("%d%d%d",&a,&b,&n);
if(a>b)swap(a,b);
if(a)n++;
int loc=0;
while(n)
{
ty[loc++]=n&1;
n>>=1;
}
ll res=0LL;
for(int i=loc-1-(a>0);i>=0;i--)
res=(res*10+(ty[i] ? b : a))%Mod;
printf("%lld\n",res);
}
return 0;
}

G. BQG's Square Glasses

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
typedef double db;
const int MAXN=100005;
const db INF=1e100;
const db eps=1e-12;
int sgn(db x)
{
if(x>eps)return 1;
if(x<-eps)return -1;
return 0;
}
db x[MAXN],y[MAXN];
db dp[MAXN][20];
int mm[MAXN];
void initRMQ(int n,db b[])
{
mm[0]=-1;
for(int i=0;i<n;i++)
{
mm[i+1]=((i&(i+1))==0) ? mm[i]+1 : mm[i];
dp[i][0]=b[i];
}
for(int j=1;j<=mm[n];j++)
for(int i=0;i+(1<<j)-1<n;i++)
dp[i][j]=min(dp[i][j-1],dp[i+(1<<(j-1))][j-1]);
}
db rmq(int x,int y)
{
if(y<x)return INF;
int k=mm[y-x+1];
return min(dp[x][k],dp[y-(1<<k)+1][k]);
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n;
scanf("%d",&n);
for(int i=0;i<n;i++)
scanf("%lf",&x[i]);
for(int i=0;i<n;i++)
scanf("%lf",&y[i]);
initRMQ(n,y);
db l=x[0]+eps,r=x[n-1]-eps,res=0.0;
while(sgn(l-(r-1))<0)
{
int kl=lower_bound(x,x+n,l)-x-1;
db yl=(y[kl+1]-y[kl])/(x[kl+1]-x[kl])*(l-x[kl])+y[kl];
db tl=l,tr=r;
for(int _=1;_<=100;_++)
{
db tm=(tl+tr)/2.0;
int kr=upper_bound(x,x+n,tm)-x-1;
db yr=(y[kr+1]-y[kr])/(x[kr+1]-x[kr])*(tm-x[kr])+y[kr];
if(tm-l>min(min(yl,yr),rmq(kl+1,kr)))tr=tm;
else tl=tm;
}
tl=(tl+tr)/2.0;
res+=(tl-l)*(tl-l);
l=tl;
}
printf("%.20f\n",res+(r-l)*(r-l));
}
return 0;
}

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int n;
scanf("%d",&n);
while(n--)
{
for(int i=0;i<8;i++)scanf("%*d");
printf("BQG is happy!\n");
}
return 0;
}

• 2
点赞
• 2
收藏
觉得还不错? 一键收藏
• 3
评论
04-05 1804
06-01 136
09-18
08-09
04-09 429
06-10 1506
04-24 834
04-22 225

### “相关推荐”对你有帮助么？

• 非常没帮助
• 没帮助
• 一般
• 有帮助
• 非常有帮助

1.余额是钱包充值的虚拟货币，按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载，可以购买VIP、付费专栏及课程。