当前位置:网站首页>Kwai 20200412 recruitment
Kwai 20200412 recruitment
2022-07-03 08:15:00 【CHPCWWHSU】


There are four questions in total , Made the first three questions . Record the next two questions , The first picture is the third question 、 The second picture is question 4 .
The code of the third question is as follows , I will simplify the third question to a sorting problem :
vector<int> WaitInLine(vector<int>& a, vector<int>& b) {
// write code here
vector<int>c; c.clear();
vector<int>out; out.clear();
for (int i = 0; i < a.size(); i++)
{
c.push_back(a[i] - b[i]);
out.push_back(i + 1);
}
// From big to small //
int num = c.size();
for(int i=0;i<num-1;i++)
for (int j = 0; j < num - 1 - i; j++)
{
if (c[j] < c[j + 1])
{
int temp = c[j + 1];
c[j + 1] = c[j];
c[j] = temp;
int temp2 = out[j + 1];
out[j + 1] = out[j];
out[j] = temp2;
}
}
return out;
}
The fourth question didn't work out , But I saw the idea on Niuke ,“ Select the least points around each time for statistics , And change the surrounding points to '*' ”, Some people also say using state compression , But I'm Xiaobai , I haven't heard of .
int GetMaxStaffs(vector<vector<char> >& pos) {
// write code here
// Traverse //
int rows = pos.size();
int cols = pos[0].size();
// The number of surrounding minimum points //
int row = 0; int col = 0;
do
{
bool isupdate = false;
int num = 4;
for (int i = 0; i < rows; i++)
for (int j = 1; j < cols; j++)
{
int tempNum = 0;
if (pos[i][j] == '.') {
if (i - 1 >= 0 && pos[i - 1][j] == '.')
{
tempNum++;
}
if (i + 1 < rows&&pos[i + 1][j] == '.')
{
tempNum++;
}
if (j - 1 >= 0 && pos[i][j - 1] == '.')
{
tempNum++;
}
if (j + 1 < cols&&pos[i][j + 1] == '.')
{
tempNum++;
}
}
if (tempNum>0&&tempNum < num)
{
num = tempNum;
row = i;
col = j;
isupdate = true;
}
}
if (row - 1 >= 0 && pos[row - 1][col] == '.')
{
pos[row - 1][col]='*';
}
if (row + 1 < rows&&pos[row + 1][col] == '.')
{
pos[row + 1][col] = '*';
}
if (col - 1 >= 0 && pos[row][col - 1] == '.')
{
pos[row][col - 1] = '*';
}
if (col + 1 < cols&&pos[row][col + 1] == '.')
{
pos[row][col + 1] = '*';
}
if (!isupdate)
{
break;
}
} while (true);
int out = 0;
for (int i = 0; i < rows; i++)
for (int j = 0; j < cols; j++)
{
if (pos[i][j] == '.')
{
out++;
}
}
return out;
}
If there is a better way , Welcome to leave a message .
边栏推荐
- Conversion between string and int types in golang
- Go resolve ID card
- regular expression
- Un système de gestion de centre commercial pour la conception de cours de technologie d'application de base de données
- Golang time format sorting
- Viz artist advanced script video tutorial -- stringmap use and vertex operation
- Ventuz Foundation Series "one step at the door"
- KunlunBase MeetUP 等您来!
- Basic operation and process control
- Pycharm remote ssh pyenv error: pydev debugger: warning: trying to add breakpoint to file that does
猜你喜欢
随机推荐
多旅行商问题——公式和求解过程概述
RM delete file
Pycharm remote ssh pyenv error: pydev debugger: warning: trying to add breakpoint to file that does
链式长取值
Zohocrm deluge function application time verification
[untitled]
C course design employee information management system
MAE
Editor Extensions
Map的实现类的顺序性
Delete the last character of the string in golang
一条通往服务器所有端口的隧道
What is BFC?
Uniapp learning records
2021-10-19
Oracle insert single quotation mark
CLion-Toolchains are not configured Configure Disable profile问题解决
Base64和Base64URL
【K&R】中文第二版 个人题解 Chapter1
璞华PLM为全场景产品生命周期管理赋能,助力产品主线的企业数字化转型









