2 shunfurh shunfurh 于 2016.12.31 22:16 提问

Let's Go to the Movies

Description

A favorite pastime for big families in Acmestan is going to the movies. It is quite common to see a number of these multi-generation families going together to watch a movie. Movie theaters in Acmestan have two types of tickets: A single ticket is for exactly one person while a family ticket allows a parent and their children to enter the theater. Needless to say, a family ticket is always priced higher than a single ticket, sometimes as high as five times the price of a single ticket.

It is quite challenging for families to decide which ticket arrangement is most economical to buy. For example, the family depicted in the figure on the right has four ticket arrangements to choose from: Seven single tickets; Two family tickets; One family ticket (for adam, bob, cindy) plus four single tickets for the rest; Or, one family ticket (for bob and his four children) plus single tickets for the remaining two.

Write a program to determine which ticket arrangement has the least price. If there are more than one such arrangement, print the arrangement that has the least number of tickets.

Input

Your program will be tested on one or more test cases. The first line of each test case includes two positive integers (S and F) where S is the price of a single ticket and F is the price of a family ticket. The remaining lines of the test case are either the name of a person going by him/herself, or of the form:

N1 N2 N3 … Nk

where N1 is the name of a parent, with N2… Nk being his/her children. Names are all lower-case letters, and no longer than 1000 characters. No parent will be taking more than 1000 of their children to the movies :-). Names are unique, the name of a particular person will appear at most twice: Once as a parent, and once as a child. There will be at least one person and at most 100,000 people in any test case.

The end of a test case is identified by the beginning of the following test case (a line made of two integers.) The end of the last test case is identified by two zeros.

Output

For each test case, write the result using the following format:

k. NS NF T

Where k is the test case number (starting at 1), NS is the number of single tickets, NF is the number of family tickets, and T is the total cost of tickets.

Sample Input

1 3
adam bob cindy
bob dima edie fairuz gary
1 2
john
paul
george
ringo
1 3
a b c
0 0
Sample Output

  1. 2 1 5
  2. 4 0 4
  3. 0 1 3

1个回答

caozhy
caozhy   Ds   Rxr 2016.12.31 23:29
已采纳
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!
其他相关推荐
字体大宝库:25款很好看的液晶数字字体下载
字体是 Web 和图形设计非常重要的一部分,选择合适的字体对于设计项目来说至关重要。今天这篇文章收集了一组好看的液晶数字字体,可以免费下载使用,相信里面有你喜欢的,赶紧收藏和下载吧。 Display     The 2K12     Score Board     LCD / LCD Mono
Let's Pee
        王小波在一篇文章中说,见到有人穿着一件T shirt,上面印着“Go,Lets Pee”,觉得简短有力让人振奋,后来知道了Pee是小便的意思,得出了一个结论,就是振奋之前,先要搞清是件什么事情,再振奋不迟,因为我们都已经过了被别人激励小便的年龄。我们也曾经为了很多事情振奋,比如说为了共产主义事业奋斗终生,可临了最后,被激励振奋,真正奋斗终生的人好像都混得不太好,而且好像并不很幸福
教你领取4只莱茨狗_百度区块链游戏项目Let‘s go
百度上周日悄悄上线了区块链项目,名为“莱茨狗”应该是取了英文“Let's go“的谐音,从该项目的官网中我们可以看到,目前百度提供了多种不同形态的小莱,每只拥有体型、眼睛、嘴巴、身体色等多类属性信息,并划分为多个等级。 汪汪汪~我是区块链赋能的莱茨狗。我的小伙伴们,每只都有独一无二的基因。一旦你拥有了我,我们的关系将被永远记录在区块链上,任何人都不能改变。 我有8个外貌特征,每个特征有两种不同
Let's go, Just do it, and enjoy it
阅读时光:不再做yesbuter 生活中总是有这样的人,他们喜欢说:“是的,可是……”   “你不是总说很想学跳舞吗?听说你们学校的舞蹈协会不错,怎么不去报名学习一下?”“是的,我也听说了,可是,我都是成年人了,肯定跳不好,再说……”“不是一直觉得自己文笔不错吗?何不向报纸杂志尝试投稿?”“是的,可是,谁知道有多少人都在投稿呢,我不行的,再说了……”“经常听你说不满于
Let's go 户外用品有限公司
Let's go 户外用品有限公司 web课程设计
百度区块链内测"莱茨狗”
开发团队为百度金融区块链实验室,该实验室主营企业级区块链解决方案,以及面向用户的应用级区块链解决方案。对此,百度相关负责人回应称,百度金融区块链实验室数字狗仅在内部测试阶段,是区块链技术应用领域的一次尝试。然而,百度并非国内第一家涉及区块链收藏游戏的厂商,早在上月10日,曾有媒体曝光,网易悄然上线了名为《网易招财猫》的区块链产品网页,并支持数字货币支付。显然,国内已有互联网巨头注意到了区块链收藏游...
UVALive 6039 Let's Go Green
树形dp。反向思维,考虑最多的情况,即所有边权和,减去没必要的,就是答案了。。。    在做减法的时候,对于一个点:     1、当存在有一条边(tmp)的权值大于通过该点所有边权值和(sum)的一半时,显然,对于除了tmp的其他边,都可以让通过tmp的自行车走这些边。所以ans -= sum-tamp。     2、当不存在上述情况时,我们就可以把通过这个点的边分成两半,这样的话对于该点就
俄罗斯方块游戏
C# 写的俄罗斯方块 可直接运行 !let's go,破纪录吧
sap+权限的设定.ppt
sap+权限的设定.ppt BASIS LET's go
高德地图返回地址详细信息
高德地图返回地址详细信息, Android&Go,Let's go!