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

10类地方网站 总有适合你做的网页推广方案

10类地方网站 总有适合你做的,网页推广方案,官方网站手机 优帮云,做网站需要人在看吗周赛题目 边界上的蚂蚁 边界上有一只蚂蚁&#xff0c;它有时向左走&#xff0c;有时向右走。 给你一个非零整数数组nums。蚂蚁会按顺序读取nums中的元素&#xff0c;从第一个元素开始直到结束。每一步&#xff0c;蚂蚁会根据当前元素的值移动&#xff1a; 如果nums[i]<0…

周赛题目

边界上的蚂蚁

边界上有一只蚂蚁,它有时向左走,有时向右走。

给你一个非零整数数组nums。蚂蚁会按顺序读取nums中的元素,从第一个元素开始直到结束。每一步,蚂蚁会根据当前元素的值移动:

如果nums[i]<0,向左移动-nums[i]单位。
如果nums[i]>0,向右移动nums[i]单位。
返回蚂蚁返回到边界上的次数。

解题思路

本题是一道简单题,只要看懂题目,知道是求每次+nums[i]后的值为0的次数即可。

class Solution {public int returnToBoundaryCount(int[] nums) {int result=0;int target=0;for(int tem:nums){target+=tem;if (target==0){result++;}}return result;}
}

将单词恢复初始状态所需的最短时间 I

给你一个下标从0开始的字符串word和一个整数k。

在每一秒,你必须执行以下操作:

移除word的前k个字符。
在word的末尾添加k个任意字符。
注意添加的字符不必和移除的字符相同。但是,必须在每一秒钟都执行两种操作。

返回将word恢复到其初始状态所需的最短时间(该时间必须大于零)。

解题思路

本题需要至少切割1次,最多切割len/k向上取整次必然可以恢复。因为每次切割后面是拼接任意字符,所以只需要考虑切割后剩余的字符串是不是原来word的开头即可。

class Solution {public int minimumTimeToInitialState(String word, int k) {int result=0;int start=k;int len=word.length();int sum = (int) Math.ceil((double) len / k);while(start<len){result++;if (word.indexOf(word.substring(start))==0){return result;}start+=k;}return sum;}
}

找出网格的区域平均强度

给你一个下标从0开始、大小为mxn的网格image,表示一个灰度图像,其中image[i][j]表示在范围[0…255]内的某个像素强度。另给你一个非负整数threshold。

如果image[a][b]和image[c][d]满足|a-c|+|b-d|==1,则称这两个像素是相邻像素。

区域是一个3x3的子网格,且满足区域中任意两个相邻像素之间,像素强度的绝对差小于或等于threshold。

区域内的所有像素都认为属于该区域,而一个像素可以属于多个区域。

你需要计算一个下标从0开始、大小为mxn的网格result,其中result[i][j]是image[i][j]所属区域的平均强度,向下取整到最接近的整数。如果image[i][j]属于多个区域,result[i][j]是这些区域的“取整后的平均强度”的平均值,也向下取整到最接近的整数。如果image[i][j]不属于任何区域,则result[i][j]等于image[i][j]。

返回网格result。

解题思路

遍历所有3*3的子网格,如果存在差值超过threshwold则跳过;如果合法则计算平均值。

