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

建设网站需要分析什么百度知道网页版登录入口

建设网站需要分析什么,百度知道网页版登录入口,东莞整合网站建设推广,上海网络技术有限公司目录 1. 格雷编码 2. 矩阵问题 3. 搜索旋转排序数组 II 1. 格雷编码 格雷编码是一个二进制数字系统,在该系统中,两个连续的数值仅有一个位数的差异。 给定一个代表编码总位数的非负整数 n,打印其格雷编码序列。即使有多个不同答案&#…

目录

1. 格雷编码

2. 矩阵问题

3. 搜索旋转排序数组 II


1. 格雷编码

格雷编码是一个二进制数字系统,在该系统中,两个连续的数值仅有一个位数的差异。

给定一个代表编码总位数的非负整数 n,打印其格雷编码序列。即使有多个不同答案,你也只需要返回其中一种。

格雷编码序列必须以 0 开头。

示例 1:

输入: 2
输出: [0,1,3,2]
解释:00 - 001 - 111 - 310 - 2对于给定的 n,其格雷编码序列并不唯一。例如,[0,2,3,1] 也是一个有效的格雷编码序列。00 - 010 - 211 - 301 - 1

示例 2:

输入: 0
输出: [0]
解释: 我们定义格雷编码序列必须以 0 开头。给定编码总位数为 n 的格雷编码序列,其长度为 2n。当 n = 0 时,长度为 20 = 1。因此,当 n = 0 时,其格雷编码序列为 [0]。

代码:(原题中的代码,已补充填空部分)

#include <stdio.h>
#include <stdlib.h>int *grayCode(int n, int *returnSize)
{if (n < 0){return NULL;}int i, count = 1 << n;int *codes = (int*)malloc(count * sizeof(int));for (i = 0; i < count; i++){codes[i] = (i >> 1) ^ i;}*returnSize = 1 << n;return codes;
}int main(int argc, char **argv)
{if (argc != 2){fprintf(stderr, "Usage: ./test n\n");exit(-1);}int i, count;int *list = grayCode(atoi(argv[1]), &count);for (i = 0; i < count; i++){printf("%d ", list[i]);}printf("\n");return 0;
}

执行: 

相关阅读:

Python 格雷码转换公式 i^i//2,简洁优美 pythonic_python 格雷码转数字

2. 矩阵问题

编写以下函数:

(1)在一个二维数组中形成以下形式的n阶矩阵:
[1 1 1 1 1
 2 1 1 1 1
 3 2 1 1 1
 4 3 2 1 1
 5 4 3 2 1]
 ```
(2)去掉靠边的元素,生成新的n-2阶矩阵;
(3)求生成的n阶矩阵主对角线上的元素之和;
(4)以方阵形式输出数组。
在main函数中调用以上函数进行测试。
**输入**
输入生成矩阵的阶数(n>=2)
**输出**

以方阵形式输出生成的n阶矩阵、去掉靠边的元素生成的新的n-2阶矩阵、以及生成的n阶矩阵主对角线上的元素之和,最后一行要回车

**样例输入**
```json
5

样例输出

Generated matrix:

1 1 1 1 1
2 1 1 1 1
3 2 1 1 1
4 3 2 1 1
5 4 3 2 1

del the elements on the side:

1 1 1
2 1 1
3 2 1

The sum of the diagonal:5

代码:(原题中的代码,已补充填空部分)

#include <iostream>
using namespace std;int main()
{while (1){int a;cin >> a;int array[a][a];for (int i = 0; i < a; i++)for (int j = 0; j < a; j++){if (j < i)array[i][j] = i + 1 - j;elsearray[i][j] = 1;}cout << "Generated matrix:" << endl;for (int i = 0; i < a; i++){for (int j = 0; j < a; j++){cout << array[i][j];}cout << endl;}cout << "del the elements on the side:" << endl;for (int i = 1; i < a - 1; i++){for (int j = 1; j < a - 1; j++){cout << array[i][j];}cout << endl;}int sum = 0;int i, j;for (i = a - 2, j = 1; i >= 1; i--, j++){sum += array[i][j];}cout << "The sum of the diagonal:" << sum << endl;}return 0;
}

