当前位置:网站首页>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 .
边栏推荐
- Delete the last character of the string in golang
- freetype库的移植
- JS regular case-
- 多旅行商问题——公式和求解过程概述
- oracle 插入单引号
- Pulitzer Prize in the field of information graphics - malofiej Award
- Golang string segmentation, substitution and interception
- Transplantation of freetype Library
- the installer has encountered an unexpected error installing this package
- P1596 [USACO10OCT]Lake Counting S
猜你喜欢

MAE

Are you still watching the weather forecast on TV?

数据的存储

PostGIS space function

Un système de gestion de centre commercial pour la conception de cours de technologie d'application de base de données

Zohocrm deluge function application time verification

Base64和Base64URL

About the problem that the editor and the white screen of the login interface cannot be found after the location of unityhub is changed

Flex flexible box layout
![[cocos creator] Click the button to switch the interface](/img/b8/f0fd54a2a197cbfd788990e2806b52.png)
[cocos creator] Click the button to switch the interface
随机推荐
P2704 [noi2001] artillery position (shape pressure DP)
Delete the last character of the string in golang
Usage of (case, when) in PostgreSQL
[end of 2021] National Meteorological Short Video (Kwai, Tiktok) influence list in December
Oracle insert single quotation mark
JS common basic case sorting (continuous update)
JS to implement publish and subscribe
[cocos creator] Click the button to switch the interface
Golang 时间格式整理
Are you still watching the weather forecast on TV?
Clion toolchains are not configured configure disable profile problem solving
Puhua PLM empowers the whole scene product lifecycle management and helps the enterprise digital transformation of the main line of products
链式长取值
[set theory] order relation (hastu example | divisive relation hastu | inclusive relation hastu | refinement relation hastu)
Scite change background color
idea取消引用显示效果
oracle 插入单引号
Minimap plug-in
Wechat native applet cloud development learning record 01
数据分析练习题