当前位置:网站首页>Leetcode-6126: designing a food scoring system
Leetcode-6126: designing a food scoring system
2022-07-25 20:38:00 【Chrysanthemum headed bat】
leetcode-6126: Design food scoring system
subject
Problem solving
Method 1 : Orderly map+ Orderly set
According to the way of cooking , You can get dishes and corresponding scores , Choose the one with the highest score .
1. use first unordered_map<string,XXXX> according to The way of cooking , Get the corresponding Dishes and scores .
2. So how to get score The biggest , You can use order map( Red and black trees ), With score As key, Sort from large to small .
So there is map<int,XXXX,greater<int>>, So you can get the corresponding dishes by scoring
3. In order to ensure that the dishes are dictionary order , So use ordered sets , Sort from small to large ,set<string>
therefore unordered_map<string,map<int,set<string>,greater<int>>> map;
It can be based on The way of cooking ----> Maximum score ----> The one with the smallest dictionary order
class FoodRatings {
public:
map<string,int> foodRating;// variety of dishes ---> score
map<string,string> foodClass;// variety of dishes --> The way of cooking
unordered_map<string,map<int,set<string>,greater<int>>> map;// The way of cooking ----> score ( From big to small )----> variety of dishes
FoodRatings(vector<string>& foods, vector<string>& cuisines, vector<int>& ratings) {
for(int i=0;i<foods.size();i++){
foodRating[foods[i]]=ratings[i];
foodClass[foods[i]]=cuisines[i];
map[cuisines[i]][ratings[i]].insert(foods[i]);
}
}
void changeRating(string food, int newRating) {
// Delete the corresponding old dish score from the set
map[foodClass[food]][foodRating[food]].erase(food);
if(map[foodClass[food]][foodRating[food]].empty()){
// If the corresponding score map It's empty , Then delete the map
map[foodClass[food]].erase(foodRating[food]);
}
// Record the score of new dishes
foodRating[food]=newRating;
map[foodClass[food]][newRating].insert(food);
}
string highestRated(string cuisine) {
return *(map[cuisine].begin()->second.begin());
}
};
边栏推荐
- JMeter - interface test
- Technology cloud report: more than zero trust, the wild hope of Parra's "Digital Security Cloud strategy"
- [today in history] July 2: BitTorrent came out; The commercial system linspire was acquired; Sony deploys Playstation now
- 4everland storage node portal network design
- [noi simulation] string matching (suffix automata Sam, Mo team, block)
- Network RTK UAV test [easy to understand]
- [onnx] export pytorch model to onnx format: support multi parameter and dynamic input
- Apache MINA框架「建议收藏」
- Vulnhub | dc: 6 | [actual combat]
- Compilation and operation of program
猜你喜欢

The database empties the table data and makes the primary key start from 1

Myormframeworkjdbc review and problem analysis of user-defined persistence layer framework, and thought analysis of user-defined persistence layer framework
![[advanced mathematics] [5] definite integral and its application](/img/b2/62748b7533982f2b864148e0857490.png)
[advanced mathematics] [5] definite integral and its application
![MySQL date [plus sign / +] condition filtering problem](/img/86/aed048e27b3e0b0baa919204bc067c.png)
MySQL date [plus sign / +] condition filtering problem

leetcode-919:完全二叉树插入器

Detailed explanation of document operation

How much memory does bitmap occupy in the development of IM instant messaging?
![[advanced mathematics] [8] differential equation](/img/83/b6b07540e3cf6d6433e57447d42ee9.png)
[advanced mathematics] [8] differential equation

【高等数学】【6】多元函数微分学

Success factors of software R & D effectiveness measurement
随机推荐
ROS_ Rqt toolbox
Today's sleep quality record 75 points
Open source SPL enhances mangodb computing
[today in history] July 7: release of C; Chrome OS came out; "Legend of swordsman" issued
Interpretation of filter execution sequence source code in sprigboot
增加 swap 空间
preprocessor directives
[tensorrt] trtexec tool to engine
Key network protocols in tcp/ip four layer model
火山引擎项亮:机器学习与智能推荐平台多云部署解决方案正式发布
Docker 搭建 Redis Cluster集群
Follow up of Arlo's thinking
leetcode-146:LRU 缓存
Introduction to several scenarios involving programming operation of Excel in SAP implementation project
Question and answer 47: geeks have an appointment - the current monitoring system construction of CSC
Vulnhub | dc: 6 | [actual combat]
Arrow parquet
Yolov7 training error indexerror: list index out of range
Myormframeworkjdbc review and problem analysis of user-defined persistence layer framework, and thought analysis of user-defined persistence layer framework
tga文件格式(波形声音文件格式)