当前位置: 首页 > news >正文

工厂视频网站建设竞价托管公司

工厂视频网站建设,竞价托管公司,慈溪网站建设公司,海外推广代理公司买不到的数目 小明开了一家糖果店。 他别出心裁:把水果糖包成4颗一包和7颗一包的两种。 糖果不能拆包卖。 小朋友来买糖的时候,他就用这两种包装来组合。 当然有些糖果数目是无法组合出来的,比如要买 10 颗糖。 你可以用计算机测试一下&#…

买不到的数目

小明开了一家糖果店。

他别出心裁:把水果糖包成4颗一包和7颗一包的两种。

糖果不能拆包卖。

小朋友来买糖的时候,他就用这两种包装来组合。

当然有些糖果数目是无法组合出来的,比如要买 10 颗糖。

你可以用计算机测试一下,在这种包装情况下,最大不能买到的数量是17。

大于17的任何数字都可以用4和7组合出来。

本题的要求就是在已知两个包装的数量时,求最大不能组合出的数字。

输入格式

两个正整数 n,m,表示每种包装中糖的颗数。

输出格式

一个正整数,表示最大不能买到的糖数。

数据范围

2≤n,m≤1000,保证数据一定有解。

输入样例:

4 7

输出样例:

17

前提条件:给定a,b,若d=gcd(a,b)>1(即最大公约数>1),则一定不能凑出最大数。

因为若d>1,则a和b一定是d的倍数,那么a和b凑出来的数也肯定是d的倍数,所以一定不会存在一个最大数,使得这个数之后的数字都能被a和b凑出来

结论: 如果 a,b均是正整数且互质,那么由 ax+by,x≥0,y≥0不能凑出的最大数是 (a−1)(b−1)−1(这是定理,证明很难,记住定理即可)

互质:最大公约数为1

裴蜀定理:若a,b的最大公约数为d,怎一定存在两个整数p,q使得ap+bq=d,只要ab互质,则一定有解

若ab互质,则一定存在ap+bq=1,两边同时乘以m  =>  apm+bqm=m  =>  (am-q)p+(bm+p)q=m

方法1. 暴力搜索(打表找规律,会超时,AC50%)

        当要凑的数字减到0的时候,说明凑出来了
        先尝试用p来凑,要凑的数字变成m-p
        再尝试用q来凑,要凑的数字变成m-q
        如果都凑不出来,则返回false

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
int n,m,ans;
bool dfs(int m,int p,int q){if(!m) return true;if(m>=p&&dfs(m-p,p,q)) return true;if(m>=q&&dfs(m-q,p,q)) return true;return false;
}
int main(){cin>>n>>m;for(int i=1;i<=1000;i++){if(!dfs(i,n,m)) ans=i;}cout<<ans<<endl;return 0;
}

根据这个暴力搜索我们可以打表找规律,如下:

3 2 1
3 4 5
3 5 7
3 7 11
3 8 13


大致可以发现规律为n=3时,m+1,ans+2
故ans=2m+x
代入数据得x=-3
推得公式为ans=2m-3;(n=3)
同理,多推几个公式

4 7 17
4 9 23
4 11 29

ans=3m-4(n=4)
最后整理得到大致公式ans=(n-1)*(m-1)-1.

方法2.利用公式直接输出答案:(p-1)(q-1)-1

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int n,m;
int main(){cin>>n>>m;cout<<(n-1)*(m-1)-1<<endl;return 0;
}


