| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 948 人关注过本帖
标题:求教:一道编程题:Counterfeit Dollar
只看楼主 加入收藏
ALU
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2008-3-11
收藏
 问题点数:0 回复次数:3 
求教:一道编程题: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
李芝超
Rank: 1
来 自:山东莒县
等 级:新手上路
帖 子:17
专家分:0
注 册:2008-9-1
收藏
得分:0 
大致意思单词翻译

萨利琼斯十几voyageur银美元。然而,只有11的硬币是真正的银美元;一硬币是伪造的,即使它的颜色和大小,使之区分真正的银美元。伪造的硬币有不同的重量从其他硬币,但莎莉不知道如果是较重或较轻的,比真正的硬币。


令人高兴的是, Sally已经朋友谁贷款,她非常准确地平衡量表。朋友将允许萨利3称量找到伪币。举例来说,如果萨利两个硬币的重量对对方和规模的平衡,然后她知道这两个硬币是真的。现在,如果萨利重量之一,真正的硬币针对第三硬币和规模的不均衡,然后莎莉知道第三硬币是伪造的,她可以告诉无论是轻或重视乎是否平衡上,把它放在上升或下降,分别为。


选择她仔细称量,莎莉是能够确保她会找到伪造硬币与正是三称量。


投入

第一线的投入是一个整数n ( > 0 )订明的个案数目遵循。每宗个案的组成,三条线的投入,一为每个称重。 Sally已经确定的每一个硬币与信访基地。的资料,称重,将所给予的两个字符串的信件,然后其中一个的话他最多'' ,他下来'' ,或他甚至'' 。第一一连串的信件将代表硬币在左边的平衡;第二个字串,这套金银纪念币上取得适当的平衡。 (萨利将始终把相同数目的硬币上取得适当的平衡,作为在左边的平衡。 )一词在第三位,是否会告诉右侧的平衡上升,下降,或保持,甚至。


输出

为每一种情况下,输出将查明伪造硬币其信,并告诉无论是重型或轻。该解决方案将永远是独特的决心。


样本输入

1
abcd efgh ,甚至
abci efjk起来
abij efgh ,甚至

示例输出


K是伪造的硬币,这是轻。

人总是要觉醒的!
2008-09-03 01:09
快速回复:求教:一道编程题:Counterfeit Dollar
数据加载中...
 
   



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

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