当前位置:网站首页>第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;
}
};
边栏推荐
- Implementation principle of PostgreSQL heap table storage engine
- MySQL数据库误删回滚的解决
- mysql主从同步
- Is it safe to open an account for online stock trading!?
- 【ICLR 2021】半监督目标检测:Unbiased Teacher For Semi-Supervised Object Detection
- Network planning | [five transport layers and six application layers] knowledge points and examples
- Jerry's touch key recognition process [chapter]
- 杰理之触摸按键识别流程【篇】
- Why must we move from Devops to bizdevops?
- 网上炒股开户安全嘛!?
猜你喜欢

25:第三章:开发通行证服务:8:【注册/登录】接口:接收并校验“手机号和验证码”参数;(重点需要知道【利用redis来暂存数据,获取数据的】的应用场景)(使用到了【@Valid注解】参数校验)

Is the project manager a leader? Can you criticize and blame members?

漏洞扫描工具大全,妈妈再也不用担心我挖不到漏洞了

maya房子建模

杰理之触摸按键识别流程【篇】

Summary of operating system interview questions (updated from time to time)

以全栈全功能解决方案,应对多样工具复杂环境DevOps落地难题

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

Document contains & conditional competition

NLP skill tree learning route - (I) route overview
随机推荐
谈谈内联函数
DEX file parsing - Method_ IDS resolution
Jerry's touch key recognition process [chapter]
Qt:qaxobject operation Excel
北京大学ACM Problems 1004:Financial Management
开会,OneMeeting,OK!
QT qstringlist usage
Jerry's touch key recognition process [chapter]
[try to hack] windows system account security
SecureCRTPortable的安装和使用(图文详解)
Is it safe to open an account in Guangzhou stock exchange by mobile phone?
maya房子建模
exness:美GDP终值意外加速萎缩1.6%
Jenkins打包拉取不到最新的jar包
Basic syntax of VB
Taihu Lake "China's healthy agricultural products · mobile phone live broadcast" enters Taihu Lake
如何快速通过PMP考试?
Jenkins can't pull the latest jar package
神经网络入门(上)
基于开源流批一体数据同步引擎ChunJun数据还原—DDL解析模块的实战分享