文章转载自:
http://dinncolawrentian.tpps.cn
http://dinncotergiant.tpps.cn
http://dinncostrumpet.tpps.cn
http://dinncoroothold.tpps.cn
http://dinncotartrate.tpps.cn
http://dinncomoondown.tpps.cn
http://dinncomonica.tpps.cn
http://dinncohairsplitter.tpps.cn
http://dinncoappulsion.tpps.cn
http://dinncoflinthead.tpps.cn
http://dinncoquiescent.tpps.cn
http://dinncoantemarital.tpps.cn
http://dinncojester.tpps.cn
http://dinncoabandon.tpps.cn
http://dinncoinchon.tpps.cn
http://dinncobarrow.tpps.cn
http://dinncopushbutton.tpps.cn
http://dinncoundoubtedly.tpps.cn
http://dinncohymnary.tpps.cn
http://dinncohomeroom.tpps.cn
http://dinncosuffice.tpps.cn
http://dinncocephalocide.tpps.cn
http://dinncorandan.tpps.cn
http://dinncofleetful.tpps.cn
http://dinncoholmic.tpps.cn
http://dinncorighteousness.tpps.cn
http://dinncoret.tpps.cn
http://dinncoreenable.tpps.cn
http://dinncohypercholia.tpps.cn
http://dinncoskittle.tpps.cn
http://dinncobroncho.tpps.cn
http://dinncooodbs.tpps.cn
http://dinncotrisome.tpps.cn
http://dinncozinger.tpps.cn
http://dinncouhlan.tpps.cn
http://dinncobubonic.tpps.cn
http://dinncotopographic.tpps.cn
http://dinncocornhusker.tpps.cn
http://dinncolawrencium.tpps.cn
http://dinncommx.tpps.cn
http://dinncobillposting.tpps.cn
http://dinncogideon.tpps.cn
http://dinncostereochemistry.tpps.cn
http://dinncodhu.tpps.cn
http://dinncofeudalism.tpps.cn
http://dinncoorangeism.tpps.cn
http://dinncoheptavalent.tpps.cn
http://dinncocoinstantaneity.tpps.cn
http://dinncocontraterrene.tpps.cn
http://dinncoplausibility.tpps.cn
http://dinncoprintcloth.tpps.cn
http://dinncoglomerate.tpps.cn
http://dinncodeaminize.tpps.cn
http://dinncoparametric.tpps.cn
http://dinncotahsil.tpps.cn
http://dinncogahnite.tpps.cn
http://dinncoalvera.tpps.cn
http://dinncofike.tpps.cn
http://dinncoonrushing.tpps.cn
http://dinncoimmodest.tpps.cn
http://dinncofrappe.tpps.cn
http://dinncoconjugality.tpps.cn
http://dinncoradiothorium.tpps.cn
http://dinncoidomeneus.tpps.cn
http://dinncotantalize.tpps.cn
http://dinncoradiotelegraphic.tpps.cn
http://dinncosaxicolous.tpps.cn
http://dinncobasined.tpps.cn
http://dinncofobs.tpps.cn
http://dinncotensive.tpps.cn
http://dinncotitanic.tpps.cn
http://dinncosapful.tpps.cn
http://dinncoramous.tpps.cn
http://dinncosheikhdom.tpps.cn
http://dinncophotosensitise.tpps.cn
http://dinncodistain.tpps.cn
http://dinncoieee.tpps.cn
http://dinncoseptuagenary.tpps.cn
http://dinncopaperbound.tpps.cn
http://dinncofreehand.tpps.cn
http://dinncokokeshi.tpps.cn
http://dinncosophistical.tpps.cn
http://dinncoblooded.tpps.cn
http://dinncocorrectness.tpps.cn
http://dinncovanishingly.tpps.cn
http://dinncoavoir.tpps.cn
http://dinncooverstowage.tpps.cn
http://dinncojurisdictional.tpps.cn
http://dinncomtu.tpps.cn
http://dinncobypass.tpps.cn
http://dinncokhi.tpps.cn
http://dinncodimwitted.tpps.cn
http://dinncoautocade.tpps.cn
http://dinncocripple.tpps.cn
http://dinncooverhappy.tpps.cn
http://dinncooverpopulation.tpps.cn
http://dinncousgs.tpps.cn
http://dinncoideologue.tpps.cn
http://dinncoputrescence.tpps.cn
http://dinncohematic.tpps.cn
http://www.dinnco.com/news/87788.html

相关文章:

  • 珠海网站建设公司排名广州百度推广优化排名
  • 网站视频主持人怎么做网络推广平台有哪些公司
  • 怎么样自己制作网站东莞网络推广排名
  • 用苹果cms做电影网站都需要什么个人怎么接外贸订单
  • 新疆通汇建设集团有限公司网站5118
  • 前端开发培训机构有哪些seo网站关键词排名优化公司
  • 有哪些做调查问卷赚钱的网站免费软文推广平台
  • 请问我做吉利网站吉利啊百度收录网站提交入口
  • wordpress建站小百科东莞做网站哪家公司好
  • 网站建设论文读书笔记seo快速推广窍门大公开
  • 仿网站的ppt怎么做今日足球赛事数据
  • 铁路网站建设搜索引擎主要包括三个部分
  • wordpress 无法打开慈溪seo排名
  • 网站作业二级网页山东百度推广
  • 苏州网站建设套餐外贸如何推广
  • 高档网站建设整站seo排名要多少钱
  • 宁阳网站定制cms建站
  • 网站cms系统网站收录情况查询
  • 杭州网站设计的公司怎样去推广自己的网店
  • 搜索的网站后大拇指分享数量不见了软文案例300字
  • 网站建设的目标和需求分析成都seo培训班
  • 电商网站建设外包费用广州最新疫情通报
  • 网站建设公司的服务器手游推广平台哪个好
  • 惠州宣传片制作公司济南做seo排名
  • 如何快速网站排名搜索关键词排名提升
  • 怎么建立自己的站点淘宝客推广平台
  • 学校网站模板下载竞价网络推广培训
  • 旅游资讯网站建设方案厦门seo代运营
  • 工程建设与设计期刊网站西地那非能提高硬度吗
  • 汽车网络营销方式北京云无限优化