题目链接:1279
开一个数组记录一下能够到达每一个深度的最大宽度==
代码:
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int width[50050],length[50050];
int main()
{
int n,m,a;
scanf("%d%d",&n,&m);
width[0]=1000000007;
for (int i=1;i<=n;i++)
{
scanf("%d",&a);
width[i]=min(width[i-1],a);
}
for (int i=0;i<m;i++)
scanf("%d",&length[i]);
int lp=n,kai=0,s=0;
while (lp&&kai<m)
{
if (length[kai]<=width[lp])
{
s++;kai++;lp--;
}
else
{
lp--;
}
}
printf("%d\n",s);
return 0;
}
题目链接:1062
打表记录a [ ] 和 zui [ ] -.-
代码:
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int a[100100],zui[100100];
int main()
{
a[0]=0;a[1]=1;zui[0]=0;zui[1]=1;
for (int i=2;i<=100000;i++)
{
if (i%2)
{
a[i]=a[i/2]+a[i/2+1];
}
else
a[i]=a[i/2];
zui[i]=max(zui[i-1],a[i]);
}
int t,n;scanf("%d",&t);
while (t--)
{
scanf("%d",&n);
printf("%d\n",zui[n]);
}
return 0;
}
题目链接:1010
把只含2,3,5的数打成表--然后sort以后就二分查找
代码:
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
unsigned long long shu[100000];
int main()
{
unsigned long long da=18446744073709551615,n,i;
int kp=0;i=1;
shu[kp++]=1;
while (i<=da/2)
{
i*=2;
shu[kp++]=i;
}
int ll=kp;
for (int k=0;k<ll;k++)
{
i=1;
while (shu[k]*i<da/3)
{
i*=3;
shu[kp++]=i*shu[k];
}
}
ll=kp;
for (int k=0;k<ll;k++)
{
i=1;
while (shu[k]*i<da/5)
{
i*=5;
shu[kp++]=i*shu[k];
}
}
sort(shu,shu+kp);
int t;scanf("%d",&t);
while (t--)
{
scanf("%llu",&n);
int pp=lower_bound(shu+1,shu+kp,n)-shu;
printf("%llu\n",shu[pp]);
}
return 0;
}