poj2419

简单题

View Code
#include <iostream>
#include
<cstdio>
#include
<cstdlib>
#include
<cstring>
#include
<algorithm>
using namespace std;

#define maxn 105

int f[maxn][maxn];
int num[maxn];
bool vis[maxn];
int p, t;

bool same(int a, int b)
{
if (num[a] != num[b])
return false;
for (int i = 0; i < num[a]; i++)
if (f[a][i] != f[b][i])
return false;
return true;
}

int main()
{
//freopen("t.txt", "r", stdin);
scanf("%d%d", &p, &t);
int a, b;
memset(num,
0, sizeof(num));
while (scanf("%d%d", &a, &b) != EOF)
f[a][num[a]
++] = b;
for (int i = 1; i <= p; i++)
{
sort(f[i], f[i]
+ num[i]);
num[i]
= unique(f[i], f[i] + num[i]) - f[i];
}
memset(vis,
0, sizeof(vis));
int ans = 0;
for (int i = 1; i <= p; i++)
if (!vis[i])
{
ans
++;
for (int j = i + 1; j <= p; j++)
if (!vis[j] && same(i, j))
vis[j]
= true;
vis[i]
= true;
}
printf(
"%d\n", ans);
return 0;
}
原文地址:https://www.cnblogs.com/rainydays/p/2135529.html