当前位置:网站首页>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 .
边栏推荐
猜你喜欢
Multi traveling salesman problem -- overview of formula and solution process
*p++、*++p、++*p、(*p)++
Free use until 2015 -- viz artist multi touch plug-in package
Unity2019_ Lighting system
WPF:解决MaterialDesign:DialogHost 无法关闭问题
Easy touch plug-in
Base64 and base64url
Wechat applet taro learning record
haproxy+keepalived集群搭建02
How to configure GDAL under idea
随机推荐
C#课程设计之学生教务管理系统
L'installateur a été installé avec une erreur inattendue
[cocos creator] get the resource UUID
How to configure GDAL under idea
Student educational administration management system of C # curriculum design
[usaco12mar]cows in a skyscraper g (state compression DP)
Yolo series --- xml2txt script
Lua hot update basic grammar
Shader foundation 01
Golang 时间格式整理
多旅行商问题——公式和求解过程概述
ArrayList
Conversion between golang JSON format and structure
Are you still watching the weather forecast on TV?
Docker installs MySQL and successfully uses Navicat connection
the installer has encountered an unexpected error installing this package
Open the influence list of "National Meteorological Short Videos (Kwai, Tiktok) in November" in an interactive way“
C#课程设计之员工信息管理系统
[cocos creator] Click the button to switch the interface
Maxcompute string splitting function -split_ PART