poj 3660 Cow Contest (bitset+floyd传递闭包)
解题思路
考试题,想到传递闭包了,写了个O(n^3)的,T了7个点。。。后来看题解是tm的bitset优化???以前好像没听过诶(我太菜了),其实也不难,时间复杂度O(n^3/32)
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<bitset> using namespace std;
const int MAXN = ; inline int rd(){
int x=,f=;char ch=getchar();
while(!isdigit(ch)) {f=ch=='-'?:;ch=getchar();}
while(isdigit(ch)) {x=(x<<)+(x<<)+ch-'';ch=getchar();}
return f?x:-x;
} int n,m,ans;
bitset<MAXN> a[MAXN]; int main(){
// freopen("rank.in","r",stdin);
// freopen("rank.out","w",stdout);
n=rd(),m=rd();int x,y;
while(m--){
x=rd(),y=rd();
a[x][y]=;
}
for(int k=;k<=n;k++)
for(register int i=;i<=n;i++)
if(a[i][k]) a[i]|=a[k];
for(int i=;i<=n;i++){
bool flag=;
for(register int j=;j<=n;j++) if(i!=j)
if(!a[i][j] && !a[j][i]) {flag=;break;}
if(flag) ans++;
}
printf("%d",ans);
return ;
}
poj 3660 Cow Contest (bitset+floyd传递闭包)的更多相关文章
- POJ 3660—— Cow Contest——————【Floyd传递闭包】
Cow Contest Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit ...
- POJ 3660 Cow Contest【Floyd 传递闭包】
传送门:http://poj.org/problem?id=3660 题意:有n头牛, 给你m对关系.(a, b)表示牛a能打败牛b, 求在给出的这些关系下, 能确定多少头牛的排名. 传递闭包: 关系 ...
- POJ 3660 Cow Contest(Floyd求传递闭包(可达矩阵))
Cow Contest Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16341 Accepted: 9146 Desc ...
- POJ 3660 Cow Contest (floyd求联通关系)
Cow Contest 题目链接: http://acm.hust.edu.cn/vjudge/contest/122685#problem/H Description N (1 ≤ N ≤ 100) ...
- POJ 3660 Cow ContestCow(Floyd传递闭包)题解
题意:给出m个关系,问你能确定机头牛的排名 思路:要确定排名那必须要把他和其他n-1头牛比过才行,所以Floyd传递闭包,如果赢的+输的有n-1就能确定排名. 代码: #include<cstd ...
- POJ 3660 Cow Contest【floyd】
题目链接: http://poj.org/problem?id=3660 题目大意: 给出n头牛,m个关系,关系为a的战力比b高.求最后可以确定排名的牛的数量 思路: 1.如果一头牛跟其他所有牛都确定 ...
- POJ 3660 Cow Contest (Floyd)
http://poj.org/problem?id=3660 题目大意:n头牛两两比赛经过m场比赛后能判断名次的有几头可转 化为路径问题,用Floyd将能够到达的路径标记为1,如果一个点能 够到达剩余 ...
- (中等) POJ 3660 Cow Contest,Floyd。
Description N (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a programming con ...
- POJ 3660 Cow Contest / HUST 1037 Cow Contest / HRBUST 1018 Cow Contest(图论,传递闭包)
POJ 3660 Cow Contest / HUST 1037 Cow Contest / HRBUST 1018 Cow Contest(图论,传递闭包) Description N (1 ≤ N ...
随机推荐
- jsp-提交表单乱码解决
jsp提交表单有两种方式,一种是get,一种是post,对于两种方式都可能出现乱码,以下给出两种乱码方式的解决方案. 1.post提交解决乱码 //设置解码方式,post提交解决乱码 比较简单 req ...
- 基于三角形与位置指纹识别算法的WiFi定位比较
文章来着:https://wenku.baidu.com/view/55d1f4146edb6f1aff001fec.html
- 15-MySQL-Ubuntu-数据表的查询-聚合函数(四)
聚合函数 (1)count() 统计总数 查询男性总数 select count(*) as 男性 from students where gender=1; (2)max() 最大值 查询男性中年龄 ...
- 【LGP5127】子异和
题目 子异和这个名字,真是思博 显然一个集合的子集异或和为,\(2^{|S|-1}\times A\),\(A\)为集合的或和 于是现在的问题变成了树链异或一个数,求树链或和 显然强行拆位是可以做的, ...
- Game of Taking Stones && POJ1259 /// 最大空凸包 几何+DP
题目大意: 给定n个点 求出这n个点中最大空凸包的面积 只放个模板 一份模板过两题(滑稽 这个讲解够详细了 https://blog.csdn.net/nyroro/article/details/4 ...
- Spring MVC @RequestMapping注解详解(2)
@RequestMapping 参数说明 value:定义处理方法的请求的 URL 地址.(重点) method:定义处理方法的 http method 类型,如 GET.POST 等.(重点) pa ...
- springboot整合thymeleaf手动渲染
Thymeleaf手动渲染 为提高页面访问速度,可缓存html页面,客户端请求从缓存获取,获取不到再手动渲染 在spring4下 @Autowired ThymeleafViewResolver th ...
- 关于__init__.py
假设程序目录结构如下: ├── checkpoints/ ├── data/ │ ├── __init__.py │ ├── dataset.py │ └── get_data.sh ├── mode ...
- 002-Java数据类型
Java数据类型 基本数据类型 和 引用数据类型 基本数据类型 整型:byte - 8bit / short - 2字节 / int - 4字节 / long - 8字节 浮点型:float doub ...
- HTML_页面注册案例
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...