| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 812 人关注过本帖
标题:[求助]请教一个有趣的c语言题目
取消只看楼主 加入收藏
xinxin0201
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2007-5-18
收藏
 问题点数:0 回复次数:2 
[求助]请教一个有趣的c语言题目
是来是布置的作业 先是英文版 然后是我翻译的 请各位高手出手相助啊
Chapter 1: Introduction
1.1 Problem description
This project requires us to help Bill to design the electric wiring for his new house.
First of all Bill has fixed the positions of several electrical outlets on the walls. To neatly connect any pair of outlets, we should make sure that the wire is always imbedded in the walls or the floor, and is parallel to at least one side of the wall. Naturally we should minimize the total length of wire he must buy to have all the outlets connected.
By the way, do not forget that there is a door for every room. The wire must not cross the door.
Hint: The house is big for any possibility and the door could be anywhere and also can be a window. And the most import thing is that the wire can’t cross the door and the ceiling but can cross the wall and the floor. Another important thing is that the wire must parallel one of the axes ( x, y, z ).
1.2 Method to measure the performance
While given a test case, the tester can calculate the length between any two distinct adjacent outlets and then generate the minimize length by himself. And then check with the result of the program. If it matches the result, we can say that the program works well. Or if it is smaller then the result, we can say that the program do not work well.
Chapter 2: Algorithm specification
2.1 Representation of graphs
Since it’s very difficult for us to solve the problem in three-dimensional, we change the house into a two-dimensional one.
As the triples of the door and the triples of the culminations of the house are given, so it’s not difficult to project the wall and the door on the floor.
After that the outlets are all on the floor. It means that we now can solve the problem in two-dimensional environment. Then each outlet can seem to be a point in a graph and the length between two points can be calculated by their triples. After that we could build a graph by queue ADT or stack ADT or other.
2.2 Implement of Kruscal’s algorithm
After we have built a graph, we can just use the Kruscal’s algorithm to solve the problem.
Chapter 3 Project Structure
3.1 Overview
The project wants us to find a optimal way to design the electric wiring. To complete the task, we should read the coordinates of the outlets and find the shortest path between each two outlets. Then, our job is finding the Minimum spanning tree. So the tree is the optimal precept, the total value of the tree is the minimum length of wire.
The problem is that the path cannot cross the door! To solve it, we put the four walls into one plane, then, our job is simple enough for us to do. Generally speaking, we need to find three paths between each two outlets, from left, right and floor. Then we say the value of each edge between the two outlets is the shortest one of the three.
Implement Kruskal’s algorithm to find the minimum spanning tree.
3.2 The main program
3.2.1 Details of the main program
1. Use for loop to deal with each case until the fscanf return EOF, which is to say we have dealt with all cases.
2. The main function open two files used in the program (If the “output.txt” file does not exist the program will generate it).
3. For each case, the program will give us a number in the "output.txt", which is the nearest integer length of wire.
4. Our program will close the two file, free all memory we used and then exit at last.
3.2.2 Flow chart of the main program

Chapter 4 Testing results and analysis
We will find that all the test cases are specially designed for the limited conditions the cases are contained in the “input.txt” file.

No. Correct Answers: Answers From "P6.exe"(Before Debugging) Answers From "P6.exe"(After Debugging)
1
2
3
4
5
6
7
8
9
10
11
For each test case, I used a piece of the program to calculate the weight of each edge and sorting, then spanning the tree manually, to find out the answer is right or wrong.
From the table above, we can find that all the answers are correct except the 3rd group. The purpose of the 3rd case is to check what and how the program will do when the connection must around the door. It has proved that the algorithm in the program to solve the crossing problem has a small bug.
Then, the programmer checked his program and found that when the program judged the condition of crossing the door and calculated the weight of the wire had a very silly mistake. Finally, the program had given the right answer. (Look at the table above!)
(The test case was from an accident. I also wrote the project for fun, but my results did not marching the results of the programmer’s. Then I found that in the test case there was a point, which generated by a “rand ()” function, in the door area. But just the wrong test case clued me on that when the program judging whether the wire had crossed door and calculated the wire length, there must bring a problem. Both of us were wrong).
Function Test:
In this part, I had test the function of the program to find out whether it can reach the requirement of Chenyue JJ.
No. Function State
1 The file operation SUCCESS
2 The format of output CORRECT
3 Whether give the result YES
4 The path of the files CORRECT
5 The state of the program STRONG
All the tests had finished, the result has listed above. The state of the program is strong enough to be tested with an enormous data file, which will not be crash.
Chapter 5 Algorithm analysis
5.1 The time complexity and space complexity analysis
5.1.1 The time complexity analysis
5.1.2 The space complexity analysis
5.2 The comments from tester
The program works well. All a word the program is: PASS!!
Duty assignments
Tester:
Programmer:
Reporter:
搜索更多相关主题的帖子: c语言 Bill outlets walls 
2007-05-18 15:45
xinxin0201
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2007-5-18
收藏
得分:0 

