zoukankan      html  css  js  c++  java
  • POJ 1129

    此题的本质问题就是对无向图的着色,使颜色使用最少的问题

    #include <stdio.h>
    #define maxn 27
    typedef struct Node
    {
    	int next[maxn];
    	int tot;
    }node;
    int main()
    {
    	int n;
    	while(scanf("%d",&n)&&n!=0)
    	{
    		getchar();//吸收回车
    		node map[maxn];
    		int i,j,k;
    		for(i=0;i<n;i++)//建图
    		{
    			map[i].tot=0;
    			getchar();//吸收每行的首字母,因为是字典序输入
    			getchar();//吸收冒号
    			char c;
    			while((c=getchar())!='\n')
    			{
    				int t=c-'A';
    				map[i].next[map[i].tot++]=t;
    			}
    		}
    		int color[maxn]={0};//每个节点的颜色
    		int mc=1;//所用颜色总数
    		for(i=0;i<n;i++)//对图的节点进行染色
    		{
    			int visit[maxn]={0};//标记邻节点的颜色
    			for(j=0;j<map[i].tot;j++)
    			{
    				if(color[j])
    					visit[color[j]]=1;
    			}
    			for(k=1;k<maxn;k++)
    			{
    				if(!visit[k])
    				{
    					color[i]=k;
    					break;
    				}
    			}
    			if(color[i]>mc)
    				mc=color[i];
    		}
    		if(mc==1)
    			printf("1 channel needed.\n");
    		else
    			printf("%d channels needed.\n",mc);
    	}
    	return 0;
    }
    


     

  • 相关阅读:
    第33周二
    第33周一
    第32周日
    第32周六
    RichTextBox 右键显示 ContextMenuTrip
    关于 Head First SQL 中文版
    linux进程通信之共享内存
    chroot 与 jail
    SQL基础--&gt; 约束(CONSTRAINT)
    MessageDigest简单介绍
  • 原文地址:https://www.cnblogs.com/lj030/p/3002321.html
Copyright © 2011-2022 走看看