题目链接:点这里.

这套题很有问题,数据有问题,第一题只有83%83\%的数据是对的,第三题只有14%14\%的数据是对的,只能说出题人有点随意,第三题居然能出现n=−1n=-1的这种情况,其实第三题应该保证所有单词的长度小于等于nn,不然这题是没法做的.

还是写下解题报告,我们忽略数据的问题,给出正确的解法.

第一题:AutoPilot02

题目:

给你一个矩阵,让你打印(0,0)(0,0)到(n−1,n−1)(n -1, n-1)的最短路径,最普通的bfsbfs,第二题就是在第一题的基础上改了下,输出最短路径的长度就好了,没什么技巧,我都是用STLSTL写的,所以代码比较简洁.

代码:

#include <bits/stdc++.h>using namespace std;const int dirx[] = {0, 1, 0, -1};
const int diry[] = {1, 0, -1, 0};struct Node {int id;int pre;Node() {}Node(int id, int pre = -1) : id(id), pre(pre) {}
};bool judge(int x, int y, int n)
{return x >= 0 && x < n && y >= 0 && y < n;
}int main()
{vector<int> mp;int x, n;while (cin >> x) {mp.push_back(x);}n = (int)sqrt(1.0 * mp.size());deque<Node> que;vector<bool> used(mp.size(), false);que.emplace_back(0);used[0] = true;decltype(que.size()) head = 0;int src = -2;while (!que.empty()) {if (que.cbegin() + head == que.cend())break;Node now = que[head++];if (now.id / n == n - 1 && now.id % n == n - 1) {src = head - 1;break;}for (int i = 0; i < 4; i++)if (judge(now.id / n + dirx[i], now.id % n + diry[i], n) &&mp[(now.id / n + dirx[i]) * n + now.id % n + diry[i]] == 0 &&!used[(now.id / n + dirx[i]) * n + now.id % n + diry[i]])que.emplace_back((now.id / n + dirx[i]) * n + now.id % n + diry[i], head - 1),used[(now.id / n + dirx[i]) * n + now.id % n + diry[i]] = true;}if (src == -2) {cout << "nopath" << endl;return 0;}stack<int> ans;while (que[src].pre != -1)ans.push(src), src = que[src].pre;ans.push(0);while (!ans.empty())cout << que[ans.top()].id / n << "," << que[ans.top()].id % n << endl, ans.pop();return 0;
}

第二题:AutoPilot01

题目:

看第一题…..

解析:

看第一题…..

代码:

#include <bits/stdc++.h>using namespace std;const int dirx[] = {0, 1, 0, -1};
const int diry[] = {1, 0, -1, 0};struct Node {int id;int step;Node() {}Node(int id, int step = 0) : id(id), step(step) {}
};bool judge(int x, int y, int n)
{return x >= 0 && x < n && y >= 0 && y < n;
}int main()
{vector<int> mp;int x, n;while (cin >> x) {mp.push_back(x);}n = (int)sqrt(1.0 * mp.size());deque<Node> que;vector<bool> used(mp.size(), false);que.emplace_back(0);used[0] = true;decltype(que.size()) head = 0;int ans = -1;while (!que.empty()) {if (que.cbegin() + head == que.cend())break;Node now = que[head++];if (now.id / n == n - 1 && now.id % n == n - 1) {ans = now.step;break;}for (int i = 0; i < 4; i++)if (judge(now.id / n + dirx[i], now.id % n + diry[i], n) &&mp[(now.id / n + dirx[i]) * n + now.id % n + diry[i]] == 0 &&!used[(now.id / n + dirx[i]) * n + now.id % n + diry[i]])que.emplace_back((now.id / n + dirx[i]) * n + now.id % n + diry[i], now.step + 1),used[(now.id / n + dirx[i]) * n + now.id % n + diry[i]] = true;}cout << ans << endl;return 0;
}

第三题:Text Justification

题目:

模拟两端对齐,每行最多L<script type="math/tex" id="MathJax-Element-433">L</script>个字符,除了单词,剩下的就是空格,空格要均匀,多余的空格往左边加.

解析:

直接模拟,巨水.

代码:

#include <bits/stdc++.h>using namespace std;int main()
{vector<string> words;string str;int maxSize = 0;while (cin >> str) {words.push_back(str);maxSize = max(maxSize, (int)str.size());}int n;stringstream sin;sin << words[words.size() - 1];sin >> n;words.pop_back();if (maxSize > n) {cout << words[0];for (decltype(words.size()) i = 1; i < words.size(); i++)cout << " " << words[i];cout << endl;return 0;}int sumNum = 0, sumLen = 0;vector<string> ans;for (decltype(words.size()) i = 0; i < words.size(); i++) {if (sumLen + words[i].size() + sumNum <= n)sumLen += words[i].size(), sumNum++, ans.push_back(words[i]);else {if (sumNum == 1) {cout << ans[0];for (int i = 0; i < n - ans[0].size(); i++)cout << " ";cout << endl;ans.clear();sumNum = sumLen = 0;--i;continue;}int space = (n - sumLen) / (sumNum - 1);int rest = (n - sumLen) % (sumNum - 1);cout << ans[0];for (decltype(ans.size()) j = 1; j < ans.size(); j++) {int top = space + (rest-- > 0 ? 1 : 0);for (int i = 0; i < top; i++)cout << " ";cout << ans[j];}cout << endl;ans.clear();sumNum = sumLen = 0;--i;}}if (ans.size() != 0) {if (sumNum == 1) {cout << ans[0];for (int i = 0; i < n - ans[0].size(); i++)cout << " ";cout << endl;return 0;}int space = (n - sumLen) / (sumNum - 1);int rest = (n - sumLen) % (sumNum - 1);cout << ans[0];for (decltype(ans.size()) j = 1; j < ans.size(); j++) {int top = space + (rest-- > 0 ? 1 : 0);for (int i = 0; i < top; i++)cout << " ";cout << ans[j];}cout << endl;}return 0;
}

