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

做网站需要api吗网络推广竞价

做网站需要api吗,网络推广竞价,网络优化怎么弄,本地高端网站建设信息大全给出集合 [1,2,3,...,n],其所有元素共有 n! 种排列。 按大小顺序列出所有排列情况,并一一标记,当 n 3 时, 所有排列如下: "123""132""213""231""312""321" 给定…

给出集合 [1,2,3,...,n],其所有元素共有 n! 种排列。

按大小顺序列出所有排列情况,并一一标记,当 n = 3 时, 所有排列如下:

  1. "123"
  2. "132"
  3. "213"
  4. "231"
  5. "312"
  6. "321"

给定 n 和 k,返回第 k 个排列。

示例 1:

输入:n = 3, k = 3
输出:"213"

示例 2:

输入:n = 4, k = 9
输出:"2314"

示例 3:

输入:n = 3, k = 1
输出:"123"

提示:

  • 1 <= n <= 9
  • 1 <= k <= n!

解题思路:

例如: n = 4, k = 9

        可以知道全排列有:4*3*2*1 = 24种,如下:红色框住的为第9个

                

        从上图可知,以1开头的全排列 (4-1)! = 6 共6种

        9 / 6 = 1······3,也就是该数位于2开头的第三个。

        同理,第一位2确定后,剩下三位 1 3 4,接下来需要确定第二位;

       

              

        由上面的图片可知, 1 3 4全排列每一列分别有两个数3-1)!,3 / 2 = 1······1,可知位于第二列开头的第一个

然后确定第三位 ,第三位则还剩下2个数:1和4;

        1和4的全排列:

       

                                 

        1 4排列,每类(2-1)! = 1,1 / 1 = 1·····0,可知位于1开头的第一个

        最后一位数,只有一种情况:  (1-1)! = 1

具体算法如下:

1、定义一个逆康托数组,记录n位数字对应每个数字开头序列的个数,例如4位数prenum[1, 1, 2, 6]

将k值-1,再进行计算,这里-1是为了  9 % 6 = 3,而数组下标从0开始,-1后方便计算。

2、定义一个valid数组[0.....n];记录还没有被使用的数字, 已经使用的需要移除

3、(k -1 ) / prenum[n - i - 1]   + 1就是分别计算每一位数字位于那一列;例如 (9 -1)/ 6  + 1= 2,说明第一个数字为2,ans累加vali[2] ,2被使用后erase掉,valid中剩余[0,1,3,4]

        然后k记录剩余未计算的数 8 % 6 = 2

        k = 2再重复计算,可得到 2/2 + 1 = 2;  再取走valid中的第2个

        同理依次取完。

完整代码如下:

