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;
}
};
```