当前位置:网站首页>力扣 第 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;
}
};
边栏推荐
- 6-4 vulnerability exploitation SSH banner information acquisition
- 【MATLAB】MATLAB 仿真模拟调制系统 — SSB 系统
- 通过dd创建asm disk
- laravel 中获取刚刚插入的记录的id
- 1. Mx6u-alpha development board (LED drive experiment in C language version)
- 附件六:防守工作簡報.docx
- 【MATLAB】通信信号调制通用函数 — 插值函数
- MAUI 入门教程系列(5.XAML及页面介绍)
- Kivy tutorial 07 component and attribute binding implementation button button click to modify the label component (tutorial includes source code)
- RAC delete damaged disk group
猜你喜欢
Technology Management - learning / practice
每日刷题记录 (十二)
令人头痛的延时双删
Formatted text of Kivy tutorial (tutorial includes source code)
中科磐云—D模块解析以及评分标准
Can closed data be deleted by DBCA? can
Talking about JVM
在代碼中使用度量單比特,從而生活更美好
2022年6月总结
Fault analysis | mongodb 5.0 reports an error, and the legal instruction solves it
随机推荐
Headache delayed double deletion
附件一:202x年xxx攻防演习授权委托书
附件六:防守工作简报.docx
LeetCode136+128+152+148
Using jsts in esmodule environment
《Cross-view Transformers for real-time Map-view Semantic Segmentation》论文笔记
Network equipment emergency response Guide
Public inputs in appliedzkp zkevm (13)
Encryption and decryption
Formatted text of Kivy tutorial (tutorial includes source code)
Flutter 调用高德地图APP实现位置搜索、路线规划、逆地理编码
关闭的数据能用dbca删除吗? 能
【MATLAB】MATLAB 仿真数字带通传输系统 — ASK、 PSK、 FSK 系统
【MATLAB】MATLAB 仿真 — 窄带高斯白噪声
Drozer tool
2022年6月总结
Definition of DCDC power supply current
【MATLAB】通信信号调制通用函数 — 低通滤波器
抓包整理外篇fiddler———— 会话栏与过滤器
cmake