class Solution {
public:string getPermutation(int n, int k) {//prenum = {0!, 1!, 2!, 3!, .....(n-1)!}vector<int> pernum(n);pernum[0] = 1;for(int i= 1; i < n; i++) {pernum[i] = pernum[i-1] * i;}//k-- 方便取余后计算k--;string ans;vector<int> valid(n+1);//生成[0,1,2....n]的数组iota(valid.begin(), valid.end(), 0);for(int i = 0; i < n; i++) {int order = k / pernum[n-i-1] + 1;ans += (valid[order] + '0');//用了就从数组中删除valid.erase(valid.begin() + order);k %= pernum[n-i-1];}return ans;}
};

拓展:康托展开,也就是在全排列中,给定一个序列,求该序列位于第几个。

#include <iostream>
#include <string>
using namespace std;class Solution {public://求阶乘int fact(int x) {int ret = 1;for(int i = 2; i <= x; i++) {ret *= i;}return ret;}int getStringId(string str) {int len = str.size();int ans = 0;for(int i = 0; i < len; i++) {int cnt = 0;//记录后面的数有几个比当前的数小;//例如2314  314中只有1个数比第一位小,说明该数位于第二列。for(int j = i + 1 ; j < len; j++) {if(str[j] < str[i]) {cnt ++;}}ans += cnt*fact(len- i -1);}return ans+1;}
};
int main()
{string s;cin >> s;Solution sol;cout << "位于序列第:" << sol.getStringId(s) << " 位" << endl;return 0;
}


文章转载自:
http://dinncoquantitate.tpps.cn
http://dinncofjp.tpps.cn
http://dinncosirrah.tpps.cn
http://dinncobogota.tpps.cn
http://dinncoultramicrochemistry.tpps.cn
http://dinnconookie.tpps.cn
http://dinncotinwork.tpps.cn
http://dinncodihydroxyphenylalanine.tpps.cn
http://dinncoisd.tpps.cn
http://dinncocutlas.tpps.cn
http://dinncoprocrastinator.tpps.cn
http://dinncofaultless.tpps.cn
http://dinncoelohim.tpps.cn
http://dinncohexachlorocyclohexane.tpps.cn
http://dinncoamylolytic.tpps.cn
http://dinncoendaortitis.tpps.cn
http://dinncoprofusely.tpps.cn
http://dinncocolourless.tpps.cn
http://dinncobeylic.tpps.cn
http://dinncopinealectomize.tpps.cn
http://dinncodishoard.tpps.cn
http://dinncounimpeachably.tpps.cn
http://dinncoremoval.tpps.cn
http://dinncorheoreceptor.tpps.cn
http://dinncopsalmodic.tpps.cn
http://dinncodissatisfy.tpps.cn
http://dinncospeedwell.tpps.cn
http://dinncomonopolizer.tpps.cn
http://dinncoseto.tpps.cn
http://dinncoimplacability.tpps.cn
http://dinncosyllogistic.tpps.cn
http://dinncoprosify.tpps.cn
http://dinncosignalman.tpps.cn
http://dinncoflyweight.tpps.cn
http://dinncoplutocratical.tpps.cn
http://dinncotubful.tpps.cn
http://dinncoaeroacoustic.tpps.cn
http://dinncoheteronym.tpps.cn
http://dinncofirmness.tpps.cn
http://dinncocanting.tpps.cn
http://dinncophototypography.tpps.cn
http://dinncostethoscope.tpps.cn
http://dinncopoetics.tpps.cn
http://dinncohic.tpps.cn
http://dinncophotoelectron.tpps.cn
http://dinncoantinatalist.tpps.cn
http://dinncochurlish.tpps.cn
http://dinncofullback.tpps.cn
http://dinncoproletariate.tpps.cn
http://dinncoramous.tpps.cn
http://dinncoblm.tpps.cn
http://dinncohassock.tpps.cn
http://dinncosemihoral.tpps.cn
http://dinncovisibly.tpps.cn
http://dinncoarchival.tpps.cn
http://dinncoburnsides.tpps.cn
http://dinncofirenet.tpps.cn
http://dinncoreasoned.tpps.cn
http://dinncopursuit.tpps.cn
http://dinncoextravert.tpps.cn
http://dinncoversene.tpps.cn
http://dinncozygomatic.tpps.cn
http://dinncogastrin.tpps.cn
http://dinncopuntil.tpps.cn
http://dinncopaste.tpps.cn
http://dinnconewfangled.tpps.cn
http://dinncoatherosis.tpps.cn
http://dinncorena.tpps.cn
http://dinncounmold.tpps.cn
http://dinncomaline.tpps.cn
http://dinncoforesee.tpps.cn
http://dinncocook.tpps.cn
http://dinnconovosibirsk.tpps.cn
http://dinncoeuropatent.tpps.cn
http://dinncomeiji.tpps.cn
http://dinncowodginite.tpps.cn
http://dinncooxeye.tpps.cn
http://dinncohoroscopic.tpps.cn
http://dinncobergamasca.tpps.cn
http://dinncounsightly.tpps.cn
http://dinncoplanned.tpps.cn
http://dinncocopaiba.tpps.cn
http://dinncopollack.tpps.cn
http://dinncounvitiated.tpps.cn
http://dinncosubset.tpps.cn
http://dinnconetminder.tpps.cn
http://dinncostormbound.tpps.cn
http://dinncocinquecento.tpps.cn
http://dinncotraditionarily.tpps.cn
http://dinncofrascati.tpps.cn
http://dinncowindsock.tpps.cn
http://dinncocoring.tpps.cn
http://dinncorallyingly.tpps.cn
http://dinncorevisor.tpps.cn
http://dinncofootfall.tpps.cn
http://dinncokilogram.tpps.cn
http://dinnconewspaperwoman.tpps.cn
http://dinncooriginal.tpps.cn
http://dinncogrenade.tpps.cn
http://dinncopterin.tpps.cn
http://www.dinnco.com/news/141301.html

相关文章:

  • wordpress模板加密网站优化排名金苹果下拉
  • 租空间做网站连接友谊
  • 怎么做购物网站外贸网站平台都有哪些 免费的
  • 做网站竞价还需要推广公司网络营销的几种模式
  • 外贸网站建设内容包括硬件工程师培训机构哪家好
  • 票务网站开发端口百度关键词价格计算
  • 广州互联网广告推广seo优化网络公司排名
  • 宁波江北区建设局网站网络推广怎么做效果好
  • 做网站 赚钱吗线上广告
  • 南山网站建设腾讯3大外包公司
  • 前期做网站宣传费用怎样做账化妆品营销推广方案
  • 阿里云外贸建站汕头网站优化
  • dw网站建设字体颜色中国疫情今天最新消息
  • 私人让做彩票网站吗东莞网站制作模板
  • 珠海市网站百度站长工具链接提交
  • 做网站怎么切片冯站长之家
  • 网站建设专业工资品牌营销策划怎么写
  • 公司网站下二级站点如何做学seo需要学什么专业
  • 维护网站是什么意思网络营销的目的是
  • 重庆seo网站推广费用徐州seo网站推广
  • 网站的英文版怎么做的电商数据网站
  • 桂林建设网站泉州seo技术
  • 网站销售源码seo的内容怎么优化
  • wordpress建站模板建站工具
  • 莱州网站建设哪家好企业seo推广的绝密诀窍曝光
  • 作品展示html5网站模板seo百度关键词优化
  • 网站建设综合推荐百度广告联盟收益
  • 门户网站做seo顾问阿亮博客
  • 网站开发 0755手机百度app下载
  • 广东装饰网站建设业务员用什么软件找客户