码迷,mamicode.com
首页 > 其他好文 > 详细

Codeforces Gym 100342J Problem J. Triatrip 三元环

时间:2016-06-27 13:48:37      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:

题目链接:

http://codeforces.com/gym/100342

题意:

求三元环的个数

题解:

用bitset分别统计每个点的出度的边和入度的边。

枚举每一条边(a,b),计算以b为出度的边的终点构成的点集和以a为入度的边的起点够成的点集的交集,更新答案。

代码:

#include<iostream>
#include<cstring>
#include<cstdio>
#include<bitset>
using namespace std;

const int maxn = 1555;
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 = 0; i < n; i++) scanf("%s", str[i]);
    LL ans = 0;
    for (int i = 0; i < n; i++){
        for (int j = 0; j < n; j++) {
            if (str[i][j] == +) {
                in[j][i] = true;
                out[i][j] = true;
            }
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (str[i][j] == +) {
                And = (in[i]) & (out[j]);
                ans += And.count();
            }
        }
    }
    printf("%I64d\n", ans / 3);
    return 0;
}

 

Codeforces Gym 100342J Problem J. Triatrip 三元环

标签:

原文地址:http://www.cnblogs.com/fenice/p/5619883.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!