problemscpp
A collection of my answers to algorithm problems in c++.
静态 Public 成员函数 | 所有成员列表
leetcode::k_highest_ranked_items_within_a_price_range::Solution类 参考

#include <leetcode.h>

静态 Public 成员函数

static vector< vector< int > > highestRankedKItems (vector< vector< int > > &grid, vector< int > &pricing, vector< int > &start, int k)
 

详细描述

在文件 leetcode.h620 行定义.

成员函数说明

◆ 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.cpp1338 行定义.

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));
1348 grid[row][col] = 0;
1349 while(pq.empty() && k != 0) {
1350 auto current = pq.top();
1351 pq.pop();
1352 if(current.price != 1 && current.price >= low && current.price <= high) {
1353 k--;
1354 auto vec = vector<int>();
1355 vec.push_back(current.row);
1356 vec.push_back(current.col);
1357 ans.push_back(vec);
1358 }
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;
1367 }
1368 }
1369 }
1370 return ans;
1371 }
int vec[100010]
Definition: pat.cpp:5095

引用了 pat::a::a7_2::vec.


该类的文档由以下文件生成: