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 ...
随机推荐
- Apache Solr 远程命令+XXE执行漏洞(CVE-2017-12629)
Apache Solr 最近有出了个漏洞预警,先复习一下之前的漏洞 命令执行 先创建一个listener,其中设置exe的值为我们想执行的命令,args的值是命令参数 POST /solr/demo/ ...
- python array基本操作一
一.排序 a = [2,3,4,1] b = np.argsort(a) # out:[3 0 1 2] # 输出:是一个数组,是按元素递增顺序的索引 二.查找 1.最大值及其索引 b = max(a ...
- Linux下core文件调试
1,ulimit -a查看默认参数 2,ulimit -c 1024 设置core文件大小,如果超过1024个blocks,则不会产生core文件 注:tune2fs -l /dev/sda8 输出分 ...
- LightOJ 1341 - Aladdin and the Flying Carpet
题目链接:http://lightoj.com/volume_showproblem.php?problem=1341 题意:给你地毯面积和最小可能边的长度,让你求有几种组合的可能. 题解:这题就厉害 ...
- shell对比两个目录中有哪些文件不同
参考:https://www.cnblogs.com/liyuchuan/p/10756066.html 目录结构: /data/dir1 subdir/ subfile /data/dir2 sub ...
- 【转】详解tomcat的连接数与线程池
对tomcat线程池.Connector的BIO.NIO解析的很透彻的一篇文章. 原文链接:https://www.cnblogs.com/kismetv/p/7806063.html 前言 在使用t ...
- Flutter 集成到现有iOS工程
前沿 由于我司已经有自己的App,flutter属于技术引进的一部分,也不太可能重新启动一个项目,因此目前我们是将flutter模块形式注入我们的App之中.即:将flutter模块集成到现在有iOS ...
- c++隐藏运行exe黑窗口
加入main方法隐藏窗口 HWND hwndDOS = GetForegroundWindow(); ShowWindow(hwndDOS, SW_HIDE);
- 读取数据库的数据并转换成List<>
一.在有帮助类DbHelperSQL的时候 1.下为其中返回SqlDataReader的方法 /// <summary> /// 执行查询语句,返回SqlDataReader ( 注意:调 ...
- Qt Creator配置
1.安装Git sudo apt install git 2.配置Git 用户和邮箱: git config --global user.name "xxx" git config ...