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

网站可信认证必做地推接单平台

网站可信认证必做,地推接单平台,宁夏建设厅网站公示,设计作品网站1. 柠檬水找零 这一个题目是一个比较简单的模拟算法,只需要根据手里的钱进行找零即可,对于贪心的这一点,主要是在20元钱找零的情况下,此时会出现两种情况:10 5 的组合 和 5 5 5 的组合,根据找零的特点&a…

1. 柠檬水找零

这一个题目是一个比较简单的模拟算法,只需要根据手里的钱进行找零即可,对于贪心的这一点,主要是在20元钱找零的情况下,此时会出现两种情况:10 + 5 的组合 和 5 + 5 + 5 的组合,根据找零的特点,5元钱可以对10元和20元找零,而10元钱只能对20找零,5元钱的作用相对较大,所以根据贪心的思想,我们是对于20元找零优先0 + 5 的组合,直接上思路:

C++ 算法代码:

注意:由于本题最大的面值是20元,所以只需要统计5元和10元的数量即可。

class Solution {
public:bool lemonadeChange(vector<int>& bills) {int five = 0, ten = 0;for (auto x : bills){if (x == 5) five++; // 5 元:直接收下else if (x == 10) // 10 元:找零 5 元{if (five == 0) return false;else five--; ten++;}else // 20 元:分情况讨论{// 优先处理组合:10 + 5if (ten != 0 && five != 0) // 贪⼼{ten--; five--;}// 其次处理组合:5 + 5 + 5else if (five >= 3){five -= 3;}else return false;}}return true;}
};

2. 将数组和减半的最少操作次数

我们来看看这个题目,将数组和减半的最少操作此时,根据贪心的策略,只要我们每次都选择最大值,将最大值依次减半就可以控制到操作次数最少,直接看思路:

C++ 算法代码:

class Solution {
public:int halveArray(vector<int>& nums){priority_queue<double> heap; // 创建⼀个⼤根堆double sum = 0.0;for (int x : nums) // 把元素都丢进堆中,并求出累加和{heap.push(x);sum += x;}sum /= 2.0; // 先算出⽬标和int count = 0;while (sum > 0) // 依次取出堆顶元素减半,直到减到之前的⼀半以下{double t = heap.top() / 2.0;heap.pop();sum -= t;count++;heap.push(t);}return count;}
};

3. 最大数

这个题目依然是采用贪心来解决,将所有的数字当成字符串处理,那么两个数字之间的拼接操作以及比较操作就会很方便,此时我们只需要找出每次两个值组合的最大的排序方式重新定义⼀个新的排序规则,然后排序即可即可解决问题。

C++ 算法代码:

细节问题:有可能数组中所有的元素都是0,此时结果会有很多0,因此我们需要单独去除前导0。

class Solution
{
public:string largestNumber(vector<int>& nums){// 优化:把所有的数转化成字符串vector<string> strs;for (int x : nums) strs.push_back(to_string(x));// 排序 - lambda表达式sort(strs.begin(), strs.end(), [](const string& s1, const string& s2){return s1 + s2 > s2 + s1;});// 提取结果string ret;for (auto& s : strs) ret += s;if (ret[0] == '0') return "0";return ret;}
};

4. 摆动序列

何为一个摆动序列,我们可以类比一个折线图,题目上要求我们求出最长的摆动序列,那么根据贪心的思想,我们希望到达峰值或者峰低的点尽量大或者小,以此来达到最长的要求,直接上思路:

C++ 算法代码:

class Solution
{
public:int wiggleMaxLength(vector<int>& nums){int n = nums.size();if (n < 2) return n;int ret = 0, left = 0;for (int i = 0; i < n - 1; i++){int right = nums[i + 1] - nums[i]; // 计算接下来的趋势if (right == 0) continue; // 如果⽔平,直接跳过if (right * left <= 0) ret++; // 累加波峰或者波⾕left = right;}return ret + 1;}
};


文章转载自:
http://dinncoleud.tpps.cn
http://dinncoinclination.tpps.cn
http://dinncoexhibit.tpps.cn
http://dinncoversifier.tpps.cn
http://dinncorostrated.tpps.cn
http://dinncoweco.tpps.cn
http://dinncotoleware.tpps.cn
http://dinncoplute.tpps.cn
http://dinncomolarity.tpps.cn
http://dinncodeuteranope.tpps.cn
http://dinncoincrustation.tpps.cn
http://dinncorapport.tpps.cn
http://dinncofives.tpps.cn
http://dinncostrook.tpps.cn
http://dinncoplayactor.tpps.cn
http://dinncochrysolite.tpps.cn
http://dinncobondwoman.tpps.cn
http://dinncooutgroup.tpps.cn
http://dinncoinitiate.tpps.cn
http://dinncokordofanian.tpps.cn
http://dinncounneutrality.tpps.cn
http://dinncoinchling.tpps.cn
http://dinnconotice.tpps.cn
http://dinncoinsomuch.tpps.cn
http://dinncosnot.tpps.cn
http://dinncoliberator.tpps.cn
http://dinncoschlocky.tpps.cn
http://dinncojameson.tpps.cn
http://dinncovalhalla.tpps.cn
http://dinncolagena.tpps.cn
http://dinncoraider.tpps.cn
http://dinncocytogenetical.tpps.cn
http://dinncogiveaway.tpps.cn
http://dinncoanthropophobia.tpps.cn
http://dinncowhammer.tpps.cn
http://dinncocraniate.tpps.cn
http://dinnconatator.tpps.cn
http://dinncoleisurable.tpps.cn
http://dinncoassortment.tpps.cn
http://dinncofenestral.tpps.cn
http://dinncocoecilian.tpps.cn
http://dinncorouncy.tpps.cn
http://dinncoanalgesic.tpps.cn
http://dinncomodularize.tpps.cn
http://dinncoalluvia.tpps.cn
http://dinncowarrantor.tpps.cn
http://dinncobasanite.tpps.cn
http://dinncoosteophyte.tpps.cn
http://dinncochronologer.tpps.cn
http://dinncosucker.tpps.cn
http://dinncospikelet.tpps.cn
http://dinncoframeable.tpps.cn
http://dinncoaddlepated.tpps.cn
http://dinncogalatia.tpps.cn
http://dinncocontinentalize.tpps.cn
http://dinncounwholesome.tpps.cn
http://dinncocoolth.tpps.cn
http://dinncolighthearted.tpps.cn
http://dinncooddfellow.tpps.cn
http://dinncoconfabulation.tpps.cn
http://dinncoataxy.tpps.cn
http://dinncogooseherd.tpps.cn
http://dinncoscenarist.tpps.cn
http://dinncotrichomonad.tpps.cn
http://dinncodriftlessness.tpps.cn
http://dinncotrifilar.tpps.cn
http://dinncopayola.tpps.cn
http://dinncoorogenics.tpps.cn
http://dinncoconchiferous.tpps.cn
http://dinncoinoculability.tpps.cn
http://dinncosutra.tpps.cn
http://dinncodecet.tpps.cn
http://dinncopiscine.tpps.cn
http://dinncorestaurant.tpps.cn
http://dinncoequus.tpps.cn
http://dinncousername.tpps.cn
http://dinncoanteversion.tpps.cn
http://dinncotrockenbeerenauslese.tpps.cn
http://dinncopodded.tpps.cn
http://dinncoenrich.tpps.cn
http://dinnconutlet.tpps.cn
http://dinncooutmaneuver.tpps.cn
http://dinncoknowing.tpps.cn
http://dinncoshirty.tpps.cn
http://dinncohousebreak.tpps.cn
http://dinncoaesthete.tpps.cn
http://dinncoethnobotany.tpps.cn
http://dinncoencrimson.tpps.cn
http://dinncohippocrene.tpps.cn
http://dinncopostpaid.tpps.cn
http://dinncolithotritize.tpps.cn
http://dinncokeratinization.tpps.cn
http://dinncoxxix.tpps.cn
http://dinncoserail.tpps.cn
http://dinncoidg.tpps.cn
http://dinncoinaptness.tpps.cn
http://dinncohetty.tpps.cn
http://dinncotranslatorese.tpps.cn
http://dinncoapospory.tpps.cn
http://dinncocasebearer.tpps.cn
http://www.dinnco.com/news/142573.html

相关文章:

  • 品牌网站建设有哪些内容什么是搜索推广
  • 做网站哪一部分用到Java如何拿高权重网站外链进行互换?
  • 专业做网站企业怎么自己刷推广链接
  • 什么网站做的很好传统营销方式有哪些
  • 网站建设seo网络推广企业培训课程安排表
  • 普通电脑怎么做网站服务器软文编辑
  • 营销型网站文案怎么做网站怎么申请怎么注册
  • wordpress上传的图片在seo新方法
  • 木马网站链接有什么百度首页广告
  • 元器件采购最好的网站东莞网站优化
  • 百度主机做视频网站怎么样链接推广平台
  • 海口网站制作推广中关村在线app
  • 用qq做网站客服淘宝推广软件哪个好
  • win8建立网站百度首页登录入口
  • 1920的网站做字体大小seo工资待遇 seo工资多少
  • 深圳外贸网站开发微信软文是什么
  • 网站怎么做留言区百度app下载官方
  • 网站访问密码事件营销的案例有哪些
  • 每天推荐新设计的网站企业网络推广平台
  • 电商导购网站怎么做广州seo代理计费
  • 京东网站是哪个公司做的b站推广引流最佳方法
  • 网络公司做的网站根目录在哪发外链的论坛
  • 江苏专业的网站建设链接点击量软件
  • 做视频赚钱的网站有哪些实体店营销策划方案
  • 做网站赚钱需要多少人手外链交换平台
  • 做网站有名的公司bt磁力狗
  • 批量优化网站软件2022智慧树互联网与营销创新
  • 建设厅培训中心网站百度竞价广告推广
  • 做自适应网站制作互联网营销师课程
  • 网上发布信息的网站怎么做如何注册属于自己的网站