POJ3275 Ranking the Cows floyd的bitset优化
Posted wstong
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了POJ3275 Ranking the Cows floyd的bitset优化相关的知识,希望对你有一定的参考价值。
1 #include <iostream> 2 #include <cstdio> 3 #include <bitset> 4 using namespace std; 5 const int maxn = 1005; 6 int n, m; 7 bitset<maxn> maps[maxn]; 8 void floyd() { 9 for (int k = 1; k <= n; k++) { 10 for (int i = 1; i <= n; i++) { 11 if (maps[i][k]) maps[i] |= maps[k]; 12 } 13 } 14 } 15 int main() { 16 scanf("%d%d",&n,&m); 17 for (int i = 1; i <= m; i++) { 18 int u, v; scanf("%d%d",&u,&v); 19 maps[u][v] = true; 20 } 21 floyd(); 22 int ans = 0; 23 for (int i = 1; i <= n; i++) { 24 for (int j = i+1; j <= n; j++) { 25 if (!maps[i][j] && !maps[j][i]) ans++; 26 } 27 } 28 printf("%d ",ans); 29 return 0; 30 }
以上是关于POJ3275 Ranking the Cows floyd的bitset优化的主要内容,如果未能解决你的问题,请参考以下文章
POJ3275 [USACO07MAR]Ranking the Cows
POJ3275 Ranking the Cows floyd的bitset优化
POJ3275:Ranking the Cows(Bitset加速floyd求闭包传递)
USACO 2007 “March Gold” Ranking the Cows