笔试

150min,3题,每题100分,自己果然还是个蒟蒻呢~

最近状态好差,虽然做了一些题,但还是考得稀烂,大概有几点需要加强:

  • 独立做题,不要一边看板子一边写代码,更不要一开始就看题解;
  • 对之前研究过的一些专项模板,要非常熟练敲出来;
  • “题海”战术要继续,薄弱算法要专项练习:即使内推,也免不了笔试,保持手感很重要。

先补下题:

No. 1



Pass 90%

开始觉得BFS可以做,但不知道怎么写,于是转去从(x-l,y-l)遍历到(x+l,y+l),写了一下发现l会变,下一轮循环遍历范围可能增大,不知道怎么写下去,又转去DFS,因为DFS每一次递归都可以自动更改l的值,不知道为毛没有AC。

其实只要每一次都搜索整个图,去吃满足条件的补给品,直到剑的长度不变

我TM竟然没想到用长度作为终止条件,而且暴力时候太谨慎,不敢把整个图过一遍(只有500*500的数据范围啊,蠢哭了),自己给自己增加难度~

#include <iostream>
#include <vector>
#include <cmath>
using namespace std; double dist(int x1, int y1, int x2, int y2) {
return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
} int main(void)
{
int t;
cin >> t;
while (t--) {
int m, l;
cin >> m >> l;
vector<vector<int>> g(m, vector<int>(m));
for (int i = 0; i < m; ++i) {
for (int j = 0; j < m; ++j) {
cin >> g[i][j];
}
} int x, y;
cin >> x >> y;
int ans = -1;
while (l != ans) {
ans = l;
for (int i = 0; i < m; ++i) {
for (int j = 0; j < m; ++j) {
if (g[i][j] > 0 && dist(x, y, i, j) <= l) {
l += g[i][j];
g[i][j] = -1;
}
}
}
}
cout << ans << endl;
}
return 0;
}

No. 2



Pass 10%

并查集都能写挂,真无语了。。。唉,菜是原罪

后来发现是自己模板有问题,结果一直T:大多数情况下T的原因不在于输入输出,而在于算法,血的教训。。。

回头看以为是个裸题,但是涉及到并查集的删除操作,索性直接用vector<int>存每个元素到其集合的映射关系,这样看来更是简单(一看到题就陷入树结构的并查集。。。):

做题要看数据范围!!!\(10^7\)普通并查集\(O(n)\)可以过!!!而且题目很明显涉及到删除求集合中元素个数的操作,在树结构的并查集中实现复杂!!!

#include <iostream>
#include <vector>
using namespace std; class UF {
public:
UF(int n) {
for (int i = 0; i <= n; ++i) {
setNum.emplace_back(i);
}
} void unio(int x, int y) {
if (setNum[x] != setNum[y]) {
for (int i = 1; i < setNum.size(); ++i) {
if (setNum[i] == setNum[y]) {
setNum[i] = setNum[x];
}
}
}
} void getOut(int x) {
if (size(x) != 1) {
setNum[x] = -1;
}
} int size(int x) {
int cnt = 0;
for (int i = 1; i < setNum.size(); ++i) {
if (setNum[x] == setNum[i]) {
++cnt;
}
}
return cnt;
} private:
vector<int> setNum;
}; int main(void)
{
int t;
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
UF uf(n);
for (int i = 0; i < m; ++i) {
int op, x, y;
cin >> op;
if (op == 1) {
cin >> x >> y;
uf.unio(x, y);
}
else if (op == 2) {
cin >> x;
uf.getOut(x);
}
else {
cin >> x;
cout << uf.size(x) << endl;
}
}
}
return 0;
}

No. 3



开始就知道暴力过不了,想着骗点分算了,枚举A的所有错排\(\{B_1,B_2...\}\),计算A与B的最小距离即可,不知道为什么WA,结果爆零。。。

贴下暴力代码:

#include <iostream>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <limits> // INT_MAX
using namespace std; int main(void)
{
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> a(n); unordered_map<int, int> w(n); for (int i = 0; i < n; ++i) {
cin >> a[i];
}
vector<int> b(a);
for (int i = 0; i < n; ++i) {
cin >> w[a[i]];
}
int ans = INT_MAX; sort(a.begin(), a.end());
do {
bool flag = true;
for (int i = 0; i < n; ++i) {
if (a[i] == b[i]) {
flag = false;
break;
}
}
if (flag) {
int cur = 0;
for (int i = 0; i < n; ++i) {
int tmp = find(a.begin(), a.end(), b[i]) - a.begin() - i;
cur += w[b[i]] * abs(tmp);
}
ans = min(ans, cur);
}
} while (next_permutation(a.begin(), a.end())); cout << ans << endl;
} return 0;
}

比较正派的做法我有想到一点,不过当时第2题没过,心情有点烦躁,净想着骗分去了~

要使dist最小,就要求错排的每个位置移动尽可能少,使得pos之差尽可能小。

如果n是偶数,相邻位置两两互换,pos之差为1;

如果n是奇数,会多一个奇数位置的坑(有点贪心的意思),这样必然要有一个奇数位置的数移动2次,当然选择权值最小的那个数:

#include <iostream>
#include <vector>
using namespace std; int main(void)
{
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> a(n);
vector<int> w(n); for (int i = 0; i < n; ++i) {
cin >> a[i];
}
int sum = 0;
for (int i = 0; i < n; ++i) {
cin >> w[i];
sum += w[i];
}
if (n & 1) {
int minIdx = 0;
for (int i = 0; i < n; i += 2) {
if (w[i] < w[minIdx]) {
minIdx = i;
}
}
sum += w[minIdx];
} cout << sum << endl;
} return 0;
}

