题目链接:

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 三元环的更多相关文章

  1. Codeforces Gym 100342J Problem J. Triatrip 求三元环的数量 bitset

    Problem J. Triatrip Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/at ...

  2. Codeforces Gym 100342J Problem J. Triatrip bitset 求三元环的数量

    Problem J. TriatripTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/att ...

  3. Codeforces Gym 100342C Problem C. Painting Cottages 转化题意

    Problem C. Painting CottagesTime Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/10 ...

  4. Codeforces Gym 100342C Problem C. Painting Cottages 暴力

    Problem C. Painting CottagesTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/1 ...

  5. Codeforces Gym 100610 Problem A. Alien Communication Masterclass 构造

    Problem A. Alien Communication Masterclass Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codefo ...

  6. Codeforces Gym 100002 Problem F "Folding" 区间DP

    Problem F "Folding" Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/ ...

  7. Codeforces Gym 100342H Problem H. Hard Test 构造题,卡迪杰斯特拉

    Problem H. Hard TestTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/at ...

  8. Codeforces Gym 100342D Problem D. Dinner Problem Dp+高精度

    Problem D. Dinner ProblemTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/1003 ...

  9. Codeforces Gym 100500F Problem F. Door Lock 二分

    Problem F. Door LockTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100500/at ...

随机推荐

  1. 集合框架学习之Collection和Map详解

    线性表,链表,哈希表是常用的数据结构,在进行Java开发时,JDK已经为我们提供了一系列相应的类来实现基本的数据结构.这些类均在java.util包中.本文试图通过简单的描述,向读者阐述各个类的作用以 ...

  2. FastSocket学习笔记~制定自已的传输协议~续~制定基于FastSocket的协议

    FastSocket这个东西上次我已经说过,它使用简单,功能强大,扩展灵活,目前在新浪的生产环境中已经被广泛使用,所以它的性能,安全等各方面我们绝对可以信赖,今天我们来说一个话题,和上一讲有关,这次我 ...

  3. 理解C#系列 / .NET体系结构

    .NET体系结构 索引 前提条件 编程 编程语言 编程语言之一:C# C#依赖.NET平台 .NET平台下的公共语言运行库 .NET平台下的基础类库 C#可以开发什么? 前提条件 [最低配置]知道什么 ...

  4. PHP的final、抽象类和方法

    final关键字的用法 final class Computer{ //无法继承的类 final public function run(){ //无法继承的方法 } } class NoteBook ...

  5. PowerDesigner数据库建模工具一缆

    转自:http://blog.csdn.net/shanliwa/archive/2007/10/20/1834117.aspx Sybase PowerDesigner - 一个高端数据建模工具.你 ...

  6. javascript弹窗基础篇

    confirm()意既确认框 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> ...

  7. 从0开始学习react(一)

    本人前端小菜鸡一枚,因为公司要重构网站,打算用用react,毕竟一切为了学习(装B)嘛!!! 在学习react之前,看了许多资料,博客,官方文档之类的,可我这记吃不记打的记性,还是需要在这里记录一下, ...

  8. Java 类成员的初始化顺序

    Java 类成员的初始化顺序 前言:开发中碰到一个Java文件中有很多的成员变量,包括静态和非静态的,还有很多的初始化方法,很好奇这些成员的初始化顺序,在这里作个研究.   1  无继承情况下的Jav ...

  9. 走出 null 就是空值的误区,以及变量赋值原理

    先放一张图片作为引入: 这里我用了一个示意图作为讲解: 平时,我们写的变量为什么能在我们调用它的时候就能被我们拿到所用,跟存钱罐一样,你往里面存一元大洋,它里面就有一元大洋,那么我们的变量在被我们创建 ...

  10. 在线生成ICO图标、站标

    网上一搜有很多,找了两个比较好用的,分别是http://ico.storyren.com/和http://www.ico.la/,前面的那个好像更好点.上传png.jpg.或gif格式的图片,按自己需 ...