当前位置:网站首页>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 .
边栏推荐
- Get to know unity2 for the first time
- Shader foundation 01
- Conversion between JSON and object
- [cocos creator] get the resource UUID
- 十六进制编码简介
- STM32F103 SPI (pit Diary)
- Golang time format sorting
- [set theory] order relation (hastu example | divisive relation hastu | inclusive relation hastu | refinement relation hastu)
- My touch screen production "brief history" 2
- Editor Extensions
猜你喜欢

图像处理8-CNN图像分类

数据的存储

Redis的数据结构

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

Oracle queries grouped by time

Clion toolchains are not configured configure disable profile problem solving

Unity2019_ Natural ambient light_ Sky box

Multi traveling salesman problem -- overview of formula and solution process

Transfinite hacker cognition

How to configure GDAL under idea
随机推荐
idea取消引用显示效果
[set theory] order relation (hastu example | divisive relation hastu | inclusive relation hastu | refinement relation hastu)
P2704 [NOI2001] 炮兵阵地(状压dp)
Conversion between string and int types in golang
One dimensional array two dimensional array (sort Max insert sort)
MAE
PostGIS space function
STM32F103 SPI (pit Diary)
ArrayList
RM delete file
JS to implement publish and subscribe
链式长取值
MaxCompute字符串分割函数-SPLIT_PART
E: Unable to locate package ROS melody desktop full
Usage of (case, when) in PostgreSQL
Golang中删除字符串的最后一个字符
Free use until 2015 -- viz artist multi touch plug-in package
Ilruntime learning - start from scratch
[USACO12MAR]Cows in a Skyscraper G(状态压缩dp)
freetype库的移植