Problem J. Triatrip
Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/gym/100342/attachments

Description

The travel agency “Four Russians” is offering the new service for their clients. Unlike other agencies that only suggest one-way or roundtrip for airline tickets to their customers, “Four Russians” offers the brand new idea — triatrip. Triatrip traveler starts in some city A, flies to some city B, then flies to some city C, and returns to the city A.
Now the managers of the agency started to wonder, how many different triatrips they can offer to their customers. Given a map of all possible flights, help them to find that out.

Input

The first line of the input file contains two integer numbers n — the number of cities that are served by airlines that agree to sell their tickets via the agency (3 ≤ n ≤ 1500). The following n lines contain a sequence of n characters each — the j-th character of the i-th line is ‘+’ if it is possible to fly from the i-th city to the j-th one, and ‘-’ if it is not. The i-th character of the i-th line is ‘-’.

Output

Output one integer number — the number of triatrips that the agency can offer to its customers.

Sample Input

4
--+-
+--+
-+--
--+-

Sample Output

2

HINT

题意

给你一个临街矩阵,然后让你找有多少个三元环

题解

这道题数据范围只有1500,所以可以n^2,我们暴力枚举两个点,假设为A->B,然后我们预处理出有哪些点可以到A,B可以到哪些点,这样就可以得到俩集合,然后再交一下,再统计一下集合里面元素的个数就好了

这个可以用bitset来解决,但是窝们太弱了,完全不知道这个东西,于是就手写的BITSET= =,我的队友太神了

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std; const int t=;
const int N=;
int v[N][N],f[N][],g[N][],sum[<<t],p,n;
long long cnt=;
char s[N]; int main()
{
// freopen("b.txt","r",stdin);
freopen("triatrip.in","r",stdin);
freopen("triatrip.out","w",stdout);
for(int i=;i<(<<t);i++)
{
for(int j=;j<t;j++)
if(i&(<<j)) sum[i]++;
}
scanf("%d",&n);
int p=(n-)/t+;
for(int i=;i<n;i++)
{
scanf("%s",s);
for(int j=;j<n;j++)
{
if(s[j]=='+') v[i][j]=;
}
}
for(int i=;i<n;i++)
{
for(int j=;j<p;j++)
{
for(int k=;k<t;k++)
{
if(v[i][j*t+k]) f[i][j]|=<<k;
if(v[j*t+k][i]) g[i][j]|=<<k;
}
// cout<<f[i][j]<<" "<<g[i][j]<<endl;
}
}
for(int i=;i<n;i++)
{
for(int j=;j<n;j++)
if(v[j][i])
{
for(int k=;k<p;k++)
{
int x=f[i][k]&g[j][k];
cnt+=(long long)sum[x];
// cout<<i<<" "<<j<<" "<<x<<" "<<sum[x]<<endl;
}
}
}
printf("%lld\n",cnt/3LL);
return ;
}

Codeforces Gym 100342J Problem J. Triatrip bitset 求三元环的数量的更多相关文章

  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 三元环

    题目链接: http://codeforces.com/gym/100342 题意: 求三元环的个数 题解: 用bitset分别统计每个点的出度的边和入度的边. 枚举每一条边(a,b),计算以b为出度 ...

  3. Gym 100342J Triatrip (求三元环的数量) (bitset优化)

    <题目链接> 题目大意:用用邻接矩阵表示一个有向图,现在让你求其中三元环的数量. 解题分析:先预处理得到所有能够直接到达每个点的集合$arrive[N]$和所有能够由当前点到达的集合$to ...

  4. Gym - 100342J Triatrip (bitset求三元环个数)

    https://vjudge.net/problem/Gym-100342J 题意:给出一个邻接矩阵有向图,求图中的三元环的个数. 思路: 利用bitset暴力求解,记得最后需要/3. #includ ...

  5. Gym - 100342J:Triatrip(Bitset加速求三元环的数量)

    题意:求有向图里面有多少个三元环. 思路:枚举起点A,遍历A可以到的B,然后求C的数量,C的数量位B可以到是地方X集合,和可以到A的地方Y集合的交集(X&Y). B点可以枚举,也可以遍历.(两 ...

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

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

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

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

  8. Codeforces Gym 100610 Problem E. Explicit Formula 水题

    Problem E. Explicit Formula Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/10 ...

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

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

随机推荐

  1. AFNetworking教程

    转:http://www.lanrenios.com/tutorials/network/2012/1126/527.html AFNETWORKING AFNetworking他是一个现在非常用得多 ...

  2. Super关键字

    一.super关键字

  3. AutoLayout UITableViewCell 动态高度

    从这里http://www.cnblogs.com/liandwufan/p/4516956.html?utm_source=tuicool 转载过来的 -(UITableViewCell*)tabl ...

  4. PowerDesigner Vs Enterprise Architect

    注: 以下文中PD表示PowerDesigner,EA表示Enterprise Architect 最近一直在做设计方面的事情,之前一直在用PD.有个阿里过来的同事说阿里都是用EA,我就抽空小研究了一 ...

  5. net中前台javascript与后台c#函数相互调用

    问: 1.如何在JavaScript访问C#函数? 2.如何在JavaScript访问C#变量? 3.如何在C#中访问JavaScript的已有变量? 4.如何在C#中访问JavaScript函数? ...

  6. Integer做WeakHashMap的Key应注意的问题

    WeakHashMap使用弱引用来作为Map的Key,利用虚拟机的垃圾回收机制能自动释放Map中没有被使用的条目.但是WeakHashMap释放条目是有条件的:首先条目的Key在系统中没有强引用指向: ...

  7. [微软实习生2014]K-th string

    很久之前的事情了,微软2014实习生的在线测试题,记录下来以备后用. 题目描述: Description Consider a string set that each of them consist ...

  8. bzoj 1025 [SCOI2009]游戏(置换群,DP)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1025 [题意] 给定n,问1..n在不同的置换下变回原序列需要的不同排数有多少种. [ ...

  9. sql-case列转行

    1:对列进行逻辑判断 select ID,Score, case when Score>=90 then 'A' when Score>=80 then 'B' when Score> ...

  10. [Hive优化] 之 MapJoin

    根据mapjoin的计算原理,MAPJION会把小表全部读入内存中,在map阶段直接拿另外一个表的数据和内存中表数据做匹配.这种情况下即使笛卡尔积也不会对任务运行速度造成太大的效率影响. mapjoi ...