当前位置:网站首页>Li Kou's 81st biweekly match
Li Kou's 81st biweekly match
2022-06-27 13:50:00 【leimingzeOuO】
Catalog
6104. Statistical asterisk
class Solution {
public:
int countAsterisks(string s) {
int cnt=1;
int res=0;
for(auto x:s)
{
if(x=='|')cnt++;
else
{
if(cnt%2)
{
if(x=='*')res++;
}
}
}
return res;
}
};
6106. Count the logarithm of points that cannot reach each other in an undirected graph
class Solution {
public:
int f[100010];
int cnt[100010];
int find(int x)
{
if(x!=f[x])f[x]=find(f[x]);
return f[x];
}
void unite(int a,int b)
{
int x=find(a),y=find(b);
if(x!=y)
{
cnt[x]+=cnt[y];
f[y]=x;
}
}
long long countPairs(int n, vector<vector<int>>& edges) {
for(int i=0;i<n;i++)f[i]=i,cnt[i]=1;
for(int i=0;i<edges.size();i++)
{
int a=edges[i][0],b=edges[i][1];
unite(a,b);
}
vector<int>v;
for(int i=0;i<n;i++)
if(f[i]==i)v.push_back(i);
long long res=0;
long long sum=0;
for(int i=0;i<v.size();i++)
{
res+=(long long)cnt[v[i]]*sum;
sum+=cnt[v[i]];
}
return res;
}
};
6105. Maximum XOR and after operation
class Solution {
public:
int maximumXOR(vector<int>& nums) {
int cnt[32]={
0};
for(int i=0;i<nums.size();i++)
{
int x=nums[i];
for(int j=0;j<31;j++)
{
if((x>>j)&1)cnt[j]++;
}
}
for(int i=0;i<31;i++)
if(cnt[i])cnt[i]=1;
int s=1;
int sum=0;
for(int i=0;i<31;i++)
{
if(cnt[i])sum+=s*cnt[i];
s<<=1;
}
return sum;
}
};
6107. The number of different die sequences
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(k!=u&&u!=j&&gcd(j+1,u+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;
}
};
边栏推荐
- Bidding announcement: Oracle database maintenance service procurement of the First Affiliated Hospital of Jinan University
- 以前国产手机高傲定价扬言消费者爱买不买,现在猛降两千求售
- IJCAI 2022 | greatly improve the effect of zero sample learning method with one line of code. Nanjing Institute of Technology & Oxford proposed the plug and play classifier module
- Kotlin函数使用示例教程
- Pre training weekly issue 51: reconstruction pre training, zero sample automatic fine tuning, one click call opt
- Cesium实现卫星在轨绕行
- JVM parameter setting and analysis
- Type 'image' is not a subtype of type 'imageprovider < object > solution
- CMOS level circuit analysis
- Learning records of numpy Library
猜你喜欢

Yuweng information, a well-known information security manufacturer, joined the dragon lizard community to build an open source ecosystem

Redis持久化

EventLoop learning

OpenSSF安全计划:SBOM将驱动软件供应链安全

Implementing springboard agent through SSH port forwarding configuration

American chips are hit hard again, and another chip enterprise after Intel will be overtaken by Chinese chips

Firewall foundation Huawei H3C firewall web page login

【业务安全-01】业务安全概述及测试流程

AGCO AI frontier promotion (6.27)

Realization of hospital medical record management system based on JSP
随机推荐
Implementing springboard agent through SSH port forwarding configuration
招标公告:上海市研发公共服务平台管理中心Oracle一体机软硬件维保项目
Pytorch learning 1 (learning documents on the official website)
Can flush open an account for stock trading? Is it safe?
[a complete human-computer interface program framework]
AXI總線
Quick news: Huawei launched the Hongmeng developer competition; Tencent conference released the "Wanshi Ruyi" plan
【周赛复盘】LeetCode第81场双周赛
Yuweng information, a well-known information security manufacturer, joined the dragon lizard community to build an open source ecosystem
MySQL locking mechanism and four isolation levels
How ASP connects Excel
OpenHGNN发布0.3版本
Axi bus
招标公告:暨南大学附属第一医院Oracle数据库维保服务采购
With the advent of the era of Internet of everything, Ruijie released a scenario based wireless zero roaming scheme
Openhgnn releases version 0.3
Intranet learning notes (8)
如何使用200行代码实现Scala的对象转换器
Kotlin函数使用示例教程
打印输出数(递归方法解决)