当前位置:网站首页>第81场双周赛
第81场双周赛
2022-06-30 20:04:00 【julia点c】
统计星号
简单模拟
class Solution {
public:
int countAsterisks(string s) {
int cnt=0;
vector<int>res;
for(int i=0;i<s.size();i++)
{
if(s[i]=='*') cnt++;
else if(s[i]=='|') res.push_back(i);
}
for(int i=0;i<res.size();i+=2)
{
int a=res[i],b=res[i+1];
for(int j=a;j<=b;j++)
{
if(s[j]=='*') cnt--;
}
}
return cnt;
}
};
统计无向图中无法互相到达点对数
并查集
class Solution {
typedef long long LL;
public:
vector<int>p,s;
int find(int x)
{
if(p[x]!=x) p[x]=find(p[x]);
return p[x];
}
long long countPairs(int n, vector<vector<int>>& edges) {
for(int i=0;i<n;i++)
{
p.push_back(i);
s.push_back(1);
}
for(auto&x:edges)
{
int a=find(x[0]),b=find(x[1]);
if(a!=b)
{
s[b]+=s[a];
p[a]=b;
}
}
LL res=n*(n-1ll)/2;
for(int i=0;i<n;i++)
{
if(p[i]==i)
{
res-=s[i]*(s[i]-1ll)/2;
}
}
return res;
}
};
操作后的最大异或和
class Solution {
public:
int maximumXOR(vector<int>& nums) {
int ans=0;
for(auto &x:nums)
{
ans|=x;
}
return ans;
}
};
不同骰子序列的数目
dp y总的答案,我不会我好菜。。。。
const int N = 10010, MOD = 1e9 + 7;
int f[N][6][6];
class Solution {
public:
int gcd(int a, int b) {
return b ? gcd(b, a % b) : a;
}
int distinctSequences(int n) {
memset(f, 0, sizeof f);
if (n == 1) return 6;
for (int i = 0; i < 6; i ++ )
for (int j = 0; j < 6; j ++ )
if (gcd(i + 1, j + 1) == 1 && i != j)
f[2][i][j] = 1;
for (int i = 3; i <= n; i ++ )
for (int j = 0; j < 6; j ++ )
for (int k = 0; k < 6; k ++ )
if (j != k && gcd(j + 1, k + 1) == 1)
for (int u = 0; u < 6; u ++ )
if (u != j && u != k && gcd(u + 1, j + 1) == 1)
f[i][j][k] = (f[i][j][k] + f[i - 1][u][j]) % MOD;
int res = 0;
for (int i = 0; i < 6; i ++ )
for (int j = 0; j < 6; j ++ )
res = (res + f[n][i][j]) % MOD;
return res;
}
};
边栏推荐
- Notes on modification of Jerry's test box pairing software [chapter]
- 杰理之关于长按开机检测抬起问题【篇】
- Torchdrug -- drug attribute prediction
- Lingyun going to sea | 10 leap &huawei cloud: jointly helping Africa with inclusive financial services
- 项目经理是领导吗?可以批评指责成员吗?
- Go language identifier and package name specification
- mysql主从同步
- Is it safe to open an account for online stock trading!?
- Primary school, session 3 - afternoon: Web_ xxe
- Qt和其它GUI库的对比
猜你喜欢
Solve the problems of Devops landing in complex environment with various tools with full stack and full function solutions
Torchdrug -- drug attribute prediction
大神详解开源 BUFF 增益攻略丨直播
杰理之触摸按键识别流程【篇】
How to pass the PMP Exam quickly?
NLP skill tree learning route - (I) route overview
Maya house modeling
Redis ziplist 压缩列表的源码解析
Halcon知识:盘点一下计量对象【1】
杰理之触摸按键识别流程【篇】
随机推荐
操作系统面试题汇总(不定期更新)
杰理之触摸按键识别流程【篇】
Filebeat自定义index和fields
[ICLR 2021] semi supervised object detection: unbiased teacher for semi supervised object detection
VB的基本语法
exness:美GDP终值意外加速萎缩1.6%
神经网络入门(上)
DEX文件解析 - method_ids解析
Detailed steps for Django to upload excel tables and write data to the database
Notes on modification of Jerry's test box pairing software [chapter]
Tensorflow2.4 implementation of repvgg
杰理之关于长按开机检测抬起问题【篇】
Transport layer uses sliding window to realize flow control
计网 | 【五 传输层、六 应用层】知识点及例题
PM reports work like this, and the boss is willing to give you a raise
为什么一定要从DevOps走向BizDevOps?
1. Introduction to generating countermeasures network
Maya house modeling
Go 语言标识符、包名规范
Openfire在使用MySQL数据库后的中文乱码问题解决