| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
大牛们帮我看看哪错了?贪心#include <iostream>
#include <string.h>
using namespace std;
int color[26][26];
int numcol[26];
int used[26];
int n;
int acc;
int max()
{
int max = 0;
int tmp = 0;
for (int i = 1; i <= n; i++)
{
if(numcol[i] > max && !used[i])
{
max = numcol[i];
tmp = i;
}
}
return tmp;
}
void bfs(int k)
{
if(!k)
return ;
used[k] = 1;
for (int i = 1; i <= n; i++)
{
if(!used[i] && color[k][i] == 0)
{
used[i] = 1;
}
}
acc++;
bfs(max());
}
int main()
{
bool conn;
char ch;
char str[26];
while(scanf("%d", &n) == 1 && n)
{
acc = 0;
memset(color, 0, sizeof(color));
memset(numcol, 0, sizeof(numcol));
memset(used, 0, sizeof(used));
for (int i = 1; i <= n; i++)
{
scanf("%s", str);
numcol[i] = strlen(str) - 2;
for (int j = 2; str[j]; j++)
{
int t = str[j] - 'A' + 1;
color[i][t] = 1;
color[t][i] = 1;
}
}
bfs(max());
if(!acc)
{
cout << "1 channel needed." << endl;
}
else
cout << acc << " channels needed." << endl;
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator