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

代码随想录 打卡第五十三天

卡码网 110 字符串迁移

#include <iostream> #include <vector> #include <string> #include <unordered_set> #include <unordered_map> #include <queue> using namespace std; int main() { string beginStr, endStr, str; int n; cin >> n; unordered_set<string> strSet; cin >> beginStr >> endStr; for (int i = 0; i < n; i++) { cin >> str; strSet.insert(str); } unordered_map<string, int> visitMap; queue<string> que; que.push(beginStr); visitMap.insert(pair<string, int>(beginStr, 1)); while(!que.empty()) { string word = que.front(); que.pop(); int path = visitMap[word]; for (int i = 0; i < word.size(); i++) { string newWord = word; for (int j = 0 ; j < 26; j++) { newWord[i] = j + 'a'; if (newWord == endStr) { cout << path + 1 << endl; return 0; } if (strSet.find(newWord) != strSet.end() && visitMap.find(newWord) == visitMap.end()) { visitMap.insert(pair<string, int>(newWord, path + 1)); que.push(newWord); } } } } cout << 0 << endl; }

卡码网 105 有向图的完全联通

#include<iostream> #include<list> #include<vector> using namespace std; void dfs(vector<list<int>>& graph,vector<int>& visit,int index){ if(visit[index] == 1) return; visit[index] = 1; list<int> nodes = graph[index]; for(int nextnode:nodes){ dfs(graph,visit,nextnode); } return; } int main(){ int n,m,x,y; cin >> n >> m; vector<list<int>> graph(n+1); while(m--){ cin >> x >> y; graph[x].push_back(y); } vector<int> visit(n+1,0); dfs(graph,visit,1); for(int i = 1;i < n+1;i++){ if(visit[i] == 0) { cout << -1; return 0; } } cout << 1; return 0; }

卡码网 106 海岸线计算

#include<iostream> #include<vector> using namespace std; int inorder[4][2] = {0,1, 1,0, 0,-1, -1,0}; int main(){ int n,m; cin >> n >> m; vector<vector<int>> graph(n,vector<int>(m,0)); for(int i = 0;i < n;i++){ for(int j = 0;j < m;j++){ cin >> graph[i][j]; } } int len = 0; for(int i = 0;i < n;i++){ for(int j = 0;j < m;j++){ if(graph[i][j] == 0) continue; for(int k = 0;k < 4;k++){ int next_x = i + inorder[k][0]; int next_y = j + inorder[k][1]; if(next_x < graph.size() && next_x >= 0 && next_y < graph[0].size() && next_y >= 0){ if(graph[next_x][next_y] == 0) len++; }else{ len++; } } } } cout << len; return 0; }
http://www.jsqmd.com/news/992980/

相关文章:

  • P8xC654X2增强型80C51:低功耗与高性能的经典平衡之道
  • 2026邯郸全城高金价回收黄金回收店铺盘点 TOP 铂金白银旧料回收正规门店联系方式全收录 - 中业金奢再生回收中心
  • 深入解析P89CV51 UART、SPI与PCA模块:从寄存器配置到实战避坑
  • Hi9100降压DC-DC控制器:150V超宽输入,外置MOS驱动,恒压恒流可配置10A输出
  • 如何用5分钟将单张图片自动转换为专业PSD分层文件?
  • 2026晋城本地人常去黄金回收门店前五整理 黄金回收百业回收铂金回收靠谱实体店联系方式汇总 - 中安检金银铂钻回收
  • 终极免费英雄联盟回放管理工具:ReplayBook完整使用指南
  • 2026年语音识别模块行业:三大核心趋势解读 - 资讯快报
  • 2026安徽贵金属回收黄金回收白银回收铂金回收店铺怎么挑?5 家不压价线下实体店完整测评清单 + 商家联络方式 - 信誉隆金银铂奢回收
  • 洛雪音乐助手:你的全平台音乐聚合神器,告别繁琐切换!
  • 微信小程序WIFI API实战全解析:从权限配置到列表获取的完整避坑指南
  • Cadence Virtuoso仿真不收敛?别慌,这份Verilog-A模型调试避坑指南帮你搞定
  • 嵌入式网络处理器端口复用架构解析与MSC8103 CPM配置实战
  • IP-guard部署与兼容性实战解析
  • 从踩坑到填坑:我的Worldclim CIMP6数据预处理避雷指南与经验分享
  • 5个技巧让你的IntelliJ IDEA Markdown插件开发效率翻倍
  • 2026年赣州市PMP培训机构哪家好?官方授权R.E.P.报考指南 - 众智商学院课程中心
  • 高考志愿必读|2026年最新数据:327万人才缺口,这个专业的应届生平均月入过万,毕业生被企业抢着要
  • NTAG21x NFC标签安全机制深度解析:密码保护与数字签名实战指南
  • 金华运动内衣厂家技术拆解 采购选型与供应链全指南 - 奔跑123
  • 黄石高口碑黄金铂金回收白银回收实体老店排行 5 家靠谱门店电话地址全收录 - 诚金汇钻回收公司
  • 3个让Windows拥有苹果级字体体验的秘密
  • RTL8821CE无线网卡在UOS/Deepin系统上的即用型Linux驱动包(含编译安装与DKMS部署)
  • 别再死记硬背了!用Python+NetworkX快速判断欧拉图和哈密顿图(附期末真题解析)
  • 江西宜春周边游景区推荐:天柱峰景区毕业狂欢三重喜 - 奔跑123
  • 2026 年 6 月最新 | 宁波厂房通风降温厂家 承接工业厂房通风降温工程 设备生产安装一站式服务 - 商业新知
  • 2026 广州黄金奢侈品回收店 TOP5 推荐:耀辉行业标杆,教你避开行业套路 - 奢侈品回收
  • 如何高效使用抖音去水印下载工具:TikTokDownload新手快速入门指南
  • 告别臃肿!G-Helper:拯救华硕笔记本性能的终极轻量解决方案
  • 2026中号自封袋批发厂家推荐:综合实力测评,优质供应商选型指南 - 资讯快报