当前位置:网站首页>[at] abc 258G - Triangle 三元组可达-暴力
[at] abc 258G - Triangle 三元组可达-暴力
2022-07-03 07:42:00 【*DDL_GzmBlog】
前言
t a g : tag : tag:bitset01图
传送门:
题意 :
给定一个 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 ;
}
边栏推荐
- 【MySQL 13】安装MySQL后第一次修改密码,可以可跳过MySQL密码验证进行登录
- Grpc message sending of vertx
- Technical dry goods Shengsi mindspire elementary course online: from basic concepts to practical operation, 1 hour to start!
- opensips与对方tls sip trunk对接注意事项
- Reconnaissance et détection d'images - Notes
- Go language foundation ----- 10 ----- string related operations (operation function, string conversion)
- HCIA notes
- 论文学习——鄱阳湖星子站水位时间序列相似度研究
- 技术干货|昇思MindSpore可变序列长度的动态Transformer已发布!
- Technology dry goods | luxe model for the migration of mindspore NLP model -- reading comprehension task
猜你喜欢

Traversal in Lucene

PAT甲级 1028 List Sorting

【开发笔记】基于机智云4G转接板GC211的设备上云APP控制

一篇文章让你读懂-曼彻斯特编码

Go language foundation ----- 03 ----- process control, function, value transfer, reference transfer, defer function

Paper learning -- Study on the similarity of water level time series of Xingzi station in Poyang Lake

Analysis of the ninth Blue Bridge Cup single chip microcomputer provincial competition

UA camouflage, get and post in requests carry parameters to obtain JSON format content

技术干货|关于AI Architecture未来的一些思考

【LeetCode】3. Merge Two Sorted Lists·合并两个有序链表
随机推荐
项目经验分享:基于昇思MindSpore实现手写汉字识别
技术干货|AI框架动静态图统一的思考
Shengsi mindspire is upgraded again, the ultimate innovation of deep scientific computing
The babbage industrial policy forum
技术干货|昇思MindSpore NLP模型迁移之Roberta ——情感分析任务
C2 several methods of merging VCF files
微软安全响应中心
experiment.........
VMware network mode - bridge, host only, NAT network
[Development Notes] cloud app control on device based on smart cloud 4G adapter gc211
PAT甲级 1027 Colors in Mars
优质博客——
Technical dry goods Shengsi mindspire innovation model EPP mvsnet high-precision and efficient 3D reconstruction
Lombok -- simplify code
【开发笔记】基于机智云4G转接板GC211的设备上云APP控制
Analysis of the ninth Blue Bridge Cup single chip microcomputer provincial competition
昇思MindSpore再升级,深度科学计算的极致创新
【CoppeliaSim4.3】C#调用 remoteApi控制场景中UR5
Lucene merge document order
PgSQL converts string to double type (to_number())