面试

收到面试通知很意外,唯一一个机会,还是面的完爆了呢。

这几天一直在看面经,说实话不难,而且很多人都没手撕代码,就有了侥幸心理。。只看了面经的代码,easy的题目都没有做出来。

第一次真正面试中写代码,紧张情绪下与平时状态完全不一样,第一次理解错题意,也没有确认就开始写,写完后才发现搞错了。。。

不知道是面试官表达能力有问题,还是我理解能力有问题,从一开始的基础知识、到后来的智力题、再到编程题,五次三番误解他的意思,总之聊的很不愉快!!!面试有时候也看运气吧~

简单做个总结吧:

  • 回答问题、手撕代码前一定要问清楚!!!!确认函数签名等细节,还可以先描述下自己的思路;
  • 只看面经不行,复习范围很局限,还是要系统学习、疯狂练习,平时有100%状态,面试才可能有70%状态;
  • 多参加面试,锻炼下高压下的思路和码力,任何时候都要冷静分析。

很难过了,后面应该还会再投一些公司吧。

INTERVIEW #5的更多相关文章

  1. Pramp mock interview (4th practice): Matrix Spiral Print

    March 16, 2016 Problem statement:Given a 2D array (matrix) named M, print all items of M in a spiral ...

  2. WCF学习系列二---【WCF Interview Questions – Part 2 翻译系列】

    http://www.topwcftutorials.net/2012/09/wcf-faqs-part2.html WCF Interview Questions – Part 2 This WCF ...

  3. WCF学习系列一【WCF Interview Questions-Part 1 翻译系列】

    http://www.topwcftutorials.net/2012/08/wcf-faqs-part1.html WCF Interview Questions – Part 1 This WCF ...

  4. Amazon Interview | Set 27

    Amazon Interview | Set 27 Hi, I was recently interviewed for SDE1 position for Amazon and got select ...

  5. Java Swing interview

    http://www.careerride.com/Swing-AWT-Interview-Questions.aspx   Swing interview questions and answers ...

  6. Pramp - mock interview experience

    Pramp - mock interview experience   February 23, 2016 Read the article today from hackerRank blog on ...

  7. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  8. [译]Node.js Interview Questions and Answers (2017 Edition)

    原文 Node.js Interview Questions for 2017 什么是error-first callback? 如何避免无止境的callback? 什么是Promises? 用什么工 ...

  9. WCF学习系列三--【WCF Interview Questions – Part 3 翻译系列】

    http://www.topwcftutorials.net/2012/10/wcf-faqs-part3.html WCF Interview Questions – Part 3 This WCF ...

  10. WCF学习系列四--【WCF Interview Questions – Part 4 翻译系列】

    WCF Interview Questions – Part 4   This WCF service tutorial is part-4 in series of WCF Interview Qu ...

随机推荐

  1. springboot actuator 配置安全

    springboot actuator监控是什么?类似php的phpinfor()函数,不过actuator更强大,可以查看的数据.状态更多.Actuator是Spring Boot提供的对应用系统的 ...

  2. java web数据库的增删改查详细

    本次课上实验是完成数据库的增删改查. 包括增加用户信息.删除用户信息.多条件查找用户信息.修改用户信息(主要是复选框单选框等的相关操作.) 下面下看一下各个界面的样子. 总页面:显示全部页面:增加页面 ...

  3. Android 6.0及以上版本如何实现从图库中选取图片和拍照功能

    XML 代码: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:andr ...

  4. Linux bash篇(三 数据流重定向)

    1>        以覆盖的方式将正确的数据输出到文件或设备上 1>>        以追加的方式将正确的数据输出到文件或设备上 2>        以覆盖的方式将错误的数据输 ...

  5. 7.5 this关键字的使用;标准学生类的编写 、构造方法的格式

    /** 学生类** 起名字我们要求做到见名知意.* 而我们现在的代码中的n和a就没有做到见名知意,所以我要改进.** 如果有局部变量名和成员变量名相同,在局部使用的时候,采用的是就近的原则. * 我们 ...

  6. P1352 没有上司的舞会&&树形DP入门

    https://www.luogu.com.cn/problem/P1352 题目描述 某大学有N个职员,编号为1~N.他们之间有从属关系,也就是说他们的关系就像一棵以校长为根的树,父结点就是子结点的 ...

  7. Linux c++ vim环境搭建系列(5)——vim使用

    5. 使用 5.1 快捷键及设置 5.1.1 光标移动 w : 正向移动到相邻单词的首字符 b : 逆向移动到相邻单词的首字符 e : 正向移动到相邻单词的尾字符 ge : 逆向移动到相邻单词的尾字符 ...

  8. hibernate.current_session_context_class 比较权威的解释

    hibernate.current_session_context_class 博客分类: hibernate HibernateSpring多线程配置管理thread  遇到过的问题: 情景1: 在 ...

  9. AJ学IOS 之UIDynamic重力、弹性碰撞吸附等现象

    AJ分享,必须精品 一:效果 重力和碰撞 吸附现象 二:简介 什么是UIDynamic UIDynamic是从iOS 7开始引入的一种新技术,隶属于UIKit框架 可以认为是一种物理引擎,能模拟和仿真 ...

  10. SpeedButton

    SpeedButton是一个图形控件,本身没有句柄.因此它不能具有焦点.你可以使用TBitBtn,调整一些属性,可以使他们的外形很接近. 只有从TWinControl派生的控件,才具有Handle.你 ...