当前位置:网站首页>[at] abc 258G - Triangle 三元組可達-暴力
[at] abc 258G - Triangle 三元組可達-暴力
2022-07-03 07:44: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 ;
}
边栏推荐
- Read config configuration file of vertx
- The difference between typescript let and VaR
- Go language foundation ------ 14 ------ gotest
- [at] abc 258G - Triangle 三元组可达-暴力
- Redis配置文件
- PAT甲级 1028 List Sorting
- PHP微信抢红包的算法
- pgAdmin 4 v6.11 发布,PostgreSQL 开源图形化管理工具
- Leetcode 198: house raiding
- Technical dry goods Shengsi mindspire lite1.5 feature release, bringing a new end-to-end AI experience
猜你喜欢
Leetcode 198: house raiding
PAT甲级 1030 Travel Plan
项目经验分享:实现一个昇思MindSpore 图层 IR 融合优化 pass
技术干货|昇思MindSpore NLP模型迁移之LUKE模型——阅读理解任务
Go language foundation ----- 05 ----- structure
Pat class a 1028 list sorting
Reconnaissance et détection d'images - Notes
图像识别与检测--笔记
Lucene hnsw merge optimization
OSPF experiment
随机推荐
什么是定义?什么是声明?它们有何区别?
UA camouflage, get and post in requests carry parameters to obtain JSON format content
Analysis of the ninth Blue Bridge Cup single chip microcomputer provincial competition
[mindspire paper presentation] summary of training skills in AAAI long tail problem
Go language foundation ------ 14 ------ gotest
【MySQL 13】安装MySQL后第一次修改密码,可以可跳过MySQL密码验证进行登录
The difference between typescript let and VaR
Go language foundation ----- 19 ----- context usage principle, interface, derived context (the multiplexing of select can be better understood here)
[at] abc 258G - Triangle 三元组可达-暴力
Es writing fragment process
Structure of golang
Go language foundation ----- 11 ----- regular expression
IndexSort
Technical dry goods Shengsi mindspire innovation model EPP mvsnet high-precision and efficient 3D reconstruction
技术干货|昇思MindSpore Lite1.5 特性发布,带来全新端侧AI体验
The concept of C language pointer
Go language foundation ----- 02 ----- basic data types and operators
HCIA notes
密西根大学张阳教授受聘中国上海交通大学客座教授(图)
JUnit unit test of vertx