当前位置:网站首页>第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;
}
};
边栏推荐
猜你喜欢

Solve the problems of Devops landing in complex environment with various tools with full stack and full function solutions
Source code analysis of redis ziplist compressed list

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

好高的佣金,《新程序员》合伙人计划来袭,人人皆可参与

CADD course learning (2) -- target crystal structure information

Build your own website (20)

GeoServer安装

Lambda expression principle analysis and learning (June 23, 2022)

How unity pulls one of multiple components

Summary of operating system interview questions (updated from time to time)
随机推荐
Maya House Modeling
Tensorflow2.4实现RepVGG
QT QStringList用法
Client请求外部接口标准处理方式
Cv+deep learning network architecture pytoch recurrence series basenets (backbones) (I)
[iccv 2019] characteristics precise supervision of feature super resolution for small object detection
Basic syntax of VB
漏洞扫描工具大全,妈妈再也不用担心我挖不到漏洞了
Primary school, session 3 - afternoon: Web_ sessionlfi
好高的佣金,《新程序员》合伙人计划来袭,人人皆可参与
杰理之关于长按开机检测抬起问题【篇】
数据库 OLAP、OLTP是什么?相同和不同?适用场景
Heartbeat and DRBD configuration process
神经网络入门(上)
Description of the latest RTSP address rules for Hikvision camera, NVR, streaming media server, playback and streaming [easy to understand]
GeoServer installation
Go 语言标识符、包名规范
文件包含&条件竞争
Heartbeat 与DRBD 配置过程
Client request external interface standard processing method