UVa 140 带宽 Bandwidth

暴力题目

注意一下细节应该还是很好ac的;

因为题目太多图片和字了,我就决定不排版了。


Given a graph (V, E) where V is a set of nodes and E is a set of arcs inV ×V , and an ordering on the elements in V , then the bandwidth of anode v is defined as the maximum distance in the ordering between vand any node to which it is connected in the graph. The bandwidthof the ordering is then defined as the maximum of the individualbandwidths. For example, consider the graph on the right:

For these orderings, the bandwidths of the nodes (in order) are 6, 6, 1, 4, 1, 1, 6, 6 giving an orderingbandwidth of 6, and 5, 3, 1, 4, 3, 5, 1, 4 giving an ordering bandwidth of 5.Write a program that will find the ordering of a graph that minimises the bandwidth.

InputInput

 will consist of a series of graphs. Each graph will appear on a line by itself. The entire file willbe terminated by a line consisting of a single ‘#’. For each graph, the input will consist of a series ofrecords separated by ‘;’. Each record will consist of a node name (a single upper case character in thethe range ‘A’ to ‘Z’), followed by a ‘:’ and at least one of its neighbours. The graph will contain nomore than 8 nodes.

Output

Output will consist of one line for each graph, listing the ordering of the nodes followed by an arrow(->) and the bandwidth for that ordering. All items must be separated from their neighbours byexactly one space. If more than one ordering produces the same bandwidth, then choose the smallestin lexicographic ordering, that is the one that would appear first in an alphabetic listing.

Sample Input

A:FB;B:GC;D:GC;F:AGH;E:HD#

Sample Output

A B C F G D H E -> 3


写的时候因为思路换过一次,有些之前思路用到的定义也还没有来得及删,大家就凑活着看吧

include 
#include 
#include 
#include 
#include 
using namespace std;
int main()
{
    //freopen("out.txt","w",stdout);
    char s[100];
    while(~scanf("%s",s))
    {
        if(s[0]=='#')break;
        mapp;                  
        int k=0,jl[10],ans[10]={0};   //ans就答案
        int lj[27][27]={0};           //表示两个字母是否链接的标记数组,虽然节点只有不到10个,可是这里必须定义27满足26个字母,我之前就是这里定义少了,狂错。
        int len=strlen(s);

        for(int i=0;id) d=z;
                    if(d>minn){f=1;break;}
                }
                if(f==1)break;                        //用f来判断是否要剪枝,来减小重复多余的循环

            }
            if(f==1)continue;
            if(d %d\n",minn);

        memset(s,0,sizeof(s));

    }
    return 0;
}


你可能感兴趣的:(暴力,uva,acm)