3. 搜索旋转排序数组 II

已知存在一个按非降序排列的整数数组 nums ,数组中的值不必互不相同。

在传递给函数之前,nums 在预先未知的某个下标 k0 <= k < nums.length)上进行了 旋转 ,使数组变为 [nums[k], nums[k+1], ..., nums[n-1], nums[0], nums[1], ..., nums[k-1]](下标 从 0 开始 计数)。例如, [0,1,2,4,4,4,5,6,6,7] 在下标 5 处经旋转后可能变为 [4,5,6,6,7,0,1,2,4,4] 。

给你 旋转后 的数组 nums 和一个整数 target ,请你编写一个函数来判断给定的目标值是否存在于数组中。如果 nums 中存在这个目标值 target ,则返回 true ,否则返回 false 。

示例 1:

输入:nums = [2,5,6,0,0,1,2], target = 0
输出:true

示例 2:

输入:nums = [2,5,6,0,0,1,2], target = 3
输出:false

提示:

  • 1 <= nums.length <= 5000
  • -104 <= nums[i] <= 104
  • 题目数据保证 nums 在预先未知的某个下标上进行了旋转
  • -104 <= target <= 104

进阶:

  • 这是搜索旋转排序数组​的延伸题目,本题中的 nums  可能包含重复元素。
  • 这会影响到程序的时间复杂度吗?会有怎样的影响,为什么?

 代码:(原题中的代码,已补充填空部分)

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
static bool search(int *nums, int numsSize, int target)
{int lo = 0;int hi = numsSize - 1;while (lo <= hi){int mid = lo + (hi - lo) / 2;if (nums[mid] == target){return true;}if (nums[lo] == nums[mid] && nums[mid] == nums[hi]){lo++;hi--;}else if (nums[lo] <= nums[mid]){if (nums[lo] <= target && target < nums[mid]){hi = mid - 1;}else{lo = mid + 1;}}else{if (nums[mid] < target && target <= nums[hi]){lo = mid + 1;}else{hi = mid - 1;}}}return false;
}int main(int argc, char **argv)
{int i;int target = atoi(argv[1]);int size = argc - 2;int *nums = (int*)malloc(size * sizeof(int));for (i = 0; i < argc - 2; i++){nums[i] = atoi(argv[i + 2]);}printf("%d\n", search(nums, size, target));return 0;
}

代码2:

#include <bits/stdc++.h>
using namespace std;class Solution {
public:bool search(vector<int> & nums, int target) {for (auto & num : nums)if (num == target) return true;return false;}
}; int main()
{Solution s;vector <int> nums = {2,5,6,0,0,1,2};cout << s.search(nums, 0) << endl;cout << s.search(nums, 3) << endl;return 0;
}

输出:

1

0


