当前位置:网站首页>[at] abc 258G - Triangle 三元组可达-暴力
[at] abc 258G - Triangle 三元组可达-暴力
2022-07-03 07:42:00 【*DDL_GzmBlog】
前言
t a g : tag : tag:bitset
01图
传送门:
题意 :
给定一个 01 01 01完全图, 1 1 1表示这两个点有边相连, 0 0 0表示这两个点没有边相连
询问有多少组三元组 ( i , j , k ) (i,j,k) (i,j,k),满足两两之间有边相连
思路 :
暴力的做法 n 3 n^3 n3,因为图只存在 01 01 01,我们考虑使用位运算减去一层的枚举
即bitset
, 我们将状态存入biset
中,然后枚举两行之间的状态,进行 & \& &运算
显然的如果 & = 1 \&=1 &=1那么,存在三个点是可达的,时间复杂度 n 2 l o g n n^2logn n2logn
code :
void solve(){
int n;cin>>n;
vector<bitset<N>> v(n);
vector<string> s(n);
for(int i = 0; i < n; i ++ ){
cin>>s[i];
for(int j = 0 ; j < n ; j ++ ){
if(s[i][j] == '1') v[i][j] = 1;
}
}
ll ans = 0 ;
for(int i = 0 ; i< n ; i ++ ){
for(int j = 0 ; j< i ; j ++ ){
if(s[i][j] == '1') ans += (v[i]&v[j]).count();
}
}
cout<<ans/3<<endl;
}
int main(){
//int t;cin>>t;while(t--)
solve();
return 0 ;
}
边栏推荐
- Pat grade a 1027 colors in Mars
- Unified handling and interception of exception exceptions of vertx
- Go language foundation ----- 11 ----- regular expression
- Vertx's responsive redis client
- Go language foundation ----- 08 ----- interface
- PAT甲级 1029 Median
- 论文学习——鄱阳湖星子站水位时间序列相似度研究
- 【开发笔记】基于机智云4G转接板GC211的设备上云APP控制
- 在浏览器输入url后执行什么
- 哪一刻你才发现青春结束了
猜你喜欢
Reconnaissance et détection d'images - Notes
PAT甲级 1031 Hello World for U
在浏览器输入url后执行什么
Technical dry goods | alphafold/ rosettafold open source reproduction (2) - alphafold process analysis and training Construction
Unity XR实现交互(抓取,移动旋转,传送,射击)-Pico
Go language foundation ----- 16 ----- goroutine, GPM model
Epoll related references
Qtip2 solves the problem of too many texts
【LeetCode】2. Valid Parentheses·有效的括号
Image recognition and detection -- Notes
随机推荐
Go language foundation ----- 03 ----- process control, function, value transfer, reference transfer, defer function
Go language - loop statement
HDMI2.1与HDMI2.0的区别以及转换PD信号。
Structure of golang
Responsive MySQL of vertx
Go language foundation ----- 06 ----- anonymous fields, fields with the same name
Go language foundation ----- 11 ----- regular expression
Technical dry goods | alphafold/ rosettafold open source reproduction (2) - alphafold process analysis and training Construction
Go language foundation ----- 01 ----- go language features
Lucene introduces NFA
技术干货 | AlphaFold/ RoseTTAFold开源复现(2)—AlphaFold流程分析和训练构建
Pat grade a 1027 colors in Mars
experiment.........
Why is data service the direction of the next generation data center?
s7700设备如何清除console密码
Vertx restful style web router
Pat grade a 1029 median
Lombok cooperates with @slf4j and logback to realize logging
【踩坑系列】mysql 修改root密码失败
Hisat2 - stringtie - deseq2 pipeline for bulk RNA seq