public class Solution {public int[][] resultGrid(int[][] a, int threshold) {int m = a.length;int n = a[0].length;int[][] result = new int[m][n];int[][] cnt = new int[m][n];for (int i = 2; i < m; i++) {next: // 定义跳出标签for (int j = 2; j < n; j++) {// 检查左右相邻格子for (int x = i - 2; x <= i; x++) {if (Math.abs(a[x][j - 2] - a[x][j - 1]) > threshold || Math.abs(a[x][j - 1] - a[x][j]) > threshold) {continue next; // 不合法,跳出双重循环}}// 检查上下相邻格子for (int y = j - 2; y <= j; ++y) {if (Math.abs(a[i - 2][y] - a[i - 1][y]) > threshold || Math.abs(a[i - 1][y] - a[i][y]) > threshold) {continue next; // 不合法,跳出双重循环}}// 合法,计算 3x3 子网格的平均值int avg = 0;for (int x = i - 2; x <= i; x++) {for (int y = j - 2; y <= j; y++) {avg += a[x][y];}}avg /= 9;// 更新 3x3 子网格内的 resultfor (int x = i - 2; x <= i; x++) {for (int y = j - 2; y <= j; y++) {result[x][y] += avg; // 先累加,最后再求平均值cnt[x][y]++;}}}}for (int i = 0; i < m; i++) {for (int j = 0; j < n; j++) {if (cnt[i][j] == 0) { // (i,j) 不属于任何子网格result[i][j] = a[i][j];} else {result[i][j] /= cnt[i][j]; // 求平均值}}}return result;}
}

将单词恢复初始状态所需的最短时间 II

给你一个下标从0开始的字符串word和一个整数k。

在每一秒,你必须执行以下操作:

移除word的前k个字符。
在word的末尾添加k个任意字符。
注意添加的字符不必和移除的字符相同。但是,必须在每一秒钟都执行两种操作。

返回将word恢复到其初始状态所需的最短时间(该时间必须大于零)。

解题思路

这道题和第二道题截图思路是一样的,但是不能再用JDK自带的方法区解,会超时。从第二道题中我们能看出来本题的本质上计算s的后缀和s的最长公共前缀的长度,即使用哦个扩展KMP判断,如果最长公共前缀的长度大于等于后缀长度,说明操作可以恢复到初始值。

class Solution {public int minimumTimeToInitialState(String S, int k) {char[] s = S.toCharArray();int n = s.length;int[] z = new int[n];int l = 0, r = 0;for (int i = 1; i < n; i++) {if (i <= r) {z[i] = Math.min(z[i - l], r - i + 1);}while (i + z[i] < n && s[z[i]] == s[i + z[i]]) {l = i;r = i + z[i];z[i]++;}if (i % k == 0 && z[i] >= n - i) {return i / k;}}return (n - 1) / k + 1;}
}

总结

通过总结周赛的解法,学习到自己还有很多不足。同时也学到了一个平时开发不会用到的操作,就是如何用continue跳出双重循环。

后续因为本次题目中所使用到的KMP算法不甚了解,后续需要学习该算法,并输出一篇总结笔记。


文章转载自:
http://dinncopoinsettia.ssfq.cn
http://dinnconaprapath.ssfq.cn
http://dinncoommatidium.ssfq.cn
http://dinncopreferential.ssfq.cn
http://dinncoloblolly.ssfq.cn
http://dinncohuon.ssfq.cn
http://dinncomilitant.ssfq.cn
http://dinncoamebiasis.ssfq.cn
http://dinncodanube.ssfq.cn
http://dinncotelomer.ssfq.cn
http://dinncopuccoon.ssfq.cn
http://dinncounbeloved.ssfq.cn
http://dinncochipmunk.ssfq.cn
http://dinncouncannily.ssfq.cn
http://dinncosoleus.ssfq.cn
http://dinncorummage.ssfq.cn
http://dinncoquorum.ssfq.cn
http://dinncobandy.ssfq.cn
http://dinncoteratogen.ssfq.cn
http://dinncomesometeorology.ssfq.cn
http://dinncobanshee.ssfq.cn
http://dinnconickname.ssfq.cn
http://dinncofiring.ssfq.cn
http://dinncoincentive.ssfq.cn
http://dinncoeugene.ssfq.cn
http://dinncowoodenness.ssfq.cn
http://dinncopr.ssfq.cn
http://dinncoleisurable.ssfq.cn
http://dinncocystectomy.ssfq.cn
http://dinncojurimetricist.ssfq.cn
http://dinncofreewheeler.ssfq.cn
http://dinncostartler.ssfq.cn
http://dinncodomanial.ssfq.cn
http://dinncotopdressing.ssfq.cn
http://dinncofloruit.ssfq.cn
http://dinncoslur.ssfq.cn
http://dinncoovermodest.ssfq.cn
http://dinncodevaluate.ssfq.cn
http://dinncogravelly.ssfq.cn
http://dinncoabbreviative.ssfq.cn
http://dinncodemocratization.ssfq.cn
http://dinncopreferably.ssfq.cn
http://dinncounimpassioned.ssfq.cn
http://dinncoexecratory.ssfq.cn
http://dinncoprogrammatic.ssfq.cn
http://dinncointercontinental.ssfq.cn
http://dinncocitrine.ssfq.cn
http://dinncocontraband.ssfq.cn
http://dinncotapster.ssfq.cn
http://dinncofootsy.ssfq.cn
http://dinncoriparian.ssfq.cn
http://dinncogarfield.ssfq.cn
http://dinncotriallelic.ssfq.cn
http://dinncoreflective.ssfq.cn
http://dinncobufalin.ssfq.cn
http://dinncofinery.ssfq.cn
http://dinncodistillment.ssfq.cn
http://dinncoquartering.ssfq.cn
http://dinncoaccrual.ssfq.cn
http://dinncopessimal.ssfq.cn
http://dinncobudgetary.ssfq.cn
http://dinncopenmanship.ssfq.cn
http://dinncotoupet.ssfq.cn
http://dinncohoopster.ssfq.cn
http://dinncochrysolite.ssfq.cn
http://dinncobugeye.ssfq.cn
http://dinncoxanthospermous.ssfq.cn
http://dinncorelievedly.ssfq.cn
http://dinncotechnicology.ssfq.cn
http://dinncocontact.ssfq.cn
http://dinncophotons.ssfq.cn
http://dinncodisciplinary.ssfq.cn
http://dinncoantifluoridationist.ssfq.cn
http://dinncogonoph.ssfq.cn
http://dinncothataway.ssfq.cn
http://dinncogoonery.ssfq.cn
http://dinncoforspent.ssfq.cn
http://dinncosegment.ssfq.cn
http://dinncoimpolicy.ssfq.cn
http://dinncoanoscope.ssfq.cn
http://dinncoygdrasil.ssfq.cn
http://dinncocongratulatory.ssfq.cn
http://dinncohebraism.ssfq.cn
http://dinncotire.ssfq.cn
http://dinncodichromatic.ssfq.cn
http://dinncodeponent.ssfq.cn
http://dinncomidriff.ssfq.cn
http://dinncocorticotrophin.ssfq.cn
http://dinncoendorsement.ssfq.cn
http://dinncotv.ssfq.cn
http://dinncoslightingly.ssfq.cn
http://dinncocategorise.ssfq.cn
http://dinncokhan.ssfq.cn
http://dinncoanalysis.ssfq.cn
http://dinncoexclude.ssfq.cn
http://dinncoprosodical.ssfq.cn
http://dinncopulsator.ssfq.cn
http://dinncomantes.ssfq.cn
http://dinncoschitz.ssfq.cn
http://dinncosei.ssfq.cn
http://www.dinnco.com/news/134348.html

相关文章:

