您的位置:首页 > 其它

蓝桥杯 买不到的数目

2018-03-31 21:16 197 查看
动态规划,当可以被凑出来的数的连续个数等于最小的那个a时,之后所有的数都可以被凑出。
与凑包子那题一样。#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int ans[100000];
int a,b;
int Count=0;
int MAX;//标记当前最大凑不出来的数
int main()
{
memset(ans,0,sizeof(ans));
scanf("%d%d",&a,&b);
ans[a]=ans[b]=1;
int n=min(a,b);
while(Count<min(a,b))//当连续可以被凑出的数等于最小的那个数时,之后所有的数都可以被凑出
{
if(ans
==1)//如果n可以被凑出 那么n+a和n+b也可以凑出
{
ans[n+a]=1;
ans[n+b]=1;
Count++;//计数
}
else{
Count=0;//不能被凑出,连续中断。
MAX=n;
}
n++;
}
printf("%d",MAX);
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: