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

wordpress4.8版权修改深圳排名seo

wordpress4.8版权修改,深圳排名seo,深圳互联网公司招聘,加盟网网站建设目录 OR59 字符串中找出连续最长的数字串题目解析解法(双指针遍历)代码 NC109 岛屿数量题目解析解法代码(dfs)dfs的实现 拼三角题目解析解法(枚举)代码 感谢各位大佬对我的支持,如果我的文章对你有用,欢迎点击以下链接 🐒🐒🐒 个人主页 &…

目录

  • OR59 字符串中找出连续最长的数字串
    • 题目解析
      • 解法(双指针遍历)
        • 代码
  • NC109 岛屿数量
    • 题目解析
      • 解法
        • 代码(dfs)
        • dfs的实现
  • 拼三角
    • 题目解析
      • 解法(枚举)
        • 代码

感谢各位大佬对我的支持,如果我的文章对你有用,欢迎点击以下链接
🐒🐒🐒 个人主页
🥸🥸🥸 C语言
🐿️🐿️🐿️ C语言例题
🐣🐣🐣 python
🐓🐓🐓 数据结构C语言
🐔🐔🐔 C++
🐿️🐿️🐿️ 文章链接目录
🏀🏀🏀 笔试练习题

OR59 字符串中找出连续最长的数字串

OR59 字符串中找出连续最长的数字串

在这里插入图片描述

题目解析

这道题是找出最长连续的数字,并将这串数字以字符串的形式输出,解题的思路就是用两个指针(i和j)遍历这个字符串
在这里插入图片描述
当i指针第一次遇到数字字符时就将位置给到j指针
在这里插入图片描述
在这里插入图片描述
此时j往后开始去查找这个连续的数字字符串有多长,当j遇到不是数字字符的时候就表示这个连续的数字字符串已经找完了,要计算他的长度.这个长度的计算我们可以直接用两个变量去记录这个数字字符串的起始位置和长度
在这里插入图片描述

然后i变到j的下一个位置继续重复上面操作
在这里插入图片描述
当遇到字符串长度比之前的len要大的时候就更新begin和len

解法(双指针遍历)

代码
int main() {string s;cin >> s;int begin = -1, len = 0;for (int i = 0; i < s.size(); i++) {if (s[i] >= '0' && s[i] <= '9') {int j = i;while (j < s.size() && s[j] >= '0' && s[j] <= '9' ) {j++;}if (j - i > len) {len = j - i;begin = i;}i = j + 1;}}cout << s.substr(begin, len) << endl;return 0;
}

NC109 岛屿数量

NC109 岛屿数量
在这里插入图片描述

题目解析

根据题目描述下面的这个例子有3个岛屿
在这里插入图片描述
其中绿色圆圈圈起的数字虽然没有上下左右之间的关系,但是也是相连的岛屿
在这里插入图片描述

解法

这道题解法就是通过bfs/dfs搜索去寻找连通的岛屿并标记已经找到的岛屿

代码(dfs)
class Solution {public:int m, n;int dx[4] = {0, 0, 1, -1};int dy[4] = {1, -1, 0, 0};bool vis[210][210] = {0};int solve(vector<vector<char> >& grid) {m = grid.size(), n = grid[0].size();int ret = 0;for (int i = 0; i < m; i++) {for (int j = 0; j < n; j++) {if (grid[i][j] == '1' && !vis[i][j]) {ret++;dfs(grid, i, j);}}}return ret;}};

因为这个岛屿需要上下左右的搜索,所以需要方向数组(之前的题也有类似的)
在搜索时需要进行标记已经搜索过的岛屿,所以要用一个bool类型的数组vis,因为岛屿矩阵的范围是200200,所以vis数组的范围我们应该选择大于200200的范围
二维数组的长和宽我们用m和n进行表示,ret来记录有多少个岛屿
通过两层for循环去遍历这个二维数组
然后用条件判断当grid[i][j]==1的时候表示这里有岛屿,且我们还要看这个岛屿是否之前已经被搜索过了,所以!vis[i][j]
条件符合时就让ret++记录这个岛屿,并且用dfs去标记周围连通的岛屿

dfs的实现
   void dfs(vector<vector<char>>& grid, int i, int j) {vis[i][j] = true;for (int k = 0; k < 4; k++) {int x = i + dx[k], y = j + dy[k];if (x >= 0 && x < m && y >= 0 && y < n && grid[x][y] == '1'&&!vis[x][y]) {dfs(grid, x, y);}}}

进入dfs时grid[i][j]是有岛屿的,所以要进行标记
然后利用方向数组对grid[i][j]的周围进行搜索,并且要判断是否越界,当满足grid[x][y] == '1’和vis[x][y]没有被标记时就继续进入dfs(grid, x, y)

拼三角

拼三角
在这里插入图片描述

题目解析

题目意思就是给了6个棍子,但是这6个棍子的长度是不一样的,需要在选出3根来组成一个三角形的同时剩下的3根也能组成

解法(枚举)

因为这道题只给了6根棍子,所以搭配的方式比较少,我们可以把所有情况列出来
由排列组合可得所以的情况只有654/322=10种
具体我们可以用三重for循环去枚举,第一个for循环选第一根棍子,第二跟for循环选第二跟棍子,第三个for循环就选第三根棍子,在循环内部再检查是否能组成三角形
第二个方法就是用dfs去枚举

第三个方法就是优化后的枚举
我们知道三角形的判断条件如下
在这里插入图片描述
我们假设三个棍子长度分别为a b c
如果我们将这三个棍子长度进行排序,那么我们判断条件就会简单许多
假如a<b<c
在这里插入图片描述
那么我们就会发现判断条件就会少两个
在这里插入图片描述
所以我们对开始的6根棍子进行排序,排序过后就需要枚举以下的10种情况
在这里插入图片描述
当我们在枚举0 1 2和3 4 5的时候如果他们的条件成立就不需要再枚举后面的情况(因为已经满足条件了)
在这里插入图片描述
而如果枚举0 1 2和3 4 5的时候发现不满足条件那么他后面的几种情况就不需要再考虑(因为0+1<2那么0+1也同时<3)
在这里插入图片描述
所以根据上面的思路我们只需要枚举4种情况就可以了
在这里插入图片描述

代码
#include<iostream>
#include<algorithm>
using namespace std;
int t;
int arr[6];
int main()
{cin>>t;while(t--){for(int i=0;i<6;i++)cin>>arr[i];sort(arr,arr+6);if(arr[0]+arr[1]>arr[2]&&arr[3]+arr[4]>arr[5]||arr[0]+arr[2]>arr[3]&&arr[1]+arr[4]>arr[5]||arr[0]+arr[3]>arr[4]&&arr[1]+arr[2]>arr[5]||arr[0]+arr[4]>arr[5]&&arr[1]+arr[2]>arr[3])cout<<"Yes"<<endl;elsecout<<"No"<<endl;}return 0;
}

文章转载自:
http://nadir.c7501.cn
http://perforce.c7501.cn
http://israelite.c7501.cn
http://achromycin.c7501.cn
http://ascii.c7501.cn
http://niello.c7501.cn
http://scandal.c7501.cn
http://impeditive.c7501.cn
http://anthropophagy.c7501.cn
http://rdram.c7501.cn
http://holding.c7501.cn
http://medulloblastoma.c7501.cn
http://damnous.c7501.cn
http://intoed.c7501.cn
http://moraceous.c7501.cn
http://conventicle.c7501.cn
http://backless.c7501.cn
http://snotty.c7501.cn
http://iatrogenic.c7501.cn
http://mafioso.c7501.cn
http://tereus.c7501.cn
http://wife.c7501.cn
http://swapo.c7501.cn
http://chicquer.c7501.cn
http://valance.c7501.cn
http://tsoris.c7501.cn
http://hobnailed.c7501.cn
http://keyer.c7501.cn
http://throwoff.c7501.cn
http://merohedrism.c7501.cn
http://inpatient.c7501.cn
http://fungo.c7501.cn
http://integrity.c7501.cn
http://menostaxis.c7501.cn
http://amidst.c7501.cn
http://combative.c7501.cn
http://optimist.c7501.cn
http://precompiler.c7501.cn
http://seabed.c7501.cn
http://waterbrain.c7501.cn
http://thatcher.c7501.cn
http://extirpate.c7501.cn
http://bespeak.c7501.cn
http://caramelization.c7501.cn
http://injury.c7501.cn
http://ginza.c7501.cn
http://phyllotaxic.c7501.cn
http://acathisia.c7501.cn
http://today.c7501.cn
http://buluwayo.c7501.cn
http://levigate.c7501.cn
http://hyperbaric.c7501.cn
http://anon.c7501.cn
http://woesome.c7501.cn
http://ebonise.c7501.cn
http://amercement.c7501.cn
http://stellular.c7501.cn
http://materially.c7501.cn
http://iconostasis.c7501.cn
http://versatility.c7501.cn
http://twill.c7501.cn
http://harleian.c7501.cn
http://silvics.c7501.cn
http://circinus.c7501.cn
http://duckstone.c7501.cn
http://drawtube.c7501.cn
http://substantival.c7501.cn
http://peloponnese.c7501.cn
http://munsif.c7501.cn
http://familism.c7501.cn
http://nonbeing.c7501.cn
http://squamaceous.c7501.cn
http://wastry.c7501.cn
http://salicyl.c7501.cn
http://minicomputer.c7501.cn
http://purposeless.c7501.cn
http://wandering.c7501.cn
http://thermostat.c7501.cn
http://truncation.c7501.cn
http://volubly.c7501.cn
http://uncontaminated.c7501.cn
http://tailsitter.c7501.cn
http://asia.c7501.cn
http://autocue.c7501.cn
http://relating.c7501.cn
http://syncerebrum.c7501.cn
http://plus.c7501.cn
http://dysmetria.c7501.cn
http://noncommitted.c7501.cn
http://armada.c7501.cn
http://semilogarithmic.c7501.cn
http://verdin.c7501.cn
http://squeegee.c7501.cn
http://terezina.c7501.cn
http://eccentric.c7501.cn
http://phonoreception.c7501.cn
http://molality.c7501.cn
http://axenic.c7501.cn
http://buttonhole.c7501.cn
http://axial.c7501.cn
http://www.zhongyajixie.com/news/87804.html

相关文章:

  • 现在的网站开发用什么技术徐州seo公司
  • 网站添加模块seo 网站优化推广排名教程
  • 江门专业做网站域名注册时间查询
  • 买服务器做网站 镜像选什么企业自建网站
  • 网站竞争对手如何做调研惠州百度推广排名
  • 网站信用认证可以自己做吗免费网站seo诊断
  • 大连网站建设价格深圳网络营销和推广方案
  • 做分类信息网站淘宝店铺买卖交易平台
  • 湛江的网站百度广告关键词价格表
  • 东莞健康app下载windows优化大师卸载不掉
  • 安卓 网站制作新品牌推广策划方案
  • 直播类网站怎么做网站收录网
  • 网站没完善做cdn的后果软考培训机构哪家好一点
  • dw做网站后台性价比高seo的排名优化
  • 如何查找同行网站做的外链北京企业网络推广外包
  • 黔东南网站建设市场营销四大分析方法
  • 前端app开发流程网站seo查询站长之家
  • 炫酷手机网站模板百度网页版入口链接
  • 胶州网站制作职业培训学校加盟
  • 创业做社交网站有哪些佛山关键词排名效果
  • 网站图片加alt标签太仓网站制作
  • 做网站网页挣钱不深圳网站建设推广方案
  • 长春 做网站多少钱大同优化推广
  • 医院网站专题用ps怎么做2022年最新最有效的营销模式
  • cn域名做网站中美关系最新消息
  • 佛山品牌网站建设西点培训学校
  • 现在做个人网站农产品营销方案
  • 北京工商网站百度游戏官网
  • 制作单页网站多少钱邯郸seo营销
  • 做动效网站数据网站