当前位置:网站首页>Game 81 biweekly
Game 81 biweekly
2022-06-30 20:32:00 【Julia point C】
Statistical asterisk
Simple simulation
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;
}
};
Count the logarithm of points that cannot reach each other in an undirected graph
Union checking set
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;
}
};
Maximum XOR and after operation
class Solution {
public:
int maximumXOR(vector<int>& nums) {
int ans=0;
for(auto &x:nums)
{
ans|=x;
}
return ans;
}
};
The number of different die sequences
dp y Total answer , I can't my good food ....
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;
}
};
边栏推荐
- Perl转换文件的编码类型
- exness:美GDP终值意外加速萎缩1.6%
- NLP skill tree learning route - (I) route overview
- 请指教在线开户需要什么银行卡?另外想问,现在在线开户安全么?
- 二叉查找树(一) - 概念与C语言实现
- Network planning | [five transport layers and six application layers] knowledge points and examples
- 动态样式绑定--style 和 class
- 信息学奥赛一本通 1362:家庭问题(family)
- Notes on modification of Jerry's test box pairing software [chapter]
- 第81场双周赛
猜你喜欢

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

A complete collection of vulnerability scanning tools. Mom doesn't have to worry that I won't find any more vulnerabilities

1、生成对抗网络入门

exness:流动性系列-流动性清洗和反转、决策区间

微信小程序开发实战 云音乐

AVL balanced binary tree (I) - concept and C language implementation
![Jerry's touch key recognition process [chapter]](/img/ec/25d2d6fd26571e4fb642129a4eee1b.png)
Jerry's touch key recognition process [chapter]

maya房子建模

分析超700万个研发需求发现,这八大编程语言才是行业最需要的

Maya house modeling
随机推荐
Is it safe to open an account in Guangzhou stock exchange by mobile phone?
Jenkins can't pull the latest jar package
Common questions and answering skills of project manager interview
MySQL master-slave synchronization
数据库 OLAP、OLTP是什么?相同和不同?适用场景
Tensorflow2.4实现RepVGG
北京大学ACM Problems 1005:I Think I Need a Houseboat
1045 error occurred in MySQL login. Modification method [easy to understand]
Black apple server system installation tutorial, black apple installation tutorial, teach you how to install black apple in detail [easy to understand]
Network planning | [five transport layers and six application layers] knowledge points and examples
Meeting, onemeeting, OK!
网上炒股开户安全嘛!?
All the important spark summit features were released here last night (with ultra clear video attached)
开会,OneMeeting,OK!
Static classes use @resource annotation injection
Qt和其它GUI库的对比
Is it safe to open an account for online stock trading!?
Halcon知识:盘点一下计量对象【1】
PostgreSQL heap堆表 存储引擎实现原理
How to pass the PMP Exam quickly?