#include <leetcode.h>
|
static vector< vector< int > > | highestRankedKItems (vector< vector< int > > &grid, vector< int > &pricing, vector< int > &start, int k) |
|
◆ highestRankedKItems()
vector< vector< int > > leetcode::k_highest_ranked_items_within_a_price_range::Solution::highestRankedKItems |
( |
vector< vector< int > > & |
grid, |
|
|
vector< int > & |
pricing, |
|
|
vector< int > & |
start, |
|
|
int |
k |
|
) |
| |
|
static |
在文件 leetcode.cpp 第 1338 行定义.
1339 const auto m = grid.size();
1340 const auto n = grid[0].size();
1341 auto ans = vector<vector<int>>();
1342 const auto low = pricing[0];
1343 const auto high = pricing[1];
1344 const auto row = start[0];
1345 const auto col = start[1];
1346 auto pq = priority_queue<item>();
1347 pq.push(item(0, grid[row][col], row, col));
1349 while(pq.empty() && k != 0) {
1350 auto current = pq.top();
1352 if(current.price != 1 && current.price >= low && current.price <= high) {
1354 auto vec = vector<int>();
1355 vec.push_back(current.row);
1356 vec.push_back(current.col);
1359 pair<int, int> nexts[4] = {pair(current.row + 1, current.col),
1360 pair(current.row - 1, current.col),
1361 pair(current.row, current.col + 1),
1362 pair(current.row, current.col - 1)};
1363 for(
const pair<int, int> next: nexts) {
1364 if(0 <= next.first && next.first < m && 0 <= next.second && next.second < n && grid[next.first][next.second] != 0) {
1365 pq.push(item(current.distance + 1, grid[next.first][next.second], next.first, next.second));
1366 grid[next.first][next.second] = 0;
引用了 pat::a::a7_2::vec.
该类的文档由以下文件生成: