计组answer08
2008noip普及组复赛--排座位--代码C++
2.排座椅(seat.pas/c/cpp)【问题描述】上课的时候总有一些同学和前后左右的人交头接耳,这是令小学班主任十分头疼的一件事情。
不过,班主任小雪发现了一些有趣的现象,当同学们的座次确定下来之后,只有有限的D对同学上课时会交头接耳。
同学们在教室中坐成了M行N列,坐在第i行第j列的同学的位置是(i,j),为了方便同学们进出,在教室中设置了K条横向的通道,L条纵向的通道。
于是,聪明的小雪想到了一个办法,或许可以减少上课时学生交头接耳的问题:她打算重新摆放桌椅,改变同学们桌椅间通道的位置,因为如果一条通道隔开了两个会交头接耳的同学,那么他们就不会交头接耳了。
请你帮忙给小雪编写一个程序,给出最好的通道划分方案。
在该方案下,上课时交头接耳的学生对数最少。
【输入】输入文件seat.in的第一行,有5各用空格隔开的整数,分别是M,N,K,L,D(2<=N,M<=1000,0<=K<M,0<=L<N,D<=2000)。
接下来D行,每行有4个用空格隔开的整数,第i行的4个整数X i,Y i,P i,Q i,表示坐在位置(X i,Y i)与(P i,Q i)的两个同学会交头接耳(输入保证他们前后相邻或者左右相邻)。
输入数据保证最优方案的唯一性。
【输出】输出文件seat.out共两行。
第一行包含K个整数,a1a2……a K,表示第a1行和a1+1行之间、第a2行和第a2+1行之间、…、第a K行和第a K+1行之间要开辟通道,其中a i< a i+1,每两个整数之间用空格隔开(行尾没有空格)。
第二行包含L个整数,b1b2……b k,表示第b1列和b1+1列之间、第b2列和第b2+1列之间、…、第b L列和第b L+1列之间要开辟通道,其中b i< b i+1,每两个整数之间用空格隔开(行尾没有空格)。
【输入输出样例解释】1 2 3 4 5上图中用符号*、※、+ 标出了3对会交头接耳的学生的位置,图中3条粗线的位置表示通道,图示的通道划分方案是唯一的最佳方案。
1995-2008 历届NOIP试题及详解
例如:N=6 时,有:
A=(4,3,0,5,1,2)
此时,数组 A 的编码定义如下:
A[0]的编码为 0;
A[i]的编码为:在 A[0],A[1],…,A[i-1]中比 A[i]的值小的个数(i=1,2,…,N-1)
∴ 上面数组 A 的编码为: B=(0,0,0,3,1,2)
程序要求解决以下问题:
③ 给出数组 A 后,求出其编码。 ④ 给出数组 A 的编码后,求出 A 中的原数据。 <2> 灯的排列问题: 设在一排上有 N 个格子(N≤20),若在格子中放置有不同颜色的灯,每种灯的个数记为 N1,N2,……Nk(k 表示不同颜色灯的个数)。 放灯时要遵守下列规则:
b 输入:N=10 B=(0,1,2,3,4,5,6,7,8,9)
输出编码: A=(0,1,2,3,4,5,6,7,8,9)
c 输入:N=7 B=(0,0,0,0,4,5,6)
输出编码: A=(3,2,1,0,4,5,6)
<7> 本题共 30 分(10%+10%+10%)
④ 数据输入: N=6
P1=R
Y
RRR
BB
Y
RRR
BB
Y
RRR
BB
Y
RRR
BB
Y
RRR
BB
Y
RRR
BB
Y
RRR
BB
Y
NOI’95 “同创杯”全国青少年信息学(计算机)奥林匹克竞赛
分区联赛复赛试题(高中组)
(上机编程,完成时间:210 分钟)
<1> 编码问题:
设有一个数组 A:ARRAY[0..N-1] OF INTEGER;
数组中存放的元素为 0~N-1 之间的整数,且 A[i]≠A[j](当 i≠j 时)。
SCAR 回复 8D 编写作业规范
建立SCAR 回复8D 之制作与文件管制作业规范。
凡处理XXX 客户抱怨者皆可利用8D 之制作方式,回复客户。
3-1. 客户抱怨处理作业规范8D :8 Disciplines, 八项项目,为intel 所定义回复抱怨的普通格式。
SCAR:Supplier Corrective Action Request,供货商改善对策要求,为intel 对供货商要求改善之正式文件。
如下图所示。
客戶結案客戶抱怨客戶抱怨處理回覆8D8D 歸檔(藍圖室)6-1. 8D 格式制作说明:8D 格式计有八个部份,范例如附件二所示。
其中若是客户有开SCAR(Supplier corrective action request)文件者,对于处理上有时效的限制,如防堵计划须于收到起24 小时内处理完毕,整个异常处理须于1 周内完成(有关Intel SCAR 写作指引详细请参考附件三)。
对于普通未开SCAR 之客户抱怨,处理时在线相同,若同时发生时,则需评估严重性,依照优先级排序进行处理。
以下针对每一个部份进行说明。
6-1-1 Team Approach成立问题解决团队,解决该问题。
其成员为来自与该问题有相关之领域或者问题之发生单位的专家或者业务执行单位。
并由理级以上之人员担任Owner。
6-1-2 Problem Description问题描述:问题描述需基于客户所开的SCAR 及遭剔退的缺点板加以分析,将问题发生的时间、发生问题的内容如Failure Mode 为何?影响的广度与深度为何?受影响的料号、批号为何?发生客户是谁?缺点率等相关问题陈述的内容加以说明,明确说明真正的问题。
6-2-3 Analysis & Finding分析与发现:分析相关的异常信息,确认缺点或者问题的形成过程,进行问题的澄清与验证。
确认问题所影响的制程范围,如回溯问题批号之生产纪录,关参数数据如管制图有无异常,L/A 检验资料有无异常。
6-2-4 Containment Action防堵行动计划:防堵计划应列出防堵对策结果有效的时间点,保证异常物料发生的期间内所有的物料皆已纳入并回溯确认该异常物料,以区隔正常与异常的物料。
IT系统分析员考题 v1-answer
[繁体字转换简体方法]打开文档---菜单栏---审阅---繁转简---转换完成IT系統分析員、軟體開發員考題題庫(V1.0)說明:選題個數可在9~11個間,答題時間80分鐘~120分鐘。
一、基礎IT技術部分(每題8~10分)說明:1、2、3、4、5、14必選,6~13可選2或不選1、某集團下屬單位共800名員工,分佈在15個部門,要設計一個含部門、姓名、崗位、年齡、工資、部門領導6項內容的人員資料庫系統,請用ER圖作一數據規劃。
Answer: ER圖如下:2、請編一帶迴圈條件的程式,可分部門遍曆上例中的每一條記錄。
Answer:Declare cursor cur_DepartmentSelect Deptcode from Department order by deptcodeFetch cur_Department into @DeptcodeWhile @@Fetch_status= 0BeginSelect ‘部門’, ‘姓名’, A.Station ‘崗位’, A.Age ‘年齡’, A.Salary ‘工資’, (select staffname from staff where staff.staffcode = b.staffcode ) 部門領導from staff A, Department BWhere A.Deptcode = @Deptcode and A.Deptcode = B.DeptcodeFetch next cur_Department into @DeptcodeEndClose cursor cur_DepartmentDeallocate cursor cur_Department3、在編寫SQL語句時為了提高性能,與資料庫索引匹配時應注意哪些?舉例說明。
Answer:1. 匹配所有的索引2. 匹配盡可能多的主健3.高級(主)的表放在等式左邊,而低級(次)的表放在等式右邊。
计算机组成原理第8章习题指导
第8章CPU的结构和功能例8.1假设指令流水线分取指(IF)、译码(ID)、执行(EX)、回写(WR)四个过程段,共有10条指令连续输入此流水线。
(1)画出指令周期流程。
(2)画出非流水线时空图。
(3)画出流水线时空图。
(4)假设时钟周期为100ns,求流水线的实际吞吐率。
(5)求该流水处理器的加速比。
解:(1)根据指令周期包括IF、ID、EX、WR四个子过程,图8.1(a)为指令周期流程图。
(2)非流水线时空图如图8.1(b)所示。
假设一个时间单位为一个时钟周期,则每隔4个时钟周期才有一个输出结果。
(3)流水线时空图如图8.1(c)所示。
由图可见,第一条指令出结果需要4个时钟周期。
当流水线满载时,以后每一个时钟周期可以出一个结果,即执行完一条指令。
(a)指令周期流程(b) 非流水线时空图(c) 标准流水线时空图图8.1 例8.1答图(4)由图8.1(c)所示的10条指令进入流水线的时空图可见,在13个时钟周期结束时,CPU执行完10条指令,故实际吞吐率为:10/(100ns×13) ≈ 0.77×107条指令/秒(5)在流水处理器中,当任务饱满时,指令不断输入流水线,不论是几级流水线,每隔一个时钟周期都输出一个结果。
对于本题四级流水线而言,处理10条指令所需的时钟周期数为T4 = 4 +(10 −1)= 13。
而非流水线处理10条指令需4×10 = 40个时钟周期。
故该流水处理器的加速比为40 ÷13 ≈ 3.08 例8.2设某机有四个中断源1、2、3、4,其硬件排队优先次序按1→2→3→4降序排列,各中断源的服务程序中所对应的屏蔽字如表8.1所示。
表8.1 例8.2各中断源对应的屏蔽字中断源 屏蔽字1 2 3 41 1 1 0 12 0 1 0 03 1 1 1 14 0 1 0 1(1)给出上述四个中断源的中断处理次序。
(2)若四个中断源同时有中断请求,画出CPU执行程序的轨迹。
第7章习题答案 计算机组成原理课后答案(清华大学出版社 袁春风主编)
• 159 •
7. 假定以下 MIPS 指 令序列在图 7.18 所示 的流 水线数据通路中 执行:
addu $s3, $s1, $s0
subu $t2, $s0, $s3
流水线深度( Pipeline Depth) 流 水 线 冒 险 ( Hazar d) 控制冒险(Control hazard) 流水线阻塞( Pipeline stall) 空 操 作 ( nop) 分支预测(Branch predict) 动态分支预测(Dynamic predict) 分支 延迟槽(Delayed branch slot) 旁 路 ( Bypassing) IPC(Instructions Per Cycle) 动态多发射(Dynamic multiple issue) 超长指令字 VLIW 动态流水线(Dynamic pipelining) 指令分发(Instruction dispatch) 无序发射( out-of-order issue) 重排序缓冲(Reorder buffer) 乱序执行( out-of-order execution) 无序完成( out-of-order completion)
(1)插入 一个流水段寄 存器,得到 一个两级 流水线 (2)插 入两个流水段 寄存器,得 到一个三 级流水线 (3)插入 三个流水段寄 存器,得到 一个四级 流水线 (4)吞 吐量最大的流 水线 参考答案:
(1)两级流水线的平衡点在 C 和 D 之间,其前面一个流水段的组合逻辑延时为 80+30+60=170ps,后 面一 个流水 段的 组合逻 辑延时 为 50+70+10=130ps。这 样每个 流水段 都 以 最 长 延 时 调 整 为 170+20=190ps , 故 时 钟 周 期 为 190ps , 指 令 吞 吐 率 为 1/190ps=5.26GOPS,每条 指令的执行时 间为 2x190=380ps。
2008年acm全球总决赛试题
ACM International Collegiate Programming Contest2008East Central Regional ContestMcMaster UniversityUniversity of CincinnatiUniversity of Michigan–Ann ArborYoungstown State UniversityNovember1,2008Sponsored by IBMRules:Problem A:Bordering on MadnessBob Roberts owns a design business which creates custom artwork for various corporations.One technique that his company likes to use is to take a simple rectilinearfigure(afigure where all sides meet at90or270degrees and which contains no holes)and draw one or more rectilinear borders around them.Each of these borders is drawn so that it is a set distance d away from the previously drawn border(or the originalfigure if it is thefirst border)and then the new area outlined by each border is painted a unique color.Some examples are shown below(without the coloring of the borders).The example on the left shows a simple rectilinearfigure(grey)with two borders drawn around it.The one on the right is a more complicatedfigure;note that the border may become disconnected.These pieces of art can get quite large,so Bob would like a program which can draw prototypes of the finished pieces in order to judge how aesthetically pleasing they are(and how much money they will cost to build).To simplify things,Bob never starts with afigure that results in a border where2horizontal (or vertical)sections intersect,even at a point.This disallows such cases as those shown below:InputInput will consist of multiple test cases.Thefirst line of the inputfile will contain a single integer indicating the number of test cases.Each test case will consist of two or more lines.Thefirst will contain three positive integers n,m and d indicating the number of sides of the rectlinearfigure,the number of borders to draw,and the distance between each border,where n≤100and m≤20. The remaining lines will contain the n vertices of thefigure,each represented by two positive integers indicating the x and y coordinates.The vertices will be listed in clockwise order starting with the vertex with the largest y value and(among those vertices)the smallest x value.OutputFor each test case,output three lines:thefirst will list the case number(as shown in the examples), the second will contain m integers indicating the length of each border,and the third will contain m integers indicating the additional area contributed to the artwork by each border.Both of these sets of numbers should be listed in order,starting from the border nearest the originalfigure.Lines two and three should be indented two spaces and labeled as shown in the examples.Separate test cases with a blank line.Sample Input26210 2030100301000000102010 10172050705070000030 20302010601060402040 Sample OutputCase1:Perimeters:340420Areas:30003800Case2:Perimeters:380Areas:2660Problem B:Jack of All TradesJack Barter is a wheeler-dealer of the highest sort.He’ll trade anything for anything,as long as he gets a good deal.Recently,he wanted to trade some red agate marbles for some goldfish.Jack’s friend Amanda was willing to trade him1goldfish for2red agate marbles.But Jack did some more digging and found another friend Chuck who was willing to trade him5plastic shovels for3marbles while Amanda was willing to trade1goldfish for3plastic shovels.Jack realized that he could get a better deal going through Chuck(1.8marbles per goldfish)than by trading his marbles directly to Amanda (2marbles per goldfish).Jack revels in transactions like these,but he limits the number of other people involved in a chain of transactions to9(otherwise things can get a bit out of hand).Normally Jack would use a little program he wrote to do all the necessary calculations tofind the optimal deal,but he recently traded away his computer for afine set of ivory-handled toothpicks.So Jack needs your help.InputInput will consist of multiple test cases.Thefirst line of thefile will contain an integer n indicating the number of test cases in thefile.Each test case will start with a line containing two strings and a positive integer m≤50.Thefirst string denotes the items that Jack wants,and the second string identifies the items Jack is willing to trade.After this will be m lines of the forma1name1a2name2indicating that some friend of Jack’s is willing to trade an amount a1of item name1for an amount a2 of item name2.(Note this does not imply the friend is also willing to trade a2of item name2for a1of item name1.)The values of a1and a2will be positive and≤20.No person will ever need more than 231−1items to complete a successful trade.OutputFor each test case,output the phrase Case i:(where i is the case number starting at1)followed by the best possible ratio that Jack can obtain.Output the ratio using5significant digits,rounded.Follow this by a single space and then the number of ways that Jack could obtain this ratio.Sample Input2goldfish marbles31goldfish2marbles5shovels3marbles1goldfish3shovelsthis that47this2that14this4that7this2theother1theother1thatSample OutputCase1:1.80001Case2:0.285713Problem C:LCRLCR is a simple game for three or more players.Each player starts with three chips and the object is to be the last person to have any chips.Starting with Player1,each person rolls a set of three dice.Each die has six faces,one face with an L,one with a C,one with an R and three with a dot.For each L rolled,the player must pass a chip to the player on their left(Player2is considered to be to the left of Player1);for each R rolled,the player passes a chip to the player on their right;and for each C rolled, the player puts a chip in a central pile which belongs to no player.No action is taken for any dot that is rolled.Play continues until only one player has any chips left.In addition,the following rules apply:1.A player with no chips is not out of the game,since they may later gain chips based on otherplayers’rolls.2.A player with only1or2chips left only rolls1or2dice,respectively.A player with no chips leftdoes not roll but just passes the dice to the next player.Your job is to simulate this game given a sequence of dice rolls.InputInput will consist of multiple test cases.Each test case will consist of one line containing an integer n (indicating the number of players in the game)and a string(specifying the dice rolls).There will be at most10players in any game,and the string will consist only of the characters‘L’,‘C’,‘R’and‘.’.In some test cases,there may be more dice rolls than are needed(i.e.,some player wins the game before you use all the dice rolls).If there are not enough dice rolls left to complete a turn(for example,only two dice rolls are left for a player with3or more chips)then those dice rolls should be ignored.A value of n=0will indicate end of input.OutputFor each test case,output the phrase“Game i:”on a single line(where i is the case number starting at1)followed by a description of the state of the game.This desciption will consist of n+1lines of the formPlayer1:c1Player2:c2...Player n:cnCenter:ctwhere c1, are the number of chips each player has at the time the simulation ended(either because some player has won or there are no more remaining dice rolls)and ct is the number of chips in the center pile.In addition,if some player has won,you should append the string“(W)”after their chip count;otherwise you should append the string“(*)”after the chip count of the player who is the next to roll.The only blank on any line should come before the game number or the player number. Use a single blank line to separate test cases.Sample InputR.L.RLLLCLR.LL..R...CLR. 5RL....C.LSample OutputGame1:Player1:0Player2:0Player3:6(W)Center:3Game2:Player1:1Player2:4Player3:1Player4:4(*)Player5:4Center:1Problem D:Party Party PartyEmma has just graduated high school and it is the custom for the new graduates to throw parties for themselves and invite everyone in school to attend.Naturally,Emma wishes to attend as many parties as possible.This is not such a problem on a weekday since usually there are only two or three parties in the evening.But,Saturdays are packed!Typically some parties start at8AM(breakfast is served) while others might end at midnight(much to the annoyance of the neighbors).Emma naturally wants to know how many parties she can attend.Each party has a starting and stopping time,which are on the hour.These are listed via a24-hour clock.For example,a party might start at10AM(10)and end at2PM(14).The earliest a party can start is8AM(8)and the latest it can end is midnight(24).In order not to be rude,Emma stays at each party at least one half hour and will consider traveling time between parties to be instantaneous. If there are times during the day when there are no parties to attend,she’ll simply go home and rest. InputThere will be multiple test cases.Each test case starts with a line containing an integer p(≤100) indicating the number of parties on the given day.(A value of p=0indicates end of input.)The following p lines are each of the form s e,both integers where8≤s<e≤24,indicating a party that starts at time s and ends at time e.Note there may be multiple parties with the same starting and ending time.OutputFor each input set output a line of the formOn day d Emma can attend as many as n parties.where you determine the value of n and d is the number of the test case starting at1.Sample Input8121313141213910910121312149113141514151415Sample OutputOn day1Emma can attend as many as7parties.On day2Emma can attend as many as2parties.Problem E:Su-Su-SudokuBy now,everyone has played Sudoku:you’re given a9-by-9grid of boxes which you are tofill in with the digits1through9so that1)every row has all nine digits,2)every column has all nine digits,and 3)all nine3-by-3subgrids have all nine digits.To start the game you are given a partially completed grid and are asked tofill in the remainder of the boxes.One such puzzle is shown below.415676985972453919853752472398187286231In this problem,you will be given Sudoku grids which you have nearly completed;indeed you’vefilled in every box exceptfive.You are asked to complete the grid,or determine that it’s impossible.(You might have already made an error!)InputThefirst line of input will contain a positive integer indicating the number of test cases to follow.Each test case will be a nearly completed Sudoku grid consisting of9lines,each containing9characters from the set of digits0through9.There will be exactlyfive0’s in each test case,indicating thefive unfilled boxes.OutputOutput for each test case should be eitherCould not complete this grid.if it is impossible to complete the grid according to the rules of the game,or the completed grid,in the form given below.(There are no blank spaces in the output.)If there is a way to complete the grid,it will be unique.Separate test cases with a blank line.Sample Input2481253697267948105539671204654389712908704563173562849702136958315897426896425371481253697267948105539671284654289710908704562173562849702136958315897426896425371Sample Output481253697267948135539671284654389712928714563173562849742136958315897426896425371Could not complete this grid.Problem F:Tanks a LotImagine you have a car with a very large gas tank-large enough to hold whatever amount you need. You are traveling on a circular route on which there are a number of gas stations.The total gas in all the stations is exactly the amount it takes to travel around the circuit once.When you arrive at a gas station,you add all of that station’s gas to your tank.Starting with an empty tank,it turns out there is at least one station to start,and a direction(clockwise or counter-clockwise)where you can make it around the circuit.(On the way home,you might ponder why this is the case-but trust us,it is.) Given the distance around the circuit,the locations of the gas stations,and the number of miles your car could go using just the gas at each station,find all the stations and directions you can start at and make it around the circuit.InputThere will be a sequence of test cases.Each test case begins with a line containing two positive integers c and s,representing the total circumference,in miles,of the circle and the total number of gas stations. Following this are s pairs of integers t and m.In each pair,t is an integer between0and c−1measuring the clockwise location(from some arbitraryfixed point on the circle)around the circumference of one of the gas stations and m is the number of miles that can be driven using all of the gas at the station. All of the locations are distinct and the maximum value of c is100,000.The last test case is followed by a pair of0’s.OutputFor each test case,print the test case number(in the format shown in the example below)followed by a list of pairs of values in the form i d,where i is the gas station location and d is either C,CC,or CCC, indicating that,when starting with an empty tank,it is possible to drive from location i around in a clockwise(C)direction,counterclockwise(CC)direction,or either direction(CCC),returning to location i.List the stations in order of increasing location.Sample Input1042343619355014121311100Sample OutputCase1:2C4CC9CCase2:0CCC1CCC2CCC3CCC4CCCProblem G:The Worm TurnsWinston the Worm just woke up in a fresh rectangular patch of earth.The rectangular patch is divided into cells,and each cell contains either food or a rock.Winston wanders aimlessly for a while until he gets hungry;then he immediately eats the food in his cell,chooses one of the four directions(north, south,east,or west)and crawls in a straight line for as long as he can see food in the cell in front of him.If he sees a rock directly ahead of him,or sees a cell where he has already eaten the food,or sees an edge of the rectangular patch,he turns left or right and once again travels as far as he can in a straight line,eating food.He never revisits a cell.After some time he reaches a point where he can go no further so Winston stops,burps and takes a nap.For instance,suppose Winston wakes up in the following patch of earth(X’s represent stones,all other cells contain food):01234X13XIf Winston starts eating in row0,column3,he might pursue the following path(numbers represent order of visitation):0123442X11816620143X2281012In this case,he chose his path very wisely:every piece of food got eaten.Your task is to help Winston determine where he should begin eating so that his path will visit as many food cells as possible. InputInput will consist of multiple test cases.Each test case begins with two positive integers,m and n, defining the number of rows and columns of the patch of earth.Rows and columns are numbered starting at0,as in thefigures above.Following these is a non-negative integer r indicating the number of rocks,followed by a list of2r integers denoting the row and column number of each rock.The last test case is followed by a pair of zeros.This should not be processed.The value m×n will not exceed 625.OutputFor each test case,print the test case number(beginning with1),followed by four values:amount row column directionwhere amount is the maximum number of pieces of food that Winston is able to eat,(row,column) is the starting location of a path that enables Winston to consume this much food,and direction isone of E,N,S,W,indicating the initial direction in which Winston starts to move along this path.If there is more than one starting location,choose the one that is lexicographically least in terms of row and column numbers.If there are optimal paths with the same starting location and different starting directions,choose thefirst valid one in the list E,N,S,W.Assume there is always at least one piece of food adjacent to Winston’s initial position.Sample Input55304313200Sample OutputCase1:2203WProblem H:You’ll be Working on the RailroadCongratulations!Your county has just won a state grant to install a rail system between the two largest towns in the county—Acmar and Ibmar.This rail system will be installed in sections,each section connecting two different towns in the county,with thefirst section starting at Acmar and the last ending at Ibmar.The provisions of the grant specify that the state will pay for the two largest sections of the rail system,and the county will pay for the rest(if the rail system consists of only two sections,the state will pay for just the larger section;if the rail system consists of only one section,the state will pay nothing).The state is no fool and will only consider simple paths;that is,paths where you visit a town no more than once.It is your job,as a recently elected county manager,to determine how to build the rail system so that the county pays as little as possible.You have at your disposal estimates for the cost of connecting various pairs of cities in the county,but you’re short one very important requirement—the brains to solve this problem.Fortunately,the lackeys in the computing services division will come up with something.InputInput will contain multiple test cases.Each case will start with a line containing a single positive integer n≤50,indicating the number of railway section estimates.(There may not be estimates for tracks between all pairs of towns.)Following this will be n lines each containing one estimate.Each estimate will consist of three integers s e c,where s and e are the starting and ending towns and c is the cost estimate between them.(Acmar will always be town0and Ibmar will always be town1.The remaining towns will be numbered using consecutive numbers.)The costs will be symmetric,i.e.,the cost to build a railway section from town s to town e is the same as the cost to go from town e to town s,and costs will always be positive and no greater than1000.It will always be possible to somehow travel from Acmar to Ibmar by rail using these sections.A value of n=0will signal the end of input.OutputFor each test case,output a single line of the formc1c2...cm costwhere each ci is a city on the cheapest path and cost is the cost to the county(note c1will always be0 and cm will always be1and ci and ci+1are connected on the path).In case of a tie,print the path with the shortest number of sections;if there is still a tie,pick the path that comesfirst lexicographically. Sample Input70210036245343354417518Sample Output03413。
2011_2012answer
7 答案: 这个程序先读入文件 original 中的内容, 然后对每个字母进行后移 2 位的编码转 换工作,最后把重新编码后的字符串写 到文件 savetoo 内。 文件“savetoo”内存储的内容: Write a program. Ytkvg c rtqitco.
四.
for i in range( len(str) ): (num) num = ord(str[i]) output..append print output
2. i3 = i3 + 1 while i1 < len(lst1): lst3[i3] = lst1[i1] i1 = i1 + 1 i3 = i3 + 1 while i2 < len(lst2): lst3[i3] = lst2[i2] i2 = i2 + 1 i3 = i3 + 1 def mergeSort(lst): n = len(lst) if n > 1: m=n/2 lst1, lst2 = lst[:m], lst[m:] mergeSort(lst1) mergeSort(lst2) merge(lst1, lst2, lst) 3. def f(a,b,c): max = min = a return max, min 4. from random import randrange from string import * def main(): lines=input("please input the lines of triangle: ") for i in range(lines): space=' '*(lines-i-1) character='' for j in range(2*i+1): if randrange(2)==0: mark='*' else: mark='#' character=character+mark print space+character main() # item added to lst3
量子计算机 经典问题
量子计算机经典问题【中英文版】Title: Quantum Computers and Classical QuestionsTitle: 量子计算机与经典问题The phrase "quantum computer" often evokes images of futuristic technology, capable of solving complex problems beyond the scope of classical computers.However, the concept of quantum computing also raises classical questions in the field of computer science.“量子计算机”这一词汇常引发人们对未来科技的想象,能够解决传统计算机难以应对的复杂问题。
然而,量子计算的概念在计算机科学领域也引发了经典问题。
One of the classical questions in computer science is the "halting problem," which asks whether it is possible to determine, for an arbitrary program, whether it will eventually halt.This problem is known to be undecidable in the classical computing paradigm.However, quantum computing offers a potential solution to this problem.计算机科学中的一个经典问题是“停机问题”,它询问是否可以确定任意程序最终是否会停止。
这个问题在传统计算范式中已知是不可判定的。
小学生信息学奥赛决赛题2008年决赛答案
2008年长沙市小学生计算机奥林匹克竞赛决赛试题(时间:150分钟)一、整数处理(100分)(存盘程序名:T1)电脑老师让小慧编程做一道题:输入一个正整数A(A≤100000000),如果A的个位数字是5,则统计A能被5整除多少次?否则,统计A当中含有多少个“0”?你能做吗?例如:输入:125输入:305160输出:3 输出:2程序:program cs200801;vara:longint;{根据A的取值范围,采用长整型}n:integer;beginreadln(a);n:=0;if a mod 10=5 thenrepeata:=a div 5;n:=n+1;until a mod 5<>0{统计A能被5带除多少次}else beginrepeatif a mod 10=0 then n:=n+1;a:=a div 10;until a<10;{统计A当中含有多少个0}end;{采用if……then……else……结构,以符合题目的逻辑关系}writeln(n);readlnend.过年了,小慧与邻居邻居的小伙伴共n人相约一起放花炮:他们同时放响了第一个,随后n个人分别以a1、a2、a3、……、an秒的间隔继续放花炮,每人都放了b个。
问:总共可听到多少声花炮响?输入:n(n≤10)a1 a2 ……an(每个数≤100,以空格相隔)b(b≤100)输出:一个整数(听到的花炮响声数)例如:输入:3 输出:71 2 34解题思路:用数组的下标表示时间,元素的值不为0表示听到花炮响。
用同一个数组来标示所有人放花炮的过程,同时响的花炮在数组中会被记录在同一元素中。
最后统计数组中有数据的元素个数,就能得出共听到了多少声花炮响。
这一方法还可以求出在某一时刻,同时有多少个花炮一起响。
程序:program CS200802;varn,b,i,j,k,s:integer;a:array[1..100] of integer;c:array[1..10000] of integer;{用于记录花炮响。
算法导论 第八章答案
{ if(m >n)
cout<<"区间输入不对"<<endl; else { if(n <0) else if(m <=0&& n <= k) else if(n > k && m >0) else if(n > k && m <=0) else
cout<<"个数为"<<0<<endl; cout<<"个数为"<<c[n]<<endl; cout<<"个数为"<<c[k] - c[m -1]<<endl;
cout<<"个数为"<<c[k]<<endl; cout<<"个数为"<<c[n] - c[m -1]<<endl;
}}
return 0;
}
void counting_sort(int*&a, int length, int k, int*&b, int*&c)
{ for(int i =0; i < k +1; i++)
const int k =2504; int* c =new int[k +1];
counting_sort(a, LEN, k, b, c); //这里需要注释掉
//for(int i = 0; i < LEN; i++)
// cout<<b[i]<<endl;
阿尔卡特朗讯程控话机功能代码
功能前缀0 Attendant Call 呼叫话务员9 Professional Trunk Group Seized 中继组出局*10 Set In/Out of service 退出/进入服务*11 Adjust Display Visibility 显示屏调整*12 Lock 话机锁定/解锁*13 Protect. against barge-in & beeps 临时通话保护*14 Substitution 替代*15 Language 语言选择*16 Sta. group exit 退出连选组*17 Sta. group entry 加入连选组*18 Camp-on Control 呼叫等待控制*19 Password modification 修改个人密码*20 Speed call to associated set 快速呼叫关联话机*21 Select Primary Line 选择主线路*22 Select Secondary Line 选择辅线路*23 Message deposit 回叫文本请求*24 Switch off Message LED 关闭留言灯*25 V oice Mail Deposit 点亮留言灯*26 Conversation Recording 通话录音*27 Recordable V oice Guides 动态语音提示录制*28 Remote Extension Activation 激活远程分机*29 Remote Extension Deactivation 取消远程分机*30 Agent processing group call pickup 坐席组代接*31 Secret/Identity 身份保密*32 Manual Hold 手动保持*33 Business account code 业务帐号代码*34 Access to waiting call 查询等待呼叫*35 Park Call/Retrieve 呼叫驻留*36 Night service answering 夜间服务代接*37 Common Hold 通用保持*38 Malicious call 恶意呼叫追踪*39 Direct trunk seizure 直接抓取中继线*40 ACD Prefixes ACD功能*41 Room status management 客房状态管理*42 Mini-bar 迷你酒吧管理*43 Last Caller Callback 回叫最后主叫*44 Meet-me Conference 遇我会议*45 Manual Add-on Conference 手动主控会议*46 Automatic Add-on Conference 自动主控会议*47 Announcement 广播*48 Explicit Precedence level 优先级别*49 Background Music 背景音乐*50 Remote forward 远端转移(跟我转移)*51 Overfl.busy to assoc.set 忙线时溢出至关联话机*52 Overfl.on no answer to associate 无应答时溢出至关联话机*53 Overf.busy/no answer to assoc.set 忙线或无应答时溢出至关联话机*54 Cancel Overfl.to associate 取消溢出至关联话机*55 Cancel auto. callback on busy 取消自动回叫*56 Personal directory Programming 个人通讯录编辑*57 Personal Directory Use 使用个人通讯录*58 Ubiquity Mobile Programming 一号通移动号码编辑*59 Ubiquity 一号通*60 Immediate forward 无条件立即转移*61 Immediate forward on busy 遇忙立即转移*62 Forward on no answer 无应答延时转移*63 Forward on busy or no answer 遇忙或无应答延时转移*64 Forward cancellation 取消转移*65 Cancel Remote forward 远程取消转移*66 Forward cancel.by destinat. 由目的地取消转移*67 Access Callback list 访问回叫列表*68 Suite Do Not Disturb 套房请勿打扰*69 Associated Direct. No. modif. 修改关联话机号码*70 Redial last number 重拨最后号码*71 Direct call pickup 直接代接*72 Group call pickup 组代接*73 Suite Wake-up 套房叫醒*74 Suite Wake-up Cancel 取消套房叫醒*75 Cancel Wake-up 取消叫醒*76 Wake-up/appointment reminder 约会提醒/叫醒服务*77 V oice Mail Access 查询语音消息*78 Do not disturb 请勿打扰*79 Tone test 音频检测# DTMF end-to-end dialing DTMF双音频透明发送功能后缀1 Broker Call 代理呼叫2 Consultation Call 查询呼叫3 Three-Party Conference 三方会议4 Barge-in 强插5 Callback On Free Or Busy Set 遇忙或无应答自动回叫6 Busy Camp-on 遇忙呼叫等待7 Call Announcement 呼叫通知8 V oice Mail Deposit 语音消息留言* DTMF end-to-end dialing DTMF双音频透明发送#71 Business number 业务帐号代码。
4.Agent008的任务
《信号与系统》工程设计问题华中科技大学光学与电子信息学院 1 / 1 Agent008的任务供题老师:洪伟本题研究莫尔斯码的幅度调制与解调。
Agend 007的最后一句话是:“The future of technology lies in 。
”你(Agend 008)目前的任务就是要破解Agend 007的最后一个字。
该字的信息包含在信号x(t)中。
信号x(t)具有下式的形式:x (t )=m 1(t )cos (2πf 1t )+m 2(t )sin (2πf 1t )+m 3(t )sin (2πf 2t )式中的调制频率分别由变量f 1和f 2给出,信号m 1(t ),m 2(t )和m 3(t )对应于字母表中的单个字母,这个字母表已用国际莫尔斯码进行编码,如下表所示:本题中信号x(t)由文件ctftmod.mat 定义,可用命令Load ctftmod 将文件ctftmod.mat 定义的变量装入系统内存。
运行命令Load ctftmod 后,装入系统的变量有af bf dash dot f1 f2 t x其中bf af : 定义了一个连续系统H(s)的分子多项式和分母多项式。
可利用freqs(bf,af,w)求出该系统的频率响应,也可用sys=tf(bf,af)得到系统的模型,从而用lsim 求出信号通过该系统的响应。
dash dot : 给出了莫尔斯码中的基本信号dash 和dot 的波形f1 f2: 载波频率t: 信号x(t)的抽样点x: 信号x(t)的在抽样点上的值 信号x(t)含有一段简单的消息。
(1) 字母B 可用莫尔斯码表示为b=[dash dot dot dot],画出字母B 莫尔斯码波形;(2) 用freqs(bf,af,w)画出系统的幅度响应;(3) 利用lsim 求出信号dash 通过由sys=tf(bf,af)定义的系统的响应,解释你所获得的结果;用fft 画出信号dash 调制 cos (2πf 1t )的信号频谱(双边谱),它是否在这个低通滤波器的频带范围内?(4)用解析法推导出下列信号的Fourier 变换,并与用fft 函数得到的结果比较:m (t )cos (2πf 1t )cos (2πf 1t )m (t )cos (2πf 1t )sin (2πf 1t )m (t )cos (2πf 1t )sin (2πf 2t )(5)利用(4)中的结果,设计一个从x(t)中提取信号m1(t)的方案,画出m1(t)的波形并确定其所代表的字母;(6)对信号m2(t)和m3(t)重复(5)。
计算机组成原理1
作业1.第15题下列关于寄存器间接寻址方式操作数所在位置的说法正确的是()。
A.操作数在指令中B.操作数在寄存器中C.操作数地址在寄存器D.操作数地址(主存)在指令中标准答案:C您的答案:题目分数:2.0此题得分:0.02.第16题程序计数器属于_______部分。
A.控制器B.运算器C.存储器D. I/O接口标准答案:A您的答案:题目分数:2.0此题得分:0.03.第17题计算机操作的最基本时间单位是______。
A.时钟周期B.指令周期C. CPU周期D.微指令周期标准答案:A您的答案:题目分数:2.0此题得分:0.04.第24题以下四种类型的二地址指令中,执行时间最短的是____。
A.RR型B. RS型C.SS型D.SR型标准答案:A您的答案:题目分数:2.0此题得分:0.05.第25题在cache的下列映射方式中,无需考虑替换策略的是____。
A.全相联映射B.组相联映射C.段相联映射D.直接映射标准答案:D您的答案:题目分数:2.0此题得分:0.06.第26题下列关于立即寻址方式操作数所在位置的说法正确的是____。
A.操作数在指令中B.操作数在寄存器中C.操作数地址在寄存器D.操作数地址(主存)在指令中标准答案:A您的答案:题目分数:2.0此题得分:0.07.第31题下面磁盘存储器的技术指标与转速无关的是()。
A.平均存取时间B.平均等待时间C.平均找道时间D.数据传输率标准答案:C您的答案:题目分数:2.0此题得分:0.08.第34题下列____不属于浮点加法的流水段?A.对阶B.阶码相加C.尾数加减D.规格化及舍入处理标准答案:B您的答案:题目分数:2.0此题得分:0.09.第38题为了便于实现多级中断,保存现场信息最有效的方法是采用____。
A.通用寄存器B.堆栈C.存储器D.外存标准答案:B您的答案:题目分数:2.0此题得分:0.010.第39题下面哪个标志触发器是CPU是否受理中断或者批准中断的标志____。
NOIP2000-2009提高组解题报告(c语言)
容易想到的思路是: 令 d[x1,y1,x2,y2]表示甲在 x1,y1,乙在 x2,y2 以后(包括取走(x1,y1))的过程中可以获得的最大和。 则 d[1,1,1,1]就是原问题的解。
若 ,则必然有 ,也就是说根在 中,应该对此区间重复该过程。 最后,就可以得到精确到 0.001 的根。 再考虑什么样的区间内会有根 。由于题目给出了所有的根都在-100 到 100 之间,且根与根之间差不小于 1 的限制 条件,故我们可知,在 、 、……、 、 这 201 个区间内,每个区间内至多只能存在一个根。这样对除去区间 外 的其他的区间 ,要么 ,要么 时这个方程在此区间内才有解。若 ,显然 为解;若 ,则可以利用上面所说的方法 球出解来。这样就可求出这个方程的所有解。 最后是输出的解要求排序。我们既可以在求出来之后排序,也可以从小到大的顺序求解,就可以按照升序求出所有 解。 数据:
第四题: 有同学搜索第一个人,拣了以后第二个人用动态规划,一定能得最优解,但时间效率不大高。 有同学采用贪心,即用动态规划算出第一个人最大能拣的数,再在剩下的数中用动态规划。 反例如下: 191 000 191 第一次是: 1->9->9->1 第二次是:1 和是 21 但显然可以两次把所有的数拣完(22)。
但是是否能取数和另一个人是否事先已经到过该格子有关,我们需要设计一种走的方法,使得只根据 x1,y1, x2,y2 就能判断一些关键的格子是否已经到达过。这样,问题才具有无后效性。
NOIP完善程序真题(07-10)
NOIP2007提高组第一题格雷码 (Gray Code)Gray Code是一种二进制编码,编码顺序与相应的十进制数的大小不一致。
其特点是,对于两个相邻的十进制数,对应的两个格雷码只有一个二进制位不同。
另外,最大数与最小数间也仅有一个二进制位不同,以4位二进制数为例,编码如下:十进制数格雷码十进制数格雷码0 0000 8 11001 0001 9 11012 0011 10 11113 0010 11 11104 0110 12 10105 0111 13 10116 0101 14 10017 0100 15 1000如果把每个二进制的位看做一个开关,则将一个数变为相邻的另一个数,只须改动一个开关。
因此,格雷码广泛用于信号处理、数-模转换等领域。
下面程序的任务是:由键盘输入二进制的位数n(n<16),再输入一个十进制数m(0≤m<2n),然后输出对应于m的格雷码(共n位,用数组gr[ ]存放)program s501;varbound,m,n,i,j,b,p:integer;gr:array[0..14]of integer;beginbound:=1; writeln('input n,m'); readln(n,m);for i:=1 to n do bound:=[ ① ];if (m<0)or(m>=bound)then beginwriteln('Data error!');[ ② ];end;b:=1;for i:=1 to n dobeginp:=0; b:=b*2;for[ ③ ] to m doif ([ ④ ]) then p:=1-p;gr:=p;end;for i:=n[ ⑤ ] do write(gr); writeln;end.NOIP2007提高组第二题连续邮资问题某国发行了n种不同面值的邮票,并规定每封信上最多允许贴m张邮票。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
“计算机组织结构”作业08参考答案1.典型的微处理器是用不同地址去访问指定设备控制器中的I/O数据寄存器、控制和状态寄存器。
这些寄存器被称为端口(port)。
Intel 8088使用两类I/O指令格式。
一类格式中,8位操作码指定I/O操作,后随8为端口地址;另一类格式中,I/O操作码隐含指示端口地址在16位的DX寄存器中。
在每类寻址模式中,8088能寻址多少端口?采用直接寻址方式的端口地址为1个字节长,可寻址28即256个端口采用间接寻址方式的端口地址为两个字节长,可寻址216即65536个端口2.在编程式I/O中,处理器陷入一个等待循环来检查I/O设备状态。
为提高效率,可编写这样的I/O软件:处理器周期性地检查设备状态,若设备未就绪,处理器跳转到执行其他任务,在某指定时间长度的间隔后处理器再次检查设备状态。
a)考虑采用上述方法向打印机一次1字符地输出数据。
打印机以10字符/秒速度运行。
若每20ms扫描一次它的状态,将发生什么?b)接着考虑一个具有单一字符缓冲器的键盘。
平均而言,字符以10字符/秒的速度被敲入。
然而两次连续按键的时间间隔是60ms。
I/O程序应该以什么频率扫描键盘?a)由于打印机的输出速度为10字符/秒,输出一个字符所需要的时间为1/10=0.1s=100ms。
若处理器每隔20ms扫描一次打印机状态,则需要查询5次时才能得到获得打印机就绪状态。
b)虽然字符以10字符/秒的速度敲入,但两次连续按键的时间间隔为60ms,且键盘只有单一字符的缓冲器。
为了保证之前输入的字符不丢失,I/O程序扫描键盘的间隔应该不大于60ms,即频率至少为17次/秒。
3.考虑某系统对一个设备使用了中断驱动式I/O,此设备以平均64kbps的速度连续传送数据。
a)假设中断处理大约用100μs,每字节中断一次,确定处理器时间的百分之几被这个I/O设备所消耗。
b)假设这个设备有两个16字节的缓冲器并当一个缓冲器满时才中断处理器一次。
执行此中断服务时,处理时间需要延长(每传送一个字节处理器要用大约8μs),重复上问。
a)由于每个字节中断一次,而数据传输率为64kbps,所以每秒钟的中断次数为8k次。
因此,该I/O设备占用处理器时间的比例是8k*100μs/1s=80%b)处理一个缓冲器的中断耗时100+(16-1)*8=220μs,而每秒钟处理的次数为8kB/16B=500次。
因此,该I/O设备占用处理器时间的比例是220*500μs/1s=11%4.在包含DMA模块的系统中,一般DMA存取主存储器的优先级比处理器存取主存储器的优先级高,为什么?如果处理器被停止访问主存储器,除处理时间延长外不产生其它问题。
但DMA可能连接高速数据传输设备,如果不及时获取主存储器的存取权限来及时写入数据,则可能会因为缓冲区溢出而造成数据丢失。
所以,一般DMA存取主存储器的优先级会高于处理器。
5.在一个系统中,经由总线的一次数据传送用500ns。
总线控制的传递,无论是由处理器到DMA模块还是由DMA模块到处理器,两个方向上都是用200ns.一个有400kbps数据传输率的I/O设备使用了DMA来传送128字节的块,每次传送1字节的数据。
a)若使用突发模式DMA,即块传送之前DMA模块获得总线控制权并一直维持对总线的控制直到整个块传送完。
设备占用总线多长时间(含获取总线控制和交回总线控制)?b)若使用周期窃取式DMA,重复上问。
a)DMA获取总线控制和交回总线控制的时间均为200ns。
在总线上传输前127字节需要的时间为500ns*127B/1B=63500ns,而I/O设备提供数据的时间为128B/400kbps=2.56ms。
因此,总线占用时间为:200ns+max(2.56ms,63500ns)+500ns+200ns=2.5609ms [晁贝贝,121250007]b)使用周期窃取式DMA时,DMA每次进行数据传输都要获取和交回总线,所以设备占用总线的时间为:128B/1B×(200+500+200)=0.1152ms6.假定某计算机的CPU主频为500MHz,所连接的某个外设的最大数据传输率为160kbps,该外设接口中有一个16位的数据缓存器,相应的中断服务程序的执行时间为500个时钟周期,则是否可以用中断方式进行该外设的输入输出?假定该外设的最大数据传输率改为16Mbps,则是否可以用中断方式进行该外设的输入输出?a)外设的最大传输率为160kbps,而每传输完16位进行一次中断处理,因此1秒内的中断次数为160kbps/16bit=10k次。
所以,1秒内需要的中断处理的时间为10k/500MHz×500=10ms<1s,所以可以用中断方式进行该外设的输入输出。
b)外设的最大传输率为16Mbps,而每传输完16位进行一次中断处理,因此1s内的中断次数为16Mbps/16bit=106次。
所以,1秒内需要的中断处理的时间为106/500MHz×500=1s,所以可以用中断方式进行该外设的输入输出。
[刘丞,121250078]7.若某计算机有5级中断,中断响应优先级为1>2>3>4>5,而中断处理优先级为1>4>5>2>3。
要求完成以下工作:a)设计各级中断处理程序的中断屏蔽字(假设1为屏蔽,0为开放)。
b)若在运行主程序时,同时出现第2、4级中断请求,而在处理第2级中断过程中,又同时出现1、3、5级中断请求,画出此程序运行过程示意图。
a)1级中断的处理优先级最高,说明1级中断对其他所有中断都屏蔽,其屏蔽字为全1;3级中断的处理优先级最低,所以除了3级中断本身之外,对其他中断全都开放,其屏蔽字为00100。
以此类推,得到所有中断屏蔽字:b)程序运行过程示意图:在运行主程序时,同时出现中断2和中断4。
因为主程序对所有中断都开放,而中断2的响应优先级高于中断4,所以先响应中断2。
(发现中断2和4后,会停止响应中断一段时间,即“关中断”,这段时间内会决定是响应中断2和4中的哪个中断,保存原有的状态,并在响应中断2之后、处理中断2之前“开中断”。
)在处理中断2之前,由于中断4的处理优先级高于中断2,因此响应并处理中断4,结束后返回中断2并处理。
在处理中断2过程中,同时发生了1、3、5级中断。
因为中断2屏蔽中断3,且中断1的响应优先级高于中断5,所以响应中断1。
因为中断1的处理优先级最高,所以在其处理过程中不会响应任何新的中断请求,直到中断1处理结束,然后返回中断2。
由于中断5的优先级高于中断2,所以会响应并处理中断5,处理完后回到中断2。
由于中断2能够屏蔽中断3,所以中断2会处理完,并回到主程序。
主程序响应并处理中断3,处理结束后回到主程序。
8.假设一个主频为1GHz的处理器需要从某个成块传送的I/O设备读取1000字节的数据到主存缓冲区中,该I/O设备一旦启动即按400kbps的数据传输率向主机传送1000字节数据,每个字节的读取、处理并存入内存缓冲区需要1000个时钟周期,则以下4种方式下,在1000字节的读取过程中,CPU用在该设备的I/O操作上的时间分别为多少?占整个处理器时间的百分比分别为多少?a)采用查询方式,每次处理一个字节,一次状态查询至少需要60个时钟周期。
b)采用中断驱动I/O方式,外设每准备好一个字节发送一次中断请求。
每次中断响应需要两个时钟周期,中断服务程序的执行需要1200个时钟周期。
c)采用周期挪用DMA方式,每挪用一次主存周期处理一个字节,一次DMA传送完成1000字节数据的I/O,DMA初始化和后处理的时间为2000个时钟周期,CPU和DMA没有访存冲突。
d)如果设备的速度提高到40Mbps,则上述3种方式中,哪些是不可行的?为什么?对于可行的方式,计算出CPU花在该设备I/O操作上的时间占整个处理器时间的百分比?a)I/O设备的数据传输率为400kbps,因此传输每个字节的时间为1B/400kbps=20μs。
处理器主频为1GHz,所以每个时钟周期为1ns。
每个字节读取、处理和存入内存缓冲的时间为1000×1ns=1μs<20μs。
因此CPU完成整个数据传输的时间为1000B/400kbps+1μs=20.001ms。
[刘丞,121250078]在查询方式中,CPU会一直参与,因此占用处理器时间的百分比为100%。
b)采用中断驱动方式,占用CPU的总时间为(2+1200)×1ns×1000=1.202ms。
I/O操作占整个处理器时间的百分比为:1.202ms/(1000B/400kbps+(2+1200)×1ns)=6.01%。
[曹雨婷,121250005](注意:此处中断处理包含了数据传输。
)c)在周期挪用方式下,由于CPU和DMA没有访存冲突,则CPU受到影响的时间为2000×1ns=2μs,所以I/O操作上占整个处理器时间的百分比为:2μs/(1000B/400kbps+1ns×1000+2μs)=0.01%[卢苇,121250091][马昕,131250093] d)当设备的速度提高到40Mbps后,传送1个字节需要的时间为0.2μs。
查询方式中获取第1个字节后,第2次查询最多可能间隔(1000+60)×1ns=1.06μs>0.2μs,会造成数据丢失,所以不可行。
中断方式中获取第1个字节后,响应第2次中断的时间间隔至少为(2+1200)×1ns=1.202μs>0.19μs,会造成数据丢失,所以不可行。
采用周期挪用DMA方式,假设DMA与CPU不存在访存冲突,占用CPU时间为2000×1ns=2μs。
如果DMA接收数据的速度慢于存入主存的速度,则所用的总时间为接收数据的时间加上将最后一个字节存入主存的时间再加上初始化和结束的时间;如果DMA接收数据的速度快于存入主存的速度,则所有的总时间为接收第一个数据的时间加上将所有数据存入主存的时间再加上初始化和结束的时间。
所以占用CPU时间的比例为:2μs/max{1000B/40Mbps+1ns×1000+2μs,0.2μs+1000×1μs+2μs}=0.20%。
[卢苇,121250091][杨松,121250190][马昕,131250093] (这里与几位同学进行了讨论,主要分歧在于“DMA处理一个字节需要1个主存周期”中“主存周期”的大小到底是1个时钟周期还是1000个时钟周期。
最终觉得还是1000个时钟周期更为合理,即CPU与DMA访问主存的时间开销是一样的,区别是采用DMA访问主存时不需要CPU的参与。