Codeforces Gym 100342J Problem J. Triatrip 三元环
题目链接:
http://codeforces.com/gym/100342
题意:
求三元环的个数
题解:
用bitset分别统计每个点的出度的边和入度的边。
枚举每一条边(a,b),计算以b为出度的边的终点构成的点集和以a为入度的边的起点够成的点集的交集,更新答案。
代码:
#include<iostream>
#include<cstring>
#include<cstdio>
#include<bitset>
using namespace std; const int maxn = ;
typedef __int64 LL; bitset<maxn> in[maxn], out[maxn], And;
char str[maxn][maxn]; int main() {
freopen("triatrip.in", "r", stdin);
freopen("triatrip.out", "w", stdout);
int n;
scanf("%d", &n);
for (int i = ; i < n; i++) scanf("%s", str[i]);
LL ans = ;
for (int i = ; i < n; i++){
for (int j = ; j < n; j++) {
if (str[i][j] == '+') {
in[j][i] = true;
out[i][j] = true;
}
}
}
for (int i = ; i < n; i++) {
for (int j = ; j < n; j++) {
if (str[i][j] == '+') {
And = (in[i]) & (out[j]);
ans += And.count();
}
}
}
printf("%I64d\n", ans / );
return ;
}
Codeforces Gym 100342J Problem J. Triatrip 三元环的更多相关文章
- Codeforces Gym 100342J Problem J. Triatrip 求三元环的数量 bitset
Problem J. Triatrip Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/at ...
- Codeforces Gym 100342J Problem J. Triatrip bitset 求三元环的数量
Problem J. TriatripTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/att ...
- Codeforces Gym 100342C Problem C. Painting Cottages 转化题意
Problem C. Painting CottagesTime Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/10 ...
- Codeforces Gym 100342C Problem C. Painting Cottages 暴力
Problem C. Painting CottagesTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/1 ...
- Codeforces Gym 100610 Problem A. Alien Communication Masterclass 构造
Problem A. Alien Communication Masterclass Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codefo ...
- Codeforces Gym 100002 Problem F "Folding" 区间DP
Problem F "Folding" Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/ ...
- Codeforces Gym 100342H Problem H. Hard Test 构造题,卡迪杰斯特拉
Problem H. Hard TestTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/at ...
- Codeforces Gym 100342D Problem D. Dinner Problem Dp+高精度
Problem D. Dinner ProblemTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/1003 ...
- Codeforces Gym 100500F Problem F. Door Lock 二分
Problem F. Door LockTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100500/at ...
随机推荐
- 一个WebForm中连接SQL Server的例子
.cs using System; using System.Collections; using System.ComponentModel; using System.Data; using Sy ...
- Centos中安装PHP的PDO MySQL扩展的教程
PHP Data Objects(PDO)扩展为 PHP 访问数据库定义了一个轻量级的一致接口.实现 PDO 接口的每个数据库驱动可以公开具体数据库的特性作为标准扩展功能.注意利用 PDO 扩展自身并 ...
- 第二篇、Swift_自定义 tabbar 的 badgeValue显示样式
在实际的开发中,我们常常需要根据实际的需求,去改变bageValue的显示样式,默认是红色的背景,白色的字体颜色 使用方式: class BKTabBarController: UITabBarCon ...
- Objective-C 【@property 的参数问题】
------------------------------------------- @property参数 总的来说,这是一种编译器的特性(在生成@property的时候为@property添加相 ...
- MongoDB中的group
在Mongodb的查询中,有类似于SQL中group by功能的group函数.两者的功能有些类似,但是区别也是比较明显的. 对于SQL来说,group by的作用就是安装依据列来将数据表中的记录分成 ...
- 10款强大的jQuery/HTML5应用新鲜出炉
1.CSS3/jQuery自定义弹出窗口 多种弹出动画 这是一款利用jQuery和CSS3实现的自定义弹出窗口,这可比浏览器默认的弹出窗口漂亮多了.弹出窗口中可以自定义html,十分灵活.另外最重要的 ...
- MySQL之左连接与右连接
左连接: select 列1,列2,列N from tableA left join tableB on tableA.列 = tableB.列(正常是一个外键列) [此处表连接成一张大表,完全当成一 ...
- CXF调用wsdl2java生成客户端异常
用cxf生成java客户端代码的时候出现异常: undefined element declaration 's:schema' 解决办法:1.删除 2.替换 参考资料: http:/ ...
- c++11:copy_n
copy_n: Copies exactly count values from the range beginning at first to the range beginning at resu ...
- corosync+pacemaker实现高可用(HA)集群
corosync+pacemaker实现高可用(HA)集群(一) 重要概念 在准备部署HA集群前,需要对其涉及的大量的概念有一个初步的了解,这样在实际部署配置时,才不至于不知所云 资源.服务与 ...