| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 948 人关注过本帖
标题:求教:一道编程题:Counterfeit Dollar
取消只看楼主 加入收藏
ALU
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2008-3-11
收藏
 问题点数:0 回复次数:2 
求教:一道编程题:Counterfeit Dollar
Sally Jones has a dozen Voyageur silver dollars. However, only eleven of the coins are true silver dollars; one coin is counterfeit even though its color and size make it indistinguishable from the real silver dollars. The counterfeit coin has a different weight from the other coins but Sally does not know if it is heavier or lighter than the real coins.


Happily, Sally has a friend who loans her a very accurate balance scale. The friend will permit Sally three weighings to find the counterfeit coin. For instance, if Sally weighs two coins against each other and the scales balance then she knows these two coins are true. Now if Sally weighs one of the true coins against a third coin and the scales do not balance then Sally knows the third coin is counterfeit and she can tell whether it is light or heavy depending on whether the balance on which it is placed goes up or down, respectively.


By choosing her weighings carefully, Sally is able to ensure that she will find the counterfeit coin with exactly three weighings.


Input

The first line of input is an integer n (n > 0) specifying the number of cases to follow. Each case consists of three lines of input, one for each weighing. Sally has identified each of the coins with the letters A-L. Information on a weighing will be given by two strings of letters and then one of the words ``up'', ``down'', or ``even''. The first string of letters will represent the coins on the left balance; the second string, the coins on the right balance. (Sally will always place the same number of coins on the right balance as on the left balance.) The word in the third position will tell whether the right side of the balance goes up, down, or remains even.


Output

For each case, the output will identify the counterfeit coin by its letter and tell whether it is heavy or light. The solution will always be uniquely determined.


Sample Input

1
ABCD EFGH even
ABCI EFJK up
ABIJ EFGH even

Sample Output


K is the counterfeit coin and it is light.
搜索更多相关主题的帖子: Counterfeit Dollar 
2008-09-02 20:35
ALU
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2008-3-11
收藏
得分:0 
中文如下:
Sally 有一打銀幣(十二個),可是只有11個是真的,有一個是假的(但是它的顏色和大小都和真的一樣)。還好那個假幣的重量和真的不一樣,不過 sally 不知道它到底是比真的輕還是重。

可喜的是, sally 有個朋友借他一個非常精準的天平,那個朋友同意讓 Sally 秤三次來找出假幣。例如,秤2個硬幣,結果天平平衡,那麼這2個都是真的。如果用其中的一個真的和第三個硬幣去秤,如果天平不平衡,那麼 sally就知道第三個硬幣是假的。同時他也可以根據天平來判斷那個假的到底是比真的輕還是重。Sally 會小心的選擇秤重的方法,這樣他才能用剛好秤三次找出那個硬幣是假的。
输入说明 :


輸入的第一列有一個整數 n,代表以下有幾組測試資料。

每組測試資料三列,每列代表一次秤重。Sally 把他的硬幣編號為A~L。每次秤重左右兩邊的硬幣用2個字串表示(Sally 總是在左右兩邊放相同數目的硬幣),秤重的結果用 up, down, even 來表示,代表天平的右邊是往上,往下,還是平衡。請參考Sample Input。

输出说明 :


對每一組測試資料輸出哪一個硬幣是假的,並且是較輕還是較重。請注意:答案一定是唯一的。

请高手教下
2008-09-02 22:12
ALU
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2008-3-11
收藏
得分:0 
中文如下:
Sally 有一打銀幣(十二個),可是只有11個是真的,有一個是假的(但是它的顏色和大小都和真的一樣)。還好那個假幣的重量和真的不一樣,不過 sally 不知道它到底是比真的輕還是重。

可喜的是, sally 有個朋友借他一個非常精準的天平,那個朋友同意讓 Sally 秤三次來找出假幣。例如,秤2個硬幣,結果天平平衡,那麼這2個都是真的。如果用其中的一個真的和第三個硬幣去秤,如果天平不平衡,那麼 sally就知道第三個硬幣是假的。同時他也可以根據天平來判斷那個假的到底是比真的輕還是重。Sally 會小心的選擇秤重的方法,這樣他才能用剛好秤三次找出那個硬幣是假的。
输入说明 :


輸入的第一列有一個整數 n,代表以下有幾組測試資料。

每組測試資料三列,每列代表一次秤重。Sally 把他的硬幣編號為A~L。每次秤重左右兩邊的硬幣用2個字串表示(Sally 總是在左右兩邊放相同數目的硬幣),秤重的結果用 up, down, even 來表示,代表天平的右邊是往上,往下,還是平衡。請參考Sample Input。

输出说明 :


對每一組測試資料輸出哪一個硬幣是假的,並且是較輕還是較重。請注意:答案一定是唯一的。

请高手教下
2008-09-02 22:12
快速回复:求教:一道编程题:Counterfeit Dollar
数据加载中...
 
   



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

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