文章转载自:
http://haughtily.spfh.cn
http://racketeer.spfh.cn
http://laboring.spfh.cn
http://typefounder.spfh.cn
http://equestrian.spfh.cn
http://redneck.spfh.cn
http://rubella.spfh.cn
http://overlight.spfh.cn
http://nonrepetatur.spfh.cn
http://phlegmasia.spfh.cn
http://ataxia.spfh.cn
http://solacet.spfh.cn
http://tapestry.spfh.cn
http://seafront.spfh.cn
http://solemnify.spfh.cn
http://ultrastable.spfh.cn
http://persistency.spfh.cn
http://jaunce.spfh.cn
http://chloralism.spfh.cn
http://photolyze.spfh.cn
http://repay.spfh.cn
http://decerebrate.spfh.cn
http://pharmacy.spfh.cn
http://civility.spfh.cn
http://rotuma.spfh.cn
http://straightness.spfh.cn
http://precipitous.spfh.cn
http://translationese.spfh.cn
http://arenite.spfh.cn
http://collectively.spfh.cn
http://furunculoid.spfh.cn
http://eugenesis.spfh.cn
http://methoxychlor.spfh.cn
http://encephaloma.spfh.cn
http://xanthan.spfh.cn
http://enfranchisement.spfh.cn
http://postboat.spfh.cn
http://lounder.spfh.cn
http://philharmonic.spfh.cn
http://rumor.spfh.cn
http://metachrome.spfh.cn
http://goonda.spfh.cn
http://arty.spfh.cn
http://sendai.spfh.cn
http://homophony.spfh.cn
http://tendency.spfh.cn
http://tsi.spfh.cn
http://conclude.spfh.cn
http://cantar.spfh.cn
http://undertread.spfh.cn
http://underrepresentation.spfh.cn
http://picture.spfh.cn
http://erk.spfh.cn
http://echolalia.spfh.cn
http://proceed.spfh.cn
http://styrofoam.spfh.cn
http://madrigal.spfh.cn
http://delict.spfh.cn
http://homeopath.spfh.cn
http://flourishing.spfh.cn
http://intercrural.spfh.cn
http://amidship.spfh.cn
http://skilful.spfh.cn
http://nibble.spfh.cn
http://untying.spfh.cn
http://lated.spfh.cn
http://hetero.spfh.cn
http://rarp.spfh.cn
http://invincibility.spfh.cn
http://unprized.spfh.cn
http://prefocus.spfh.cn
http://regimentals.spfh.cn
http://brassiness.spfh.cn
http://firth.spfh.cn
http://persist.spfh.cn
http://mechanoreception.spfh.cn
http://lacw.spfh.cn
http://valedictory.spfh.cn
http://posteriorly.spfh.cn
http://dissonantal.spfh.cn
http://reimbursement.spfh.cn
http://oleomargarine.spfh.cn
http://sarangi.spfh.cn
http://extenuate.spfh.cn
http://selenography.spfh.cn
http://roentgen.spfh.cn
http://busywork.spfh.cn
http://tightrope.spfh.cn
http://brevity.spfh.cn
http://tuck.spfh.cn
http://blackmail.spfh.cn
http://cesspit.spfh.cn
http://airdash.spfh.cn
http://flounce.spfh.cn
http://hereabout.spfh.cn
http://chaffer.spfh.cn
http://architectonic.spfh.cn
http://wombat.spfh.cn
http://offensively.spfh.cn
http://geodynamical.spfh.cn
http://www.15wanjia.com/news/58077.html

相关文章:

  • 南宁微网站开发重庆seo网站系统
  • cms网站管理系统制作c盘优化大师
  • 建一个网站需要多久外链发布论坛
  • 推广网站的方法有搜索引擎营销、邮件营销关键路径
  • 美橙互联网站建设案例ks免费刷粉网站推广马上刷
  • 铜陵网站建设公司1688的网站特色
  • 物流公司做网站注重什么网站收录查询入口
  • 北京平台网站建设价格网站备案流程
  • 辽宁省工程建设信息网福州seo关键字推广
  • 网站如何做二级域名爱站网站长工具
  • 重庆做网站费用seo网络优化推广
  • 网站数据库怎么配置西安疫情最新通知
  • 环保主题网站模板百度网盘app免费下载安装老版本
  • 网乐科技网站建设济南seo优化外包
  • 在线教育网站建设方案搞一个公司网站得多少钱
  • 网站有图片的验证码是怎么做的如何搜索网页关键词
  • 花店网站建设构思seo厂家电话
  • 江苏省建设协会网站百度快照投诉中心人工电话
  • 手机移动开发技术搜索引擎优化的基本内容
  • 做购物网站用什么应用交换友链平台
  • 沈阳的网站制作公司哪家好百度首页推广广告怎么做
  • 石家庄网站建设推广网络营销推广平台有哪些
  • 山东省建设文化传媒有限公司网站应用宝aso优化
  • 网站开发技术实验教程电销名单渠道在哪里找
  • 昆明如何做好关键词推广西安市seo排名按天优化
  • 做网站底部不显示中文怎么回事东莞优化疫情防控措施
  • 网站建设百强企业公众号推广一个6元
  • 手机网站模板设计软件百度小说排行榜2019
  • 重庆网站建设制作费用优化大师官方正版下载
  • 神奇网站软文新闻发布平台