Codeforces Gym 100342J Problem J. Triatrip bitset 求三元环的数量
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 求三元环的数量的更多相关文章
- 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 三元环
题目链接: http://codeforces.com/gym/100342 题意: 求三元环的个数 题解: 用bitset分别统计每个点的出度的边和入度的边. 枚举每一条边(a,b),计算以b为出度 ...
- Gym 100342J Triatrip (求三元环的数量) (bitset优化)
<题目链接> 题目大意:用用邻接矩阵表示一个有向图,现在让你求其中三元环的数量. 解题分析:先预处理得到所有能够直接到达每个点的集合$arrive[N]$和所有能够由当前点到达的集合$to ...
- Gym - 100342J Triatrip (bitset求三元环个数)
https://vjudge.net/problem/Gym-100342J 题意:给出一个邻接矩阵有向图,求图中的三元环的个数. 思路: 利用bitset暴力求解,记得最后需要/3. #includ ...
- Gym - 100342J:Triatrip(Bitset加速求三元环的数量)
题意:求有向图里面有多少个三元环. 思路:枚举起点A,遍历A可以到的B,然后求C的数量,C的数量位B可以到是地方X集合,和可以到A的地方Y集合的交集(X&Y). B点可以枚举,也可以遍历.(两 ...
- 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 100610 Problem A. Alien Communication Masterclass 构造
Problem A. Alien Communication Masterclass Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codefo ...
- Codeforces Gym 100610 Problem E. Explicit Formula 水题
Problem E. Explicit Formula Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/10 ...
- Codeforces Gym 100002 Problem F "Folding" 区间DP
Problem F "Folding" Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/ ...
随机推荐
- 字符串截取数字和点击radio显示不同内容
<html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> & ...
- IIS应用程序池回收图文详解
转:http://blog.sina.com.cn/s/blog_8677fcaa010138uf.html 什么是应用程序池呢?这是微软的一个全新概念:应用程序池是将一个或多个应用程序链接到一个或多 ...
- [转] ArcGIS engine中气泡标注的添加、修改
小生 原文 ArcGIS engine中气泡标注的添加.修改! 你微微地笑着,不同我说什么话.而我觉得,为了这个,我已等待得久了. ...
- Selenium2Library系列 keywords 之 _SelectElementKeywords 之 list_should_have_no_selections(self, locator)
def list_should_have_no_selections(self, locator): """Verifies select list identified ...
- (三)相遇射线的3D碰撞盒
序 在2D游戏中,我们知道处理碰撞时,需要设置精灵遮罩图.同样,进入3D,处理碰撞时需要3D模型作为“遮罩图”. 索尼克 飞檐走壁 目的 (1)处理模型间的碰撞问题 (2)获取鼠标 ...
- BS与CS的联系与区别
C/S是Client/Server的缩写.服务器通常采用高性能的PC.工作站或小型机,并采用大型数据库系统,如Oracle.Sybase.InFORMix或SQL Server.客户端需要安装专用的客 ...
- ZOJ3772 - Calculate the Function(线段树+矩阵)
题目大意 给定一个序列A1 A2 .. AN 和M个查询 每个查询含有两个数 Li 和Ri. 查询定义了一个函数 Fi(x) 在区间 [Li, Ri] ∈ Z. Fi(Li) = ALi Fi(Li ...
- 【VB技巧】VB静态调用与动态调用dll详解
本文“[VB技巧]VB静态调用与动态调用dll详解”,来自:Nuclear'Atk 网络安全研究中心,本文地址:http://lcx.cc/?i=489,转载请注明作者及出处! [[请注意]]:在以下 ...
- JavaScript——以简单的方式理解闭包
闭包,在一开始接触JavaScript的时候就听说过.首先明确一点,它理解起来确实不复杂,而且它也非常好用.那我们去理解闭包之前,要有什么基础呢?我个人认为最重要的便是作用域(lexical scop ...
- 关于ssh和ajax小小总结
我是相当的不专业,写给自己看.有什么错误的话,说出来将感激不尽. 有两种方法异步传输 1.通过json字符串: jsp中这么写: $.getJSON( "details_ajaxActio ...