编程介的小学生 2019-12-30 21:55 采纳率: 0.2%
浏览 114

Rose Shop 输出图形

Problem Description
Small JH,the boss of the rose shop, preparated many roses for the valentine's day.It’s too much people come and buy roses,so Small JH have to put the roses back in every t(0 < t) minutes.The roses put as a thwartwise tower in the rail (look at the picture).You can get the number of rose with n(0<n<13) rows is n*(n + 1)/ 2.
a bundle of rose like this:

@

@~@~@
@~@\@/@~@
\@|@|@|@/
\|///
\|//
|/
=&=
/|\

This is the rose in the rail:

The rose numbered as below:

  1
2   3

4 5 6
7 8 9 10

The rule of putting the rose in is to find a empty bay where the number is smallest and put the rose in.We can suppose he add the rose spend no time,the customer should wait after Small JH add the rose.
The shop opened at 8:00am and closed at 11:00pm(the customer can buy rose at 11:00pm but the boss will not add the rose at 11:00pm).He want to know the situation of the customer buy the rose and the placement of rose after 11:00pm.If the customer see the shop is closed,he will leave.

Input
The input will consist of several cases, please deal with till the end of file. Each case contains three integers N , T and M (0<N<13, 0<T, 0<M<=100) representing there are N rows of roses,small JH add the rose every T minutes and M customer.Then follow M*2 lines as below format:
hh:mm k
a1 a2…ak
stand for at hh:mm the customer want to buy k roses,ai means he wants the rose numberd ai.at the same time,only one customer into the shop.
the time is increase and 0 < k <= n*(n + 1)/ 2, 0 < ai <= n*(n+1)/2.

Output
For each customer, when the shop Not yet opened,print “Not yet open for business”. if he can buy at least one rose,please print “You bought X beams of rose”.X means the number of the customer have bought.otherwise,print “What a pity!”.
After all, print the state of rose.

Sample Input
2 1 1
8:00 1
2
2 10000 1
8:00 1
2

Sample Output
You bought 1 beams of rose
+---------------------+
| @ |
| @~@~@ |
| @~@\@/@~@ |
| @ \@|@|@|@/ @ |
| @~@~@\|///@~@~@ |
|@~@\@/@~@|/@~@\@/@~@|
|\@|@|@|@/|/\@|@|@|@/|
| \|/// =&= \|/// |
| \|// /|\ \|// |
| |/ |/ |
| =&= =&= |
| /|\ /|\ |
+---------------------+
You bought 1 beams of rose
+---------------------+
| @ |
| @~@~@ |
| @~@\@/@~@ |
| \@|@|@|@/ @ |
| \|///@~@~@ |
| \|/@~@\@/@~@|
| |/\@|@|@|@/|
| =&= \|/// |
| /|\ \|// |
| |/ |
| =&= |
| /|\ |
+---------------------+

  • 写回答

1条回答 默认 最新

  • 你知我知皆知 2024-07-27 15:21
    关注

    以下回答参考 皆我百晓生券券喵儿 等免费微信小程序相关内容作答,并由本人整理回复。

    这是一个典型的动态规划问题。我们可以将每个时刻的顾客分为两部分:已经购买了玫瑰的人和没有购买玫瑰的人。对于每一个时刻,我们只需要考虑那些还没有购买过玫瑰的顾客。

    我们需要使用一个数组来存储每个小时的未购买顾客的数量。在每一次操作之后,我们将这个数减去1,因为那个位置现在被一个新的顾客占据。

    当我们到达11点的时候,我们要检查一下数组中的所有值,如果有的时候是负数,那么就说明有人在这个时间点没有购买任何玫瑰,我们就输出"not yet open for business"。

    接下来,我们需要计算出到11点时有多少个顾客还没有购买任何玫瑰。这可以通过从N中减去当前的时间点开始的分钟数得到。

    最后,我们将所有的顾客都放入一个字符串中,并用逗号分隔,然后输出结果。

    下面是代码实现:

    # 定义函数
    function(N,T,M){
        # 初始化数组
        unacquired <- rep(0,N)
        
        # 遍历每一分钟
        for(t in 1:T){
            # 计算剩余未购买顾客的数量
            unacquired[N-t] <- unacquired[N-t-1]
            
            # 如果有新的顾客进入
            if(unacquired[t] > 0){
                # 将他们加入数组
                unacquired[t] <- unacquired[t] - 1
                
                # 检查是否有人没有购买任何玫瑰
                if(sum(unacquired) == 0){
                    return("not yet open for business")
                }
                
                # 如果有人买了玫瑰,将他们的数量加一
                if((t % M) >= 0 && ((t % M) * (M+1)) / 2 <= N){
                    unacquired[(t%M)] <- unacquired[(t%M)] + 1
                    
                    # 如果有顾客离开,将他们的数量减一
                    if((t % M) >= 0 && ((t % M) * (M+1)) / 2 < N){
                        unacquired[(t%M)] <- unacquired[(t%M)] - 1
                    }
                }
            }
        }
        
        # 返回结果
        return(paste("You bought",sum(unacquired), "beams of rose"))
    }
    
    # 测试数据
    print(function(N,T,M){ 
        print(rbind(c(N,T,M),sample(1:1000,3)))
    })
    

    请注意,这段代码需要你提供一些测试数据,以便你可以看到它的工作原理。

    评论

报告相同问题?

悬赏问题

  • ¥20 根据动态演化博弈支付矩阵完成复制动态方程求解和演化相图分析等
  • ¥15 Prism框架ItemControl元素绑定ViewModel中的命令失败
  • ¥20 关于DAC输出1.000V对分辨率和精度的要求
  • ¥20 想写一个文件管理器,加载全部子文件夹后,要一级一级返回
  • ¥15 华为超融合部署环境下RedHat虚拟机分区扩容问题
  • ¥15 哪位能做百度地图导航触点播报?
  • ¥15 请问GPT语言模型怎么训练?
  • ¥15 已知平面坐标系(非直角坐标系)内三个点的坐标,反求两坐标轴的夹角
  • ¥15 webots有问题,无响应
  • ¥15 使用VH6501干扰RTR位,CANoe上显示的错误帧不足32个就进入bus off快慢恢复,为什么?