当前位置:网站首页>[at] abc 258G - Triangle 三元組可達-暴力
[at] abc 258G - Triangle 三元組可達-暴力
2022-07-03 07:44: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 ;
}
边栏推荐
- Web router of vertx
- 技术干货|百行代码写BERT,昇思MindSpore能力大赏
- Project experience sharing: Based on mindspore, the acoustic model is realized by using dfcnn and CTC loss function
- Analysis of the problems of the 12th Blue Bridge Cup single chip microcomputer provincial competition
- Redis批量启停脚本
- The concept of C language pointer
- Pat class a 1031 Hello world for u
- 【踩坑系列】mysql 修改root密码失败
- Epoll related references
- 【LeetCode】3. Merge two sorted lists · merge two ordered linked lists
猜你喜欢

Harmonyos third training notes

项目经验分享:实现一个昇思MindSpore 图层 IR 融合优化 pass

PAT甲级 1029 Median

HCIA notes

Unity XR实现交互(抓取,移动旋转,传送,射击)-Pico

Go language foundation ------17 ----- channel creation, read-write, security shutdown, multiplexing select
![[MySQL 11] how to solve the case sensitive problem of MySQL 8.0.18](/img/9b/db5fe1a37e0de5ba363f9e108310a5.png)
[MySQL 11] how to solve the case sensitive problem of MySQL 8.0.18

Go language foundation ----- 01 ----- go language features

Technical dry goods Shengsi mindspire innovation model EPP mvsnet high-precision and efficient 3D reconstruction

Partage de l'expérience du projet: mise en œuvre d'un pass optimisé pour la fusion IR de la couche mindstore
随机推荐
Industrial resilience
C2 several methods of merging VCF files
Pat class a 1028 list sorting
experiment.........
s7700设备如何清除console密码
【LeetCode】4. Best time to buy and sell stock
Analysis of the problems of the 10th Blue Bridge Cup single chip microcomputer provincial competition
PAT甲级 1032 Sharing
An overview of IfM Engage
IndexSort
PHP微信抢红包的算法
Robots protocol
【MindSpore论文精讲】AAAI长尾问题中训练技巧的总结
Lucene hnsw merge optimization
UA camouflage, get and post in requests carry parameters to obtain JSON format content
Pat class a 1030 travel plan
PAT甲级 1029 Median
【踩坑系列】mysql 修改root密码失败
Application of pigeon nest principle in Lucene minshouldmatchsumscorer
EtherCAT state machine transition (ESM)