Re: [闲聊] LeetCode Weekly Contest 413

楼主: oin1104 (是oin的说)   2024-09-01 12:39:04
家人们
下辈子在跟你们一起拿徽章
q1
西洋棋上的两个格子颜色是不是一样的
思路:
就看看奇偶 虾鸡巴写
```cpp
class Solution {
public:
bool checkTwoChessboards(string coordinate1, string coordinate2)
{
int a = 0;
if((coordinate1[0]-'0')&1)
{
if((coordinate1[1]-'a')&1)
{
a = 1;
}
else
{
a = 0;
}
}
else
{
if((coordinate1[1]-'a')&1)
{
a = 0;
}
else
{
a = 1;
}
}
int b = 0;
if((coordinate2[0]-'0')&1)
{
if((coordinate2[1]-'a')&1)
{
b = 1;
}
else
{
b = 0;
}
}
else
{
if((coordinate2[1]-'a')&1)
{
b = 0;
}
else
{
b = 1;
}
}
return a==b;
}
};
```
q2
给你一堆石头座标 绝对值相加是距离
每次放一颗石头进去
问你放入这个石头之后
第k近的有多远
思路:
用priority queue 来记录
要弹出最大的
保持在刚好k个在里面
```cpp
class Solution {
public:
vector<int> resultsArray(vector<vector<int>>& queries, int k)
{
int n = queries.size();
vector<int> res(n,-1);
priority_queue<int> sta;
for(int i = 0; i < n ; i ++)
{
int now = 0;
now += abs(queries[i][0]);
now += abs(queries[i][1]);
sta.push(now);
if(sta.size() > k)sta.pop();
if(sta.size() == k)res[i] = sta.top();
}
return res;
}
};
```
q3
不会
q4
不会
我哭了

Links booklink

Contact Us: admin [ a t ] ucptt.com