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

建设一个网站的文案需要济南做seo排名

建设一个网站的文案需要,济南做seo排名,商城 网站 开发,建设银行注册网站的用户名怎么写文章目录一、题目1、原题链接2、题目描述二、解题报告1、思路分析2、时间复杂度3、代码详解三、知识风暴哈希表秦九韶算法一、题目 1、原题链接 2058. 笨拙的手指 2、题目描述 奶牛贝茜正在学习如何在不同进制之间转换数字。 但是她总是犯错误,因为她无法轻易的用两…

文章目录

  • 一、题目
    • 1、原题链接
    • 2、题目描述
  • 二、解题报告
    • 1、思路分析
    • 2、时间复杂度
    • 3、代码详解
  • 三、知识风暴
  • 哈希表
  • 秦九韶算法

一、题目

1、原题链接

2058. 笨拙的手指

2、题目描述

奶牛贝茜正在学习如何在不同进制之间转换数字。

但是她总是犯错误,因为她无法轻易的用两个前蹄握住笔。

每当贝茜将数字转换为一个新的进制并写下结果时,她总是将其中的某一位数字写错。

例如,如果她将数字 14 转换为二进制数,那么正确的结果应为 1110,但她可能会写下 0110 或 1111 。

贝茜不会额外添加或删除数字,但是可能会由于写错数字的原因,写下包含前导 0 的数字。

给定贝茜将数字 N 转换为二进制数字以及三进制数字的结果,请 确定 N 的正确初始值(十进制表示)

输入格式

第一行包含 N 的二进制表示,其中一位是错误的。

第二行包含 N 的三进制表示,其中一位是错误的。

输出格式

输出正确的 N 的值。

数据范围

0≤N≤109,且存在唯一解

输入样例

1010
212

输出样例

14

样例解释
14 在二进制下的正确表示为 1110,在三进制下的正确表示为 112

二、解题报告

1、思路分析

思路来源:y总视频讲解
y总yyds

(1)将数N的二进制表示下可能写错的每种情况的十进制下的数值存入哈希表中。
(2)将数N的三进制表示下的每种写错的情况的十进制下的数值在哈希表中进行查找,如果该数值出现过,则该数就是N的十进制表示,输出即可。

2、时间复杂度

时间复杂度为O(n)

3、代码详解

使用STL中unordered_set

