当前位置:网站首页>力扣 第 300 场周赛
力扣 第 300 场周赛
2022-07-04 04:24:00 【leimingzeOuO】
6108. 解密消息
class Solution {
public:
map<char,int>mp;
string decodeMessage(string key, string message) {
int cnt=0;
string s;
for(auto x:key)
if(!mp.count(x)&&x!=' ')mp[x]=cnt++;
for(auto x:message)
if(x==' ')s+=x;
else s+=mp[x]+'a';
return s;
}
};
6111. 螺旋矩阵 IV
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode() : val(0), next(nullptr) {} * ListNode(int x) : val(x), next(nullptr) {} * ListNode(int x, ListNode *next) : val(x), next(next) {} * }; */
class Solution {
public:
vector<vector<int>> spiralMatrix(int m, int n, ListNode* head) {
vector<vector<int>>v(m,vector<int>(n));
int row=0,col=0;
for(int i=0;i<m;i++)
for(int j=0;j<n;j++)v[i][j]=-1;
int l=0,r=n-1;
int t=0,b=m-1;
while(l<=r||t<=b)
{
for(int i=l;i<=r&&t<=b&&head;i++)v[t][i]=head->val,head=head->next;
t++;
for(int i=t;i<=b&&l<=r&&head;i++)v[i][r]=head->val,head=head->next;
r--;
for(int i=r;i>=l&&t<=b&&head;i--)v[b][i]=head->val,head=head->next;
b--;
for(int i=b;i>=t&&l<=r&&head;i--)v[i][l]=head->val,head=head->next;
l++;
}
return v;
}
};
6109. 知道秘密的人数
class Solution {
public:
int peopleAwareOfSecret(int n, int delay, int forget) {
const int mod=1e9+7;
vector<vector<int>>f(n+1,vector<int>(n+1));
for(int i=1;i<=forget;i++)f[1][i]=1;
for(int i=2;i<=n;i++)
{
for(int j=1;j<=forget;j++)
{
if(j==1)f[i][j]=(f[i-1][forget-1]-f[i-1][delay-1])%mod;
else f[i][j]=(f[i-1][j-1]-f[i-1][j-2])%mod;
f[i][j]=(f[i][j]+f[i][j-1])%mod;
}
}
return (f[n][forget]+mod)%mod;
}
};
6110. 网格图中递增路径的数目
class Solution {
public:
int n,m;
const int N=1010,mod=1e9+7;
int f[1010][1010];
vector<vector<int>>g;
int dx[4]={
-1,0,1,0},dy[4]={
0,1,0,-1};
int dp(int x,int y)
{
int &v=f[x][y];
if(~v)return v;
v=1;
for(int i=0;i<4;i++)
{
int a=x+dx[i],b=y+dy[i];
if(a>=0&&a<n&&b>=0&&b<m&&g[a][b]>g[x][y])
v=(v+dp(a,b))%mod;
}
return v;
}
int countPaths(vector<vector<int>>& grid) {
n=grid.size(),m=grid[0].size();
g=grid;
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
f[i][j]=-1;
int res=0;
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
res=(res+dp(i,j))%mod;
return res;
}
};
边栏推荐
- 中科磐云—2022广东木马信息获取解析
- Niuke Xiaobai monthly race 49
- Annex 2-2 confidentiality commitment docx
- 【MATLAB】MATLAB 仿真模拟调制系统 — DSB 系统
- Annex II: confidentiality agreement for offensive and defensive drills docx
- qt下开发mqtt的访问程序
- Utiliser des unités de mesure dans votre code pour une vie meilleure
- The second case analysis of the breakthrough of defense system from the perspective of the red team
- 【Go】数据库框架gorm
- Flutter 调用高德地图APP实现位置搜索、路线规划、逆地理编码
猜你喜欢
随机推荐
中科磐云—D模块解析以及评分标准
LeetCode136+128+152+148
When using flash to store parameters, the code area of flash is erased, which leads to the interrupt of entering hardware error
【MATLAB】MATLAB 仿真数字带通传输系统 — QPSK 和 OQPSK 系统
全国职业院校技能大赛(中职组)网络安全竞赛试题—解析
Error response from daemon: You cannot remove a running container 8d6f0d2850250627cd6c2acb2497002fc3
郑州正清园文化传播有限公司:针对小企业的7种营销技巧
Correct the classpath of your application so that it contains a single, compatible version of com. go
Create ASM disk through DD
The second case analysis of the breakthrough of defense system from the perspective of the red team
中科磐云—2022广东木马信息获取解析
What is the difference between Western Digital Green disk, blue disk, black disk, red disk and purple disk
Niuke Xiaobai monthly race 49
分享一些我的远程办公经验
2022年6月总结
GUI application: socket network chat room
First knowledge of batch processing
Drozer tool
Network equipment emergency response Guide
附件2-2保密承诺书.docx