N - Channel Allocation

N - Channel Allocation
Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I64u

Description

When a radio station is broadcasting over a very large area, repeaters are used to retransmit the signal so that every receiver 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 should be minimised. You have to write a program that reads in a description of a repeater network and determines the minimum number of channels required.

Input

The 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 A. For example, ten repeaters would 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 A. 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 symmetric relationship; if A is adjacent to B, then B is necessarily adjacent to A. Also, since the repeaters lie in a plane, the graph formed by connecting adjacent repeaters does not have any line segments that cross. 

Output

For each map (except 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

2
A:
B:
4
A:BC
B:ACD
C:ABD
D:BC
4
A:BCD
B:ACD
C:ABD
D:ABC
0

Sample Output

1 channel needed.
3 channels needed.
4 channels needed. 

#include <stdio.h> #include <stdlib.h> #pragma pack(push, 1) typedef struct { unsigned short bfType; unsigned int bfSize; unsigned short bfReserved1; unsigned short bfReserved2; unsigned int bfOffBits; } BITMAPFILEHEADER; typedef struct { unsigned int biSize; unsigned int biWidth; unsigned int biHeight; unsigned short biPlanes; unsigned short biBitCount; unsigned int biCompression; unsigned int biSizeImage; unsigned int biXPelsPerMeter; unsigned int biYPelsPerMeter; unsigned int biClrUsed; unsigned int biClrImportant; } BITMAPINFOHEADER; #pragma pack(pop) // C6000兼容的周期计数函数 unsigned long long get_cycle_count() { unsigned int tsch, tscl; asm(" mvc .s2 TSCH, %0" : "=r"(tsch)); asm(" mvc .s2 TSCL, %0" : "=r"(tscl)); return ((unsigned long long)tsch << 32) | tscl; } int main(void) { const int width = 768, height = 576; const int sizeImage = width * height * 3; const int iterations = 1000; const char *src1_path = "HazyDay1.bmp"; const char *src2_path = "HazyDay2.bmp"; const char *dst_path = "jieguo.bmp"; printf("Starting image processing on C6000 DSP...\n"); printf("Image size: %dx%d, Iterations: %d\n", width, height, iterations); FILE *src1 = fopen(src1_path, "rb"); FILE *src2 = fopen(src2_path, "rb"); FILE *dst = fopen(dst_path, "wb"); if (!src1 || !src2 || !dst) { printf("Error opening files\n"); if (src1) fclose(src1); if (src2) fclose(src2); if (dst) fclose(dst); return -1; } BITMAPFILEHEADER fileHeader; BITMAPINFOHEADER infoHeader; if (fread(&fileHeader, sizeof(BITMAPFILEHEADER), 1, src1) != 1 || fread(&infoHeader, sizeof(BITMAPINFOHEADER), 1, src1) != 1) { printf("Error reading BMP headers\n"); fclose(src1); fclose(src2); fclose(dst); return -1; } unsigned char *img1 = (unsigned char *)malloc(sizeImage); unsigned char *img2 = (unsigned char *)malloc(sizeImage); unsigned char *result = (unsigned char *)malloc(sizeImage); if (!img1 || !img2 || !result) { printf("Memory allocation failed\n"); free(img1); free(img2); free(result); fclose(src1); fclose(src2); fclose(dst); return -1; } fseek(src1, fileHeader.bfOffBits, SEEK_SET); fseek(src2, fileHeader.bfOffBits, SEEK_SET); fread(img1, 1, sizeImage, src1); fread(img2, 1, sizeImage, src2); unsigned long long start_cycles, end_cycles; double total_time_3ch = 0, total_time_1ch = 0; int i, iter; // ================= 三通道同时处理 ================= printf("Running 3-channel method...\n"); start_cycles = get_cycle_count(); for (iter = 0; iter < iterations; iter++) { unsigned char *p1 = img1; unsigned char *p2 = img2; unsigned char *res = result; for (i = 0; i < sizeImage; i++) { *res++ = (*p1++ + *p2++) >> 1; } } end_cycles = get_cycle_count(); total_time_3ch = (double)(end_cycles - start_cycles); // ================= 单通道分别处理 ================= printf("Running 1-channel method...\n"); start_cycles = get_cycle_count(); for (iter = 0; iter < iterations; iter++) { for (i = 0; i < sizeImage; i += 3) { result[i] = (img1[i] + img2[i]) >> 1; result[i+1] = (img1[i+1] + img2[i+1]) >> 1; result[i+2] = (img1[i+2] + img2[i+2]) >> 1; } } end_cycles = get_cycle_count(); total_time_1ch = (double)(end_cycles - start_cycles); // 输出结果 printf("\nProcessing Time Comparison (after %d iterations):\n", iterations); printf("3-Channel Method:\n"); printf(" Total cycles: %.0f\n", total_time_3ch); printf(" Average cycles: %.0f\n", total_time_3ch/iterations); printf("1-Channel Method:\n"); printf(" Total cycles: %.0f\n", total_time_1ch); printf(" Average cycles: %.0f\n", total_time_1ch/iterations); if (total_time_1ch > 0 && total_time_3ch > 0) { double improvement = (total_time_1ch - total_time_3ch) / total_time_1ch * 100; printf("Efficiency Improvement: %.2f%% (%s method is faster)\n", fabs(improvement), improvement > 0 ? "3-channel" : "1-channel"); } // 写入结果 fwrite(&fileHeader, sizeof(BITMAPFILEHEADER), 1, dst); fwrite(&infoHeader, sizeof(BITMAPINFOHEADER), 1, dst); fseek(dst, fileHeader.bfOffBits, SEEK_SET); fwrite(result, 1, sizeImage, dst); // 释放资源 free(img1); free(img2); free(result); fclose(src1); fclose(src2); fclose(dst); return 0; } 为什么有下面的报错 **** Build of configuration Debug for project lab_03_app **** "G:\\ccs\\CCS5.5.0.00077_win32\\ccsv5\\utils\\bin\\gmake" -k all 'Building file: ../main.c' 'Invoking: C6000 Compiler' "G:/ccs/CCS5.5.0.00077_win32/ccsv5/tools/compiler/c6000_7.4.4/bin/cl6x" -mv6740 --abi=coffabi -g --include_path="G:/ccs/CCS5.5.0.00077_win32/ccsv5/tools/compiler/c6000_7.4.4/include" --display_error_number --diag_warning=225 --diag_wrap=off --preproc_with_compile --preproc_dependency="main.pp" "../main.c" "../main.c", line 31: error #18: expected a ")" "../main.c", line 32: error #18: expected a ")" "../main.c", line 33: warning #551-D: variable "tsch" is used before its value is set "../main.c", line 33: warning #551-D: variable "tscl" is used before its value is set 2 errors detected in the compilation of "../main.c". >> Compilation failure gmake: *** [main.obj] Error 1 gmake: Target `all' not remade because of errors. **** Build Finished ****
最新发布
06-06
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值