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 ...
随机推荐
- ubuntu安装 ibus-google输入法
1.$sudo apt-get install ibus-googlepinyin //ibus 融合了许多种输入法,google便是一种,此步就是下载安装ibus-google拼音输入法. ...
- 1 对WinMain的理解
就像C语言的main是它的程序路口一样,windows的程序入口是WinMain,WinMain的定义可以查看winbase.h文件. Hello Windows(c语言中的Hello world!) ...
- Cocos2d-x场景生命周期函数介绍
层(Layer)的生命周期函数有如下: init().初始化层调用. onEnter().进入层时候调用. onEnterTransitionDidFinish().进入层而且过渡动画结束时候调用. ...
- 【学习笔记】【C语言】常量
1. 什么是常量 常量,表示一些固定的数据 2. 常量的分类 1> 整型常量(int) 包括了所有的整数,比如6.27.109.256.-10.0.-289等 2> 浮点型常量(float ...
- 后台获取ajax发送过来的值
user.CityId = int.Parse(HttpContext.Request[ "bindArea"]); 以上为获取方法:
- 10款很好用的 jQuery 图片滚动插件
jQuery 作为最流行的 JavaScript 框架,使用简单灵活,同时还有许多优秀的插件可供使用.其中最令人印象深刻的应用之一就是各种很酷的图片效果,它可以让的网站更具吸引力.这里收集了10款很好 ...
- OpenGL第8,9讲小结
这两节,透明度和物体的3D运动,主要集中在第9讲,因为第9讲也用到了通过Alpha值来调整透明度的地方. 因为要模拟星星,所以要创建的四边形需要很多,例子中创建了50个正方形.因为每个星星的属性都差不 ...
- 简明Python中的一个小错误
最近在学Python,先看的是<Python基础教程>,后来经别人推荐,感觉网络上的<简明Python教程>也挺好的,在里面发现一个小错误. 网址如下:http://sebug ...
- 《DNS的正向反向解析》RHEL6
DNS的正向解析: Iptables –F Setenforce 0 安装DNS服务器的软件包: 启动DNS服务器: 修改DNS的配置文件:vim /etc/named.conf 修改DNS的配置:( ...
- 【Qt】Qt之自定义界面(添加自定义标题栏)【转】
简述 通过上节内容,我们实现了自定义窗体的移动,但是我们缺少一个标题栏来显示窗体的图标.标题,以及控制窗体最小化.最大化.关闭的按钮. 自定义标题栏后,所有的控件我们都可以定制,比如:在标题栏中添加换 ...