以下是翻译
一 介绍
1.1问题描述
要求我们帮助BILL为他的新房子设计电子线路。
首先BILL在墙上弄了几个固定的电路插口,为了整齐美观地把各对电路插口连接好,电线要埋入墙内或者地板上,并且至少要与一面墙平行,同样自然尽量电线的总长最少。
另外,不要忘了每个房间都有一个门,而且电线不能从门里穿过。
提示:房子设计可以任意大,而门可以是任何地方,也可以有一个窗子。最重要的是电线不能从门或天花板上穿过,只能从墙面或者地板上经过,另外一个重要的事就是电线必须与(X,Y,Z)任一轴平行。
1.2测量检测方法
当给出一个测试案例,测试者能够自动的计算出相邻的接口的长度并自动给出最小值,然后测试程序的结果,如果符合要求程序给出程序正常运行,如果过小,就给出程序运行异常。
二 算法详述
2.1 图形表示
由于用三维表示法去解决问题很难,我们把房子转换成二维的。
门的坐标点和房子顶点的坐标已经给出,所以可以很容易的把墙和门在地板上表示出来。(As the triples of the door and the triples of the culminations of the house are given, so it’s not difficult to project the wall and the door on the floor.)
这样接口就全在地板上表示出来,这意味着我们可以在二维平面上解决这个问题,然后每个电路接口可以看成图表中的一个点,两个点间的长度也可以由坐标值算出,接下来我们通过对列或堆栈或者其它的方法来产生图表。(Then each outlet can seem to be a point in a graph and the length between two points can be calculated by their triples. After that we could build a graph by queue ADT or stack ADT or other.)
2.2 Kruscal算法实现
建立图后,就只要用Kruscal算法去解决问题。
三 程序结构
3.1 总述
要求我们找出一个设计布线最佳的方法,为了完成任务,我们必须读出所有接口的坐标,找出每二个接口间的最短路径,然后我们要找到生成的最小的树,所得到的这个树就是最理想的方案,树的总值就是线路的最小长度。
问题在于线路不能通过门,所以为了解决这个问题,把四面墙都表示在平面上,接下来的工作就轻松了,一般来说,我们只要找出每两个接口之间的三条路径,可以从左边,右边,或者是从地板通过。再找出这三条路径间的最短的那条。
Kruskal算法的实现就是通过找出这些最小的路径值再生成树。
3.2 主程序
3.2.1 主程序的细节
1用FOR LOOP循环去处理每一种情况,直到fscanf返回EOF,这就是说我们已经处理完了所有的情况
2这个MIAN函数打开这个这个程序中要用到的两个文件。(如果“output.txt” 没有程序会产生它

3在每种情况下,程序会在“output.txt”里 给我们最接近电线长的整数。
4我们的程序将关掉两个文件,释放内存,并最终退出。
3.2.2 主程序的流程图

四 测试结果及分析
我们会发现所有的测试状况都是为这些有限条件设计的,包含在“input.txt”里。
No. 正确答案: P6.exe答案(调试前) P6.exe答案(调试后)
1
2
3
4
5
6
7
8
9
10
11
每个测试状况,我都用一段程序计算边的长度并分类,其后手动生成树,并找出其结论对错。
上面的表格中,除了第三组的值,另外的全是正确的,第三组主要是为检测当线路绕过门时程序到底做什么.这证明程序中处理线路穿越门的算法有漏洞。
然后程序员检查程序并发现当程序判断线路穿越门时有一个愚蠢错误,最后改正并得出正确的结果(看上面的表格)
(这个测试方案是意外发现,我出于兴趣写了这个程序,但是我的结果并没有和程序员的相符。然后我发现在这个方案中有一个点,是在门那部分一个rand()函数产生的。但是就是因为这个错误的测试案例让我知道程序在判断线路穿越门并计算长度时,一定要出现问题。我们都错了。)
函数测试:
这部分中,我通过测试程序的函数来找出结果是否达到表Chenyue JJ要求

No. 函数 状态
1 文件操作 成功
2 输出格式 正确
3 是否得到结果 是
4 文件路径 正确
5 程序状态 健壮
五 算法分析5
5.1时间和空间复杂度分析
5.1.1时间复杂度分析
5.1.2空间复杂度分析
5.2注释
程序应能够正常良好的运行,一句话:程序通过
任务分配:测试者
程序员
报告员


2007-05-18 15:46
xinxin0201
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2007-5-18
收藏
得分:0 
勉勉强强翻译了下。。
偶是编程菜鸟,对这此题无从下手。。
2007-05-18 17:10
快速回复:[求助]请教一个有趣的c语言题目
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.027102 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved