Search for poj 1129

Source: Internet
Author: User
Channel allocation

Time limit:1000 MSMemory limit:10000 KB

64-bit integer Io format:% I64d, % i64uJava class name:Main

[Submit] [Status] [discuss]

Descriptionwhen a radio station is broadcasting over a very large area, repeaters are used to retransmit the signal so that every runner er has a strong signal. however, the channels used by each repeater must be carefully chosen so that nearby repeaters do not interfere with one another. this condition is satisfied if adjacent repeaters use different channels.

Since the radio frequency spectrum is a precious resource, the number of channels required by a given network of repeaters shoshould be minimized. you have to write a program that reads in a description of a repeater network and determines the minimum number of channels required. inputthe input consists of a number of maps of repeater networks. each map begins with a line containing the number of repeaters. this is between 1 and 26, and the repeaters are referred to by consecutive upper-case letters of the alphabet starting with. for example, ten repeaters wocould have the names a, B, c ,..., I and J. A network with zero repeaters indicates the end of input.

Following the number of repeaters is a list of adjacency relationships. Each line has the form:

A: bcdh

Which indicates that the repeaters B, C, D and H are adjacent to the repeater. the first line describes those adjacent to repeater A, the second those adjacent to B, and so on for all of the repeaters. if a repeater is not adjacent to any other, its line has the form

A:

The repeaters are listed in alphabetical order.

Note that the adjacency is a valid Ric relationship; if A is adjacent to B, then B is necessarily adjacent to. also, since the repeaters lie in a plane, the graph formed by connecting adjacent repeaters does not have any line segments that cross. outputfor each map (could t the final one with no repeaters), print a line containing the minumum number of channels needed so that no adjacent channels interfere. the sample output shows the format of this line. take care that channels is in the singular form when only one channel is required. sample Input
2A:B:4A:BCB:ACDC:ABDD:BC4A:BCDB:ACDC:ABDD:ABC0
Sample output
1 channel needed.3 channels needed.4 channels needed. 

# Include <iostream> # include <string. h> # include <stdio. h> using namespace STD;/* int N; // The contact relationship between N broadcast sites bool map [35] [35]; // int ans; /// number of broadcast sites required int color [35]; // dyeing bool isfind; */int n; bool isfind; int ans; int color [35]; bool map [35] [35]; // What is the difference between the two versions ?????????????????? Bool OK (int x, int c) // determine whether the color of adjacent nodes is the same {for (INT I = 0; I <n; I ++) {If (Map [x] [I] & C = color [I]) /// compare the ID node with each node X and the ID node with the same edge & Color {return false ;}return true ;} void DFS (int id, int total) /// the total number of colors used by the current dyeing node number {If (isfind) return; If (ID >=n) {isfind = true; return ;} for (INT I = 1; I <= total; I ++) {If (OK (ID, I) {color [ID] = I; /// specifies the color of the DFS (ID + 1, total) before the color meets the condition. // Add another color [ID] = 0; // backtracking} If (! Isfind) // The previous colors do not meet the requirements {ans ++; // Add some DFS (ID, total + 1 ); /// add color} int main () {char STR [35]; while (scanf ("% d", & N )! = EOF) {If (n = 0) break; memset (MAP, false, sizeof (MAP); memset (color, 0, sizeof (color )); for (INT I = 1; I <= N; I ++) {CIN> STR; int Len = strlen (STR); For (Int J = 2; j <= Len; j ++) {map [STR [0]-'a'] [STR [J]-'a'] = true ;;}} isfind = false; ans = 1; DFS (0, 1); If (ANS = 1) printf ("1 channel needed. \ n "); else printf (" % d channels needed. \ n ", ANS);} return 0 ;}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.