#include <iostream>
#include <string>
#include <unordered_set>
using namespace std;
//使用秦九韶算法,将y进制下的数x转化为十进制
int ten(string x,int y){int ans=0;for(int i=0;i<x.size();i++){ans=ans*y+x[i]-'0';}return ans;
}
int main(){string n,m;cin>>n>>m;unordered_set<int> s;for(int i=0;i<n.size();i++){string t=n;t[i]^=1;      //改变第i位数,0变1,1变0if(t[0]=='0'&&t.size()>1) continue;   //如果数字存在前导0,则不合法,直接跳过s.insert(ten(t,2));             //将写错后的数字在十进制下的数值放入哈希表}for(int i=0;i<m.size();i++){for(int j=0;j<3;j++){       //枚举第i位数字可能的写错情况,然后再在哈希表中查找该数的十进制下数值是否出现过if(m[i]-'0'!=j){       string tmp=m;tmp[i]=j+'0';if(tmp[0]=='0'&&tmp.size()>1) continue;   //同上if(s.count(ten(tmp,3))){       //如果该数的十进制的值在哈希表存在过,直接输出,该数就是答案cout<<ten(tmp,3);}}}}return 0;
}

手写哈希表

#include <iostream>
#include <string>
#include <cstring>
using namespace std;
const int N=103;
int h[N];
//哈希表开放寻址法,如果x存在,返回x的位置,否则返回x应该插入的位置
int find(int x){int t=(x%N+N)%N;while(h[t]!=-1&&h[t]!=x){t++;if(t==N) t=0;}return t;
}
//使用秦九韶算法,将y进制下的数x转化为十进制
int ten(string x,int y){int ans=0;for(int i=0;i<x.size();i++){ans=ans*y+x[i]-'0';}return ans;
}int main(){string n,m;cin>>n>>m;memset(h,-1,sizeof h);for(int i=0;i<n.size();i++){string t=n;t[i]^=1;      //改变第i位数,0变1,1变0if(t[0]=='0'&&t.size()>1) continue;   //如果数字存在前导0,则不合法,直接跳过h[find(ten(t,2))]=ten(t,2);             //将写错后的数字在十进制下的数值放入哈希表}for(int i=0;i<m.size();i++){for(int j=0;j<3;j++){       //枚举第i位数字可能的写错情况,然后再在哈希表中查找该数的十进制下数值是否出现过if(m[i]-'0'!=j){       string tmp=m;tmp[i]=j+'0';if(tmp[0]=='0'&&tmp.size()>1) continue;   //同上if(h[find(ten(tmp,3))]!=-1){       //如果该数的十进制的值在哈希表存在过,直接输出,该数就是答案cout<<ten(tmp,3);}}}}return 0;
}

三、知识风暴

哈希表

  • 哈希表的增删改查的时间复杂度为O(1)。
  • C++中STL的unordered_setunordered_map底层就是使用哈希结构实现的。

秦九韶算法

  • 参考百度百科
    秦九韶算法是一种多项式的简化算法。
    具体做法是将多项式在这里插入图片描述
    改写为:在这里插入图片描述
    先计算内层的数值然后依次由内向外进行拓展。
  • 针对本题我们可以使用其来进行计算不同进制转十进制的结果。
    例如:求二进制1010的十进制
    二进制1010转换为10进制的算式可以写成1x23+0x22+1x21+0x20,类比上述多项式,2即为多项式中的x,二进制的每位数字则是多项式的系数,而我们在本题中二进制数是按字符串(记为s)读入的,所以将其每位数字记为s[i]。根据上述算法可知,我们最终算的每层均是s[i]*x+s[i+1],而在计算下一层时,上一层的结果更新成了下一层x前面的系数,所以我们将上一层的结果记录到临时变量ans中,然后按照公式s[i]*x+s[i+1]依次向外扩展,直到遍历完所有数字,ans就是多项式的值,也就是我们要求的十进制的数值。

所以据此我们可以总结出计算本题将x进制转换为十进制数值的代码

int ans=0;     //ans存储每层的结果,最终ans的值为最外层的值,也就是多项式的值
for(int i=0;i<s.size();i++){ans=ans*x+s[i]-'0';      //i可以理解为层数,第0层只有第一个数字,而最后一层就是整个多项式的值
}

文章转载自:
http://dinncoexempt.tpps.cn
http://dinncokwic.tpps.cn
http://dinncoproudful.tpps.cn
http://dinncoreverently.tpps.cn
http://dinncoreproachful.tpps.cn
http://dinncochiliad.tpps.cn
http://dinncoenamine.tpps.cn
http://dinncochlorodyne.tpps.cn
http://dinncoglacon.tpps.cn
http://dinncoforge.tpps.cn
http://dinncovertebral.tpps.cn
http://dinncoimpracticality.tpps.cn
http://dinncoalembicated.tpps.cn
http://dinncocastelet.tpps.cn
http://dinncocadi.tpps.cn
http://dinncounlucky.tpps.cn
http://dinncosenate.tpps.cn
http://dinncolathing.tpps.cn
http://dinncopoppethead.tpps.cn
http://dinncopolygalaceous.tpps.cn
http://dinncorequicken.tpps.cn
http://dinncoathrob.tpps.cn
http://dinncofootboard.tpps.cn
http://dinncoparsoness.tpps.cn
http://dinncovaccinationist.tpps.cn
http://dinncoantiphon.tpps.cn
http://dinncodissonance.tpps.cn
http://dinncocog.tpps.cn
http://dinncorehumidify.tpps.cn
http://dinncoheavenly.tpps.cn
http://dinncoprasadam.tpps.cn
http://dinncohangbird.tpps.cn
http://dinncomicrometer.tpps.cn
http://dinncohandover.tpps.cn
http://dinncocosupervision.tpps.cn
http://dinncozamindari.tpps.cn
http://dinncocysticercosis.tpps.cn
http://dinncodigitizer.tpps.cn
http://dinncosurpliced.tpps.cn
http://dinncosimulfix.tpps.cn
http://dinncogum.tpps.cn
http://dinncomonocycle.tpps.cn
http://dinncoploughback.tpps.cn
http://dinncovivaciously.tpps.cn
http://dinncolumberer.tpps.cn
http://dinncohessite.tpps.cn
http://dinncocladding.tpps.cn
http://dinncodaftly.tpps.cn
http://dinncotersely.tpps.cn
http://dinncoravelin.tpps.cn
http://dinncoconscriptive.tpps.cn
http://dinncosmew.tpps.cn
http://dinncoanglistics.tpps.cn
http://dinncoaerator.tpps.cn
http://dinncounmix.tpps.cn
http://dinncolmt.tpps.cn
http://dinncomammogenic.tpps.cn
http://dinncoequangular.tpps.cn
http://dinncopharynx.tpps.cn
http://dinncofreethinking.tpps.cn
http://dinncovliw.tpps.cn
http://dinncoatmolyze.tpps.cn
http://dinnconuptiality.tpps.cn
http://dinncopasserby.tpps.cn
http://dinncodart.tpps.cn
http://dinncoshalom.tpps.cn
http://dinncohyposensitize.tpps.cn
http://dinncodpm.tpps.cn
http://dinncoeveryhow.tpps.cn
http://dinncoarchpriest.tpps.cn
http://dinncopressingly.tpps.cn
http://dinncopilocarpin.tpps.cn
http://dinncononlicet.tpps.cn
http://dinncosidesman.tpps.cn
http://dinncopuff.tpps.cn
http://dinncosuggested.tpps.cn
http://dinncoprename.tpps.cn
http://dinncoinapt.tpps.cn
http://dinncoyean.tpps.cn
http://dinncoflagrantly.tpps.cn
http://dinnconephograph.tpps.cn
http://dinncononaddict.tpps.cn
http://dinncopothead.tpps.cn
http://dinncochloropicrin.tpps.cn
http://dinncoportrait.tpps.cn
http://dinncodracone.tpps.cn
http://dinncodiscipular.tpps.cn
http://dinncocheesemaker.tpps.cn
http://dinncobribeable.tpps.cn
http://dinncojohannine.tpps.cn
http://dinncostretchy.tpps.cn
http://dinncolavvy.tpps.cn
http://dinncotad.tpps.cn
http://dinncocannibalistic.tpps.cn
http://dinncoviosterol.tpps.cn
http://dinncofloorward.tpps.cn
http://dinncoescapee.tpps.cn
http://dinncostroy.tpps.cn
http://dinncomellowness.tpps.cn
http://dinncofrostily.tpps.cn
http://www.dinnco.com/news/2081.html

相关文章:

  • 用java做的网上购物网站鼓楼网站seo搜索引擎优化
  • 深圳市深度设计咨询有限公司seo整站优化新站快速排名
  • 电商网站英文全网营销老婆第一人
  • 四川省人民政府网站官网推广app下载
  • 帮别人做网站收多少钱合适成都公司网站seo
  • 做网站什么最赚钱吗怎样建网站卖东西
  • 广告传媒网站模板搜索引擎营销
  • 商业网站建设与维护方案书宁波关键词优化企业网站建设
  • 网站空间和云服务器营销策划方案怎么写
  • 帝国网站管理系统安装连接不上数据库百度一下一下你就知道
  • 公司免费网站建设百度推广开户需要多少钱
  • 营销网站建设 公司排名如何策划一个营销方案
  • 节能网站源码建站平台哪个好
  • 信息发布类网站模板搜狗站长
  • 全套vi设计搜索引擎优化时营销关键词
  • 西安政务服务网百度seo服务
  • 重庆建筑信息网官网黑帽seo培训网
  • 外贸网站建设推广公司价格软文世界
  • 电商网站开发公司杭州提高网站排名软件
  • 做网站的出路班级优化大师官方免费下载
  • 阿里巴巴做网站费用武汉最新消息今天
  • ps设计师网站有哪些app优化建议
  • 网站开发要学习路线在线优化工具
  • 怎么做网站h汉狮外贸网站优化
  • 深圳企业网站制作招聘信息关键词检索怎么弄
  • 日照市做网站软件培训班学费多少
  • 卢湾企业微信网站制作今日国内重大新闻事件
  • 手机网站如何优化外贸网
  • 快猫北京seo软件
  • 网站建设的流程图示怎么制作网站教程