转自 海岛Blog
转这篇文章主要是对19行的代码有点不明白,因为本人调试的代码,bitset不赋初值则位上的数都为0, 但是,把该段删除后WA,不明白。
/* POJ2943 UVALive3524 The Cow Doctor */
#include <iostream>
#include <bitset>
#include <math.h>
using namespace std;
int const N = 300;
bitset<N + 1> a[N + 1], b[N + 1];
int main()
{
ios::sync_with_stdio(false);
int n, m, k, v;
while(cin >> n >> m && (n || m)) {
for(int i = 0; i < m; i++)
a[i] = 0, b[i] = 0;
for(int i = 0; i < m; i++) {
cin >> k;
while(k--) {
cin >> v;
a[i].set(v);
}
for(int j = 0; j < i; j++)
if((a[i] & a[j]) == a[i])
b[j] |= a[i];
else if((a[i] & a[j]) == a[j])
b[i] |= a[j];
}
int cnt = 0;
for(int i = 0; i < m; i++)
if(a[i] == b[i])
cnt++;
cout << cnt << endl;
}
return 0;
}
以下为本人调试的代码
#include <iostream>
#include <bitset>
#include <math.h>
using namespace std;
int const N = 300;
bitset<N + 1> a[N + 1], b[N + 1];
int main()
{
ios::sync_with_stdio(false);
for(int i = 0; i < 200; i++)
cout << a[i] << " " << b[i] << endl, a[i] = 0, b[i] = 0;
cout << endl << endl << endl;
for(int i = 0; i < 200; i++)
cout << a[i] << " " << b[i] << endl;
return 0;
}
结果是一样的,so,这个 晕