当前位置:网站首页>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;
}
};
边栏推荐
- 北京大学ACM Problems 1006:Biorhythms
- unittest自动测试多个用例时,logging模块重复打印解决
- CADD course learning (1) -- basic knowledge of drug design
- 25: Chapter 3: developing pass service: 8: [registration / login] interface: receiving and verifying "mobile number and verification code" parameters; (it is important to know the application scenario
- Meeting, onemeeting, OK!
- 基于开源流批一体数据同步引擎ChunJun数据还原—DDL解析模块的实战分享
- C文件指针
- 杰理之关于长按开机检测抬起问题【篇】
- 好高的佣金,《新程序员》合伙人计划来袭,人人皆可参与
- 请问海量数据如何去取最大的K个
猜你喜欢
漏洞扫描工具大全,妈妈再也不用担心我挖不到漏洞了
Exness: liquidity series - liquidity cleaning and reversal, decision interval
Cv+deep learning network architecture pytoch recurrence series basenets (backbones) (I)
Big God explains open source buff gain strategy live broadcast
杰理之触摸按键识别流程【篇】
Torchdrug -- drug attribute prediction
Build your own website (20)
大神详解开源 BUFF 增益攻略丨直播
Transport layer uses sliding window to realize flow control
To eliminate bugs, developers must know several bug exploration and testing artifacts.
随机推荐
exness:美GDP终值意外加速萎缩1.6%
北京大学ACM Problems 1001:Exponentiation
How to pass the PMP Exam quickly?
北京大学ACM Problems 1004:Financial Management
Jenkins can't pull the latest jar package
好高的佣金,《新程序员》合伙人计划来袭,人人皆可参与
Summary of PHP file upload (garbled code, move failure, permission, display picture)
Transport layer uses sliding window to realize flow control
Heartbeat 与DRBD 配置过程
北京大学ACM Problems 1005:I Think I Need a Houseboat
大神詳解開源 BUFF 增益攻略丨直播
凌云出海记 | 一零跃动&华为云:共助非洲普惠金融服务
Summary of personal work of 21 groups in the first week of summer training
C文件指针
信息学奥赛一本通 1362:家庭问题(family)
杰理之触摸按键识别流程【篇】
Client request external interface standard processing method
Implementation principle of PostgreSQL heap table storage engine
Notes on modification of Jerry's test box pairing software [chapter]
Maya house modeling