当前位置:网站首页>Li Kou's 300th weekly match
Li Kou's 300th weekly match
2022-07-04 05:04:00 【leimingzeOuO】
Catalog
6108. Decrypt the message
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. Spiral matrix 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. Number of people who know the secret
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. The number of incremental paths in the grid graph
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;
}
};
边栏推荐
- 附件三:防守方评分标准.docx
- 红队视角下的防御体系突破之第二篇案例分析
- 【MATLAB】MATLAB 仿真模拟调制系统 — VSB 系统
- 【无标题】
- Capturing and sorting out external Fiddler -- Conversation bar and filter
- 在代碼中使用度量單比特,從而生活更美好
- Annex III: scoring standard of the defender docx
- Trie数-字典树
- Yolov6 practice: teach you to use yolov6 for object detection (with data set)
- 【MATLAB】MATLAB 仿真模拟调制系统 — AM 已调信号的功率谱与相干解调
猜你喜欢
Detailed comparison of Hynix emmc5.0 and 5.1 series
Customize a pager needed in your project
VSCode的有用插件
2022年T电梯修理操作证考试题库及模拟考试
小程序毕业设计---美食、菜谱小程序
Flutter ‘/usr/lib/libswiftCore. dylib‘ (no such file)
National vocational college skills competition (secondary vocational group) network security competition questions - Analysis
Fault analysis | mongodb 5.0 reports an error, and the legal instruction solves it
NTFS 安全权限
Unity 接入天气系统
随机推荐
在代碼中使用度量單比特,從而生活更美好
Network equipment emergency response Guide
[matlab] matlab simulation - simulate the AM modulation process of the modulation system
When using flash to store parameters, the code area of flash is erased, which leads to the interrupt of entering hardware error
VSCode的有用插件
COMP1721 Creating Classes
YoloV6实战:手把手教你使用Yolov6进行物体检测(附数据集)
[matlab] matlab simulation - narrow band Gaussian white noise
STM32F1与STM32CubeIDE编程实例-74HC595驱动4位7段数码管
[matlab] general function of communication signal modulation inverse Fourier transform
Customize a pager needed in your project
appliedzkp zkevm(11)中的EVM Proof
Encryption and decryption
附件六:防守工作簡報.docx
EVM proof in appliedzkp zkevm (11)
Unity is connected to the weather system
2022年6月总结
【MATLAB】MATLAB 仿真模拟调制系统 — AM 已调信号的功率谱与相干解调
附件六:防守工作简报.docx
RPC - grpc simple demo - learn / practice