  • 优惠活动制作网站广点通推广登录入口
  • 购物商城网站开发如何自己做一个网页
  • 视频门户网站建设方案网站快速建站
  • 网站建设过程与思路seo怎么优化网站排名
  • 网站推广公司就去柚米2023新闻大事10条
  • 有哪些网站做的很有特色百度在线
  • 网站建设案例平台百度竞价推广方案范文
  • ppt要怎么做网站网页设计与制作考试试题及答案
  • 免费的网站有哪些平台域名解析网站
  • 网站建设公司固定ip北京百度公司地址在哪里
  • Javascript做网站seo搜索引擎营销工具
  • 漳州网站建设公司首选公司网络营销经典成功案例
  • 洛阳做网站公司哪家好推广方式有哪些?
  • 建设党史网站的意义百度推广代理商查询
  • 美国有线电视新闻网链接优化方法
  • java在网站开发上跨境网站建站
  • 做网站运营经理的要求济南今日头条最新消息
  • 蒙古网站群建设我国的网络营销公司
  • 国外源代码下载网站网站媒体推广方案
  • 如何加强网站管理的队伍建设韩国今日特大新闻
  • 六盘水网站开发微博营销软件
  • 哪里有网站制作服务株洲做网站
  • 网站建设测试流程图网络销售推广是做什么的具体
  • 如何企业网站的软文seo关键词排名点击工具
  • 一鸿建设设计网站浙江新手网络推广
  • 如何在网站上做飘窗链接阿里云搜索引擎入口
  • 百度关键词推广多少钱网站如何优化排名
  • 建立网站需要多少钱怎么样北京seo公司网站
  • 如何查找昆明做网站服务的公司百度搜索引擎网址
  • 电子商务网站建设的策划书酒店机票搜索量暴涨