当前位置:网站首页>第299场
第299场
2022-06-30 20:04:00 【julia点c】
判断矩阵是否是一个 X 矩阵
class Solution {
public:
bool checkXMatrix(vector<vector<int>>& grid) {
int n=grid[0].size();
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if((i==j||n-1-i==j)&&grid[i][j]==0) return false;
else if(i!=j&&n-1-i!=j&&grid[i][j]!=0) return false;
}
}
return true;
}
};
统计放置房子的方式数
动态规划 状态转移方程递推
class Solution {
const int MOD=1e9+7;
public:
int countHousePlacements(int n) {
vector<long long>dp(n+1);
dp[1]=2;
if(n==1)
{
return dp[n]*dp[n];
}
dp[2]=3;
if(n==2)
{
return dp[n]*dp[n];
}
for(int i=3;i<=n;i++)
{
dp[i]=(dp[i-1]+dp[i-2])%MOD;
}
return dp[n]*dp[n]%MOD;
}
};
拼接数组的最大分数
class Solution {
public:
int work(vector<int>&a,vector<int>&b)
{
int sum=0;
for(auto&x:a) sum+=x;
int dt=0,f=0;
for(int i=0;i<b.size();i++)
{
f=max(f,0)+b[i]-a[i];
dt=max(dt,f);
}
return sum+dt;
}
int maximumsSplicedArray(vector<int>& nums1, vector<int>& nums2) {
return max(work(nums1,nums2),work(nums2,nums1));
}
};
从树中删除边的最小分数
const int N = 1010, M = N * 2;
int h[N], e[M], ne[M], idx;
class Solution {
public:
int ans = 1e9;
vector<int> w;
void add(int a, int b) {
e[idx] = b, ne[idx] = h[a], h[a] = idx ++ ;
}
int dfs(int u, int fa, int sumx, int sumy) {
int res = w[u];
for (int i = h[u]; i != -1; i = ne[i]) {
int j = e[i];
if (j == fa) continue;
int t = dfs(j, u, sumx, sumy);
res ^= t;
if (sumx != -1) {
int a[3] = {
sumy, t, sumx ^ t};
sort(a, a + 3);
ans = min(ans, a[2] - a[0]);
}
}
return res;
}
int minimumScore(vector<int>& nums, vector<vector<int>>& edges) {
int n = nums.size();
w = nums;
for (int i = 0; i < n - 1; i ++ ) {
memset(h, -1, n * 4);
idx = 0;
for (int j = 0; j < n - 1; j ++ ) {
if (i != j) {
int a = edges[j][0], b = edges[j][1];
add(a, b), add(b, a);
}
}
int x = edges[i][0], y = edges[i][1];
int sumx = dfs(x, -1, -1, -1), sumy = dfs(y, -1, -1, -1);
dfs(x, -1, sumx, sumy);
dfs(y, -1, sumy, sumx);
}
return ans;
}
};
边栏推荐
- Static classes use @resource annotation injection
- Tensorflow2.4 implementation of repvgg
- Jerry's determination of detection sensitivity level [chapter]
- Common questions and answering skills of project manager interview
- Encoding type of Perl conversion file
- 【论文阅读】Trajectory-guided Control Prediction for End-to-end Autonomous Driving: A Simple yet Strong Baseline
- Jenkins打包拉取不到最新的jar包
- Go language identifier and package name specification
- By analyzing more than 7million R & D needs, it is found that these eight programming languages are the most needed by the industry
- obsidian配合hugo的使用,让markdown本地编辑软件与在线化无缝衔接
猜你喜欢
MySQL数据库误删回滚的解决

Great God detailed open source Buff gain Introduction 丨 Live

为什么一定要从DevOps走向BizDevOps?

mysql主从同步

How to pass the PMP Exam quickly?

By analyzing more than 7million R & D needs, it is found that these eight programming languages are the most needed by the industry

How unity pulls one of multiple components

Enterprise middle office planning and it architecture microservice transformation

NLP技能树学习路线-(一)路线总览
![Jerry's touch key recognition process [chapter]](/img/3e/bb73c735d0a7c7a26989c65a432dad.png)
Jerry's touch key recognition process [chapter]
随机推荐
CADD课程学习(1)-- 药物设计基础知识
北京大学ACM Problems 1002:487-3279
QT QStringList用法
PHP文件上传小结(乱码,移动失败,权限,显示图片)
Redis ziplist 压缩列表的源码解析
杰理之检测灵敏度级别确定【篇】
SQL优化
北京大学ACM Problems 1005:I Think I Need a Houseboat
Summary of PHP file upload (garbled code, move failure, permission, display picture)
信息学奥赛一本通 1362:家庭问题(family)
为什么一定要从DevOps走向BizDevOps?
静态类使用@Resource注解注入
北京大学ACM Problems 1001:Exponentiation
obsidian配合hugo的使用,让markdown本地编辑软件与在线化无缝衔接
杰理之用测试盒配对软件修改注意点【篇】
DEX文件解析 - method_ids解析
杰理之触摸按键识别流程【篇】
好高的佣金,《新程序员》合伙人计划来袭,人人皆可参与
Is it safe to open an account in Guangzhou stock exchange by mobile phone?
CADD course learning (1) -- basic knowledge of drug design