去哪儿2017校园招聘 开发工程师(第二批次)- 题解相关推荐

  1. 去哪儿2017校园招聘 开发工程师(第一批次)- 题解

    题目链接:点这里. 这套题目有点味道啊,不算难,但是考验编码技巧,尤其是最后一题,我也是醉了,看人家用Python的,直接调用库函数,几行代码就搞定了,看来Python大法还是牛啊,C++写了好长的代 ...

  2. 深信服2018校园招聘C++工程师编程题 - 题解

    深信服2017的校园招聘的题目和这次的几乎一样,不知道贵公司是什么样的想法.做过2017的题目的同学应该会比较占优势.题目不难,比较考验编程的技巧与准确度. 第一题:堆排序 题目: 函数heap_so ...

  3. 哔哩哔哩 2019校园招聘 开发工程师-2018.09.21

    思路: 从后往前思考,偶数用扭蛋机3号,奇数用扭蛋机2号,每次更改n的值,统计路径 代码: #include <bits/stdc++.h>using namespace std; int ...

  4. 去哪儿2017校园招聘笔试题

    import java.util.Scanner;/*** filename extension* 时间限制:C/C++语言 1000MS:其他语言 3000MS* 内存限制:C/C++语言 6553 ...

  5. 去哪儿2017校园招聘笔试题——获得文件扩展名filename extension

    1. 题目 Please create a function to extract the filename extension from the given path,return the extr ...

  6. 去哪儿2017校园招聘笔试题——统计字符串中最先出现三次的字符

    1. 题目 统计字符 给定一个英文字符串,请写一段代码找出这个字符串中首先出现三次的那个英文字符. 输入 qywyery23tdd 输出 y 2. 分析 和所有统计英文字符一样,依次利用Hash算法将 ...

  7. 百世集团2016校园招聘开发工程师笔试试卷

    1.从按下pc的电源键开始,到屏幕上出现windows的欢迎界面为止,请尝试从计算机软硬件的角度来描述一下这期间分别发生了什么事情? 启动bios检测硬件,正常以后读取硬盘系统盘,启动操作系统,看到页 ...

  8. 阿里 c语言开发工程师,阿里巴巴2014秋季校园招聘软件研发工程师笔试题

    阿里巴巴2014秋季校园招聘软件研发工程师笔试题 1. 单选题 1. 假设把整数关键码K散列到N个槽列表,以下哪些散列函数是好的散列函数 A: h(K)=K/N; B: h(K)=1; C: h(K) ...

  9. 【算法】创新工场涂鸦移动2017校园招聘测试题-A卷-软件工程师

    今天做了创新工场涂鸦移动2017校园招聘测试题-A卷-软件工程师的题目,我也不知道这算不算是泄题,再说也不见得我写的算法就是对的.贴出来,希望大家相互学习,相互进步,如有违反XX,不胜荣幸. 链表 1 ...

最新文章

  1. 硬件基础:电阻作用及产品应用
  2. js弹出一段html,html js 弹出层
  3. golang strings包部分函数使用
  4. 剑桥MPhil Industrial Systems, Manufacture and Management录取率
  5. HDU 1175 连连看 dfs+剪枝
  6. Linux ss命令 报错,ECS Linux中ss命令显示连接状态的使用说明
  7. windows10 安装mqtt服务器和client客户端进行本地调试
  8. 你还记得windows workflow foundation吗
  9. 滴滴全链路压测解决之道 | 技术头条
  10. HTML5 本地存储(Web Storage)
  11. rust如何进枪战服_rust手机版
  12. EduSoHo在线教育商业版源码
  13. 西门子em235模块的功能_图文讲解PLC模拟量模块与传感器接线方法和注意事项
  14. 【优化电价】基于matlab内点法求解实时电价最优问题【含Matlab源码 1161期】
  15. java oracle 中文列_java oracle中文乱码怎么办
  16. web前后端分离系统之间的单点登录
  17. 计算机基础证和PS证,全国计算机等级PHOTOSHOP一级证书
  18. 各种水龙头拆卸图解_各种水龙头拆卸图解 蜜罐蚁小编带您了解水龙头拆卸方法...
  19. W3C 标准 较详细
  20. 宁银消费金融来了 母行授信80亿,全国急招人

热门文章

  1. 高性能的gpu服务器,高性能GPU云服务器
  2. 【阅读笔记】后真相时代的竞争性真相
  3. 物联网毕设选题 机器视觉人脸识别系统 - 单片机 stm32 嵌入式
  4. C# Winform 仿Win10-计算器
  5. Pycharm常用快捷键【快查字典版】
  6. 山东女子学院数据科学与计算机学院官网,数据科学与计算机学院举办2006级校友返校活动...
  7. 数字通信第三章——多维信号传输
  8. P4745 B’s problem(b)
  9. STL之容器Vector内存管理
  10. 【macOS】U盘格式化(命令行)