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
题意
给出邻接矩阵,有向图,找出三元环的个数
题解:
bitset 暴力枚举一条边,出度入度的集合用到bitset
代码:
- //作者:1085422276
- #include <cstdio>
- #include <cmath>
- #include <cstring>
- #include <ctime>
- #include <iostream>
- #include <algorithm>
- #include <set>
- #include <vector>
- #include <sstream>
- #include <queue>
- #include <typeinfo>
- #include <fstream>
- #include<bits/stdc++.h>
- #include <map>
- #include <stack>
- typedef long long ll;
- using namespace std;
- const int inf = ;
- inline ll read()
- {
- ll x=,f=;
- char ch=getchar();
- while(ch<''||ch>'')
- {
- if(ch=='-')f=-;
- ch=getchar();
- }
- while(ch>=''&&ch<='')
- {
- x=x*+ch-'';
- ch=getchar();
- }
- return x*f;
- }
- ll exgcd(ll a,ll b,ll &x,ll &y)
- {
- ll temp,p;
- if(b==){
- x=;y=;
- return a;
- }
- p=exgcd(b,a%b,x,y);
- temp=x;x=y;y=temp-(a/b)*y;
- return p;
- }
- //*******************************
- #define N 1510
- bitset<N> in[N],out[N],he;
- char mp[][];
- int main()
- {
- freopen("triatrip.in","r",stdin);
- freopen("triatrip.out","w",stdout);
- int n;
- n=read();
- for(int i=;i<=n;i++)
- scanf("%s",mp[i]);
- for(int i=;i<=n;i++)
- {
- for(int j=;j<=n;j++)
- {
- if(i==j)continue;
- if(mp[i][j-]=='+')
- {
- in[i][j]=true;
- out[j][i]=true;
- }
- }
- }
- ll ans=;
- for(int i=;i<=n;i++)
- {
- for(int j=;j<=n;j++)
- {
- if(i==j)continue;
- if(mp[i][j-]=='+')
- he=(in[j])&(out[i]),ans+=he.count();
- }
- }
- cout<<ans/<<endl;
- return ;
- }
Codeforces Gym 100342J Problem J. Triatrip 求三元环的数量 bitset的更多相关文章
- 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 100342J Problem J. Triatrip 三元环
题目链接: http://codeforces.com/gym/100342 题意: 求三元环的个数 题解: 用bitset分别统计每个点的出度的边和入度的边. 枚举每一条边(a,b),计算以b为出度 ...
- Gym 100342J Triatrip (求三元环的数量) (bitset优化)
<题目链接> 题目大意:用用邻接矩阵表示一个有向图,现在让你求其中三元环的数量. 解题分析:先预处理得到所有能够直接到达每个点的集合$arrive[N]$和所有能够由当前点到达的集合$to ...
- Gym - 100342J:Triatrip(Bitset加速求三元环的数量)
题意:求有向图里面有多少个三元环. 思路:枚举起点A,遍历A可以到的B,然后求C的数量,C的数量位B可以到是地方X集合,和可以到A的地方Y集合的交集(X&Y). B点可以枚举,也可以遍历.(两 ...
- Gym - 100342J Triatrip (bitset求三元环个数)
https://vjudge.net/problem/Gym-100342J 题意:给出一个邻接矩阵有向图,求图中的三元环的个数. 思路: 利用bitset暴力求解,记得最后需要/3. #includ ...
- Codeforces 434E - Furukawa Nagisa's Tree(三元环+点分治)
Codeforces 题面传送门 & 洛谷题面传送门 场号 hopping,刚好是我的学号(指 round 的编号) 注:下文中分别用 \(X,Y,K\) 代替题目中的 \(x,y,k\) 注 ...
- 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 ...
随机推荐
- Strust的基础情况
Struts的优点: 1.实现MVC模式,结构清晰 2.丰富的标签(tag) 3.通过配置文件页面导航,便于后期维护 4.与Servlet API松耦合,便于测试 Structs2=Structs1的 ...
- js Float 精度
1.加法 //加法 function add(arg1,arg2){ var r1,r2,m; try{r1=arg1.toString().split(".")[1].lengt ...
- .NET笔试面试题
.NET 1.const和readonly的区别? 2.静态类和实例区别?什么时候使用? 3.接口和抽象类的区别?什么时候使用? 4.类和结构体的区别?什么时候使用? 5.文件操作 6.序列化 7.O ...
- MySQL日期数据类型、MySQL时间类型使用总结
MySQL:MySQL日期数据类型.MySQL时间类型使用总结 MySQL 日期类型:日期格式.所占存储空间.日期范围 比较. 日期类型 存储空间 日期格式 日期范围 ------------ --- ...
- 各种工具使用手册:http://www.itshouce.com.cn/linux/linux-tcpdump.html 关于tcpdump!!!!
各种工具使用手册:http://www.itshouce.com.cn/linux/linux-tcpdump.html 关于tcpdump!!!! 实用tcpdump命令 //查看本机与mysql的 ...
- MD5 Message Digest Algorithm MD5(中文名为消息摘要算法第五版)
MD5 编辑 Message Digest Algorithm MD5(中文名为消息摘要算法第五版)为计算机安全领域广泛使用的一种散列函数,用以提供消息的完整性保护.该算法的文件号为RFC 1321( ...
- php 开启curl,重启php-fpm服务
1,找到php.ini配置 find / -name 'php.ini' /usr/local/php/etc/php.ini 找到extension=php_curl.dll 把前面的分号去掉即可. ...
- Billboard(线段树)
Billboard Time Limit:8000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit St ...
- HttpWatch详解
一 概述: HttpWatch强大的网页数据分析工具.集成在Internet Explorer工具栏.包括网页摘要.Cookies管理.缓存管理.消息头发送/接受.字符查询.POST 数据和目录管理功 ...
- windows下的C/C++精确计时
由于我要测试线性筛法的速度,用上了C/C++精确计时.此时传统的clock()方法不够用了,我们需要另一种测量的办法,即CPUTicks/CPUFreq.如何实现呢? #include <win ...