当前位置:网站首页>第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;
}
};
边栏推荐
- 杰理之关于长按开机检测抬起问题【篇】
- Filebeat custom indexes and fields
- 25: Chapter 3: developing pass service: 8: [registration / login] interface: receiving and verifying "mobile number and verification code" parameters; (it is important to know the application scenario
- 大神詳解開源 BUFF 增益攻略丨直播
- 杰理之触摸按键识别流程【篇】
- exness:美GDP终值意外加速萎缩1.6%
- Installation and use of securecrtportable
- 杰理之触摸按键识别流程【篇】
- 杰理之触摸按键识别流程【篇】
- 杰理之关于长按开机检测抬起问题【篇】
猜你喜欢

Exness: the final value of US GDP unexpectedly accelerated to shrink by 1.6%

项目经理是领导吗?可以批评指责成员吗?

maya房子建模

NLP paper lead reading | what about the degradation of text generation model? Simctg tells you the answer

CADD course learning (1) -- basic knowledge of drug design

传输层 使用滑动窗口实现流量控制

obsidian配合hugo的使用,让markdown本地编辑软件与在线化无缝衔接

Why should offline stores do new retail?

What is the difference between tolocal8bit and toutf8() in QT

1、生成对抗网络入门
随机推荐
Mistakes the project manager should not make
Jerry's touch key recognition process [chapter]
Go language identifier and package name specification
为什么一定要从DevOps走向BizDevOps?
Is it safe to open an account for online stock trading!?
【论文阅读】Trajectory-guided Control Prediction for End-to-end Autonomous Driving: A Simple yet Strong Baseline
Jerry's touch key recognition process [chapter]
[ICLR 2021] semi supervised object detection: unbiased teacher for semi supervised object detection
Tensorflow2.4 implementation of repvgg
By analyzing more than 7million R & D needs, it is found that these eight programming languages are the most needed by the industry
What is the difference between tolocal8bit and toutf8() in QT
TorchDrug--药物属性预测
CADD课程学习(1)-- 药物设计基础知识
Jerry's question about long press boot detection [chapter]
操作系统面试题汇总(不定期更新)
大神詳解開源 BUFF 增益攻略丨直播
文件包含&条件竞争
Build your own website (20)
北京大学ACM Problems 1006:Biorhythms
Filebeat自定义index和fields