Re: [闲聊] 每周leetcode

楼主: oin1104 (是oin的说)   2024-06-16 12:05:02
https://i.imgur.com/Y41d1jv.png
我起飞了家人们
计画有变 冲击徽章
第 1 2 题 :
问你有多少对数字
加起来可以被24整除
思路:
24个格子的哈希
```cpp
class Solution {
public:
long long countCompleteDayPairs(vector<int>& hours)
{
int len = hours.size();
vector<int> paper(24,0);
long long res = 0;
for(int i = 0 ; i < len ; i ++)
{
res += paper[(24 - hours[i]%24)%24];
// cout << (24 - hours[i]%24)%24 << " ";
paper[hours[i]%24] ++;
}
return res;
}
};
```
第 3 题 :
复杂版的强盗抢房子
思路 :
dp
干我一开始忘记因为是damage乘以数量
所以前面也有可能出现更大的数字
卡了超久
操机掰
```cpp
class Solution {
public:
long long maximumTotalDamage(vector<int>& power)
{
int plen = power.size();
map<int,int> spell;
for(int i = 0 ; i < plen ; i ++)
{
spell[power[i]] ++;
}
int len = spell.size();
vector<pair<int , long long>> paper (len , {0,0});
int p = 0;
long long pre = 0;
for(auto k : spell)
{
long long now = (long long)(k.second) * (long long)(k.first);
paper[p].first = k.first;
paper[p].second = now;
if(p > 0 && (paper[p-1].first != k.first-1) && (paper[p-1].first !=
k.first-2))
{
paper[p].second = max(paper[p].second, paper[p-1].second + now);
}
if(p > 1 && (paper[p-2].first != k.first-2))
{
paper[p].second = max(paper[p].second, paper[p-2].second + now);
}
if(p > 2)
{
pre = max(pre , paper[p-3].second);
}
paper[p].second = max(paper[p].second, pre + now);
p++;
}
long long res=0;
for(int i = 0 ; i < len ; i ++)
{
res = max(paper[i].second , res);
//cout << paper[i].first << " " ;
}
// cout << endl;
// for(int i = 0 ; i < len ; i ++)
// {
// cout << paper[i].second << " " ;
// }
// cout << endl;
return res;
}
};
```
作者: ErL0715 (爱萝)   2023-06-16 12:05:00
好猛==
作者: sustainer123 (caster)   2024-06-16 12:06:00
干 大师
作者: digua (地瓜)   2024-06-16 12:10:00
我好崇拜你
作者: DJYOSHITAKA (Evans)   2024-06-16 12:12:00
你好猛

Links booklink

Contact Us: admin [ a t ] ucptt.com