Codeforces Gym 100342J Problem J. Triatrip 三元环
题目链接:
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 三元环的更多相关文章
- 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 bitset 求三元环的数量
Problem J. TriatripTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/att ...
- 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 ...
- Codeforces Gym 100002 Problem F "Folding" 区间DP
Problem F "Folding" Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/ ...
- Codeforces Gym 100342H Problem H. Hard Test 构造题,卡迪杰斯特拉
Problem H. Hard TestTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/at ...
- Codeforces Gym 100342D Problem D. Dinner Problem Dp+高精度
Problem D. Dinner ProblemTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/1003 ...
- Codeforces Gym 100500F Problem F. Door Lock 二分
Problem F. Door LockTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100500/at ...
随机推荐
- DOS 批处理 修改xml文件
之前对批处理和dos只停留在cd ping ipconfig水平,我以为改个文件应该很简单吧,把文件读出来做个替换再写回去不就欧了,百度个例子改改,那还不是分分钟的事,哪知道事实比想的要复杂的多. 我 ...
- Objective-C设计模式——工厂方法模式virtual constructor(对象创建)
工厂方法模式 工厂方法模式可以控制对象的创建过程,屏蔽对象创建的细节,可以直接创建出我们所需要的已经配置好的对象. 工厂方法模式定义了创建方法的接口,让子类决定实例化哪一个类,工厂方法模式使得一个类的 ...
- 兼容IE,chrome 等所有浏览器 回到顶部代码
今天在博客园看到一片帖子回到顶部代码,索性就看了下,但是发现在非IE浏览器下可以运行,在IE浏览器下却运行不了. 故将其代码搬弄过来做了些许修改后,完美支持了IE下的运行. 主要实现功能代码文件: & ...
- 怎样把function中的arguments变成普通数组
当我们在写一个具有处理可变长度参数的函数时,需要对arguments做一些操作.但是arguments它并不是一个数组,没有数组的各种操作,而且,JS的严格模式中不允许更改它的值. 这时我们需要将它的 ...
- 11.find 查找并复制文件
请把系统上拥有者为ira用户的所有文件,并将其拷贝到/root/findfiles目录中 find /home/ira/ -user ira -exec cp -a {} /root/findfile ...
- c++11:function的用法
function是函数.函数对象.函数指针.和成员函数的包装器,可以容纳任何类型的函数对象,函数指针,引用函数,成员函数的指针 普通函数 #include <functional> voi ...
- .NET研发人员面试题(二)
1.当使用new BB()创建BB的实例时,产生什么输出? public class AA { public AA() { PrintFields(); } public virtual void P ...
- WordPress 主题开发 - (二) 理解主题 待翻译
What is “Theme Sense”? What is “Theme Sense”? Theme Sense is an intuitive understanding of WordPress ...
- CSS content内容生成技术以及应用
content属性早在CSS2.1的时候就被引入了,可以使用:before以及:after伪元素生成内容.此特性目前已被大部分的浏览器支持:(Firefox 1.5+, Safari 3.5+, IE ...
- Optimize date2str function
/*************************************************** Created Date: 19 Jul 2013 Created By: Jimmy Xie ...