笔试

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. python部署-Flask+uwsgi+Nginx

    一.Flask部分(app.py) flask即Python代码:部分参考代码如下,相信很多人如果看到这篇文章一定有flask的代码能力. from app import create_app fro ...

  2. Linux网络安全篇,进入SELinux的世界(四)

    SELinux的策略与规则管理set 1.安装SELInux工具 yum install setools-console 2.基本的命令 seinfo [-Atrub] -A ===> 列出SE ...

  3. 从JDK源码学习HashSet和HashTable

    HashSet Java中的集合(Collection)有三类,一类是List,一类是Queue,再有一类就是Set. 前两个集合内的元素是有序的,元素可以重复:最后一个集合内的元素无序,但元素不可重 ...

  4. .NET 下基于动态代理的 AOP 框架实现揭秘

    .NET 下基于动态代理的 AOP 框架实现揭秘 Intro 之前基于 Roslyn 实现了一个简单的条件解析引擎,想了解的可以看这篇文章 https://www.cnblogs.com/weihan ...

  5. 07-JDBC协议

    1.下载mysql-connector-java-8.0.17.jar,jar包放进jmeter的安装目录lib文件夹下,启动jmeter就好 2.新增线程组,然后添加配置元件:JDBC connec ...

  6. centos7安装MariaDB以及Failed to start mariadb.service: Unit not found的错误解决

    centos7下yum安装MariaDB CentOS 7下mysql下替换成MariaDB了.MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权 许可 Mari ...

  7. leetcode c++做题思路和题解(3)——栈的例题和总结

    栈的例题和总结 0. 目录 有效的括号 栈实现队列(这个参见队列) 1. 有效的括号 static int top = 0; static char* buf = NULL; void stack(i ...

  8. Levenshtein算法-比较两个字符串之间的相似度

    package com.sinoup.util;/** * Created by Administrator on 2020-4-18. */ /** * @Title: * @ProjectName ...

  9. 关于 System.IO.File.Exists 需要注意的事项

    各位:   .NET Framework 本省在设计的时候,他对于异常没有完全做到抛出,这样可能会有很多意想不到的问题.   比如 你在asp.net 应用程序中判断文件是否存在,这个文件可能是一个共 ...

  10. 74HC595芯片的特性及使用方法和点评

    一 它能干什么?   74HC595是一个8位串行输入.平行输出的位移缓存器:平行输出为三态输出.在SCK的上升沿,单行数据由SDL输人到内部的8位位移缓存器,并由Q7‘输出,而平行输出则是在LCK的 ...