编程介的小学生 2019-08-19 22:56 采纳率: 20.5%
浏览 73

C语言的程序,解决Box Betting问题

Problem Description
Theres a new delivery boy at your company, supposed to drive around delivering a specific number of items to difierent locations. He needs to deliver at least X of an item, while the truck can at most take Y of the item.

If there are more, the truck is will to break down due to the weight. If there are less, that means he hasn't fulfilled the assignment. At the loading station, there's a row of boxes he can bring along.

Each box contains a specified number of items. This driver isn't the sharpest snail on the rock, however. Since he's also too shy to ask for help, he's decided to just choose one entirely random starting point in the row of boxes. Then he chooses a random end point among the boxes from the starting point to the end, inclusive.

All the boxes between those points (inclusive) are loaded onto the truck. You and the other employees have started betting on whether or not the truck breaks
down, he brings to few items along or if he should happen to be lucky enough to fulfil the assignment without any problems. This gets you wondering. What is the actual probability for each of these scenarios to occur? Assume for the sake of this problem that the driver will always be able to fit all the boxes into the truck (after all, he had to have SOME skill, seeing as he was hired).

Input
The input will start with a line containing a single number T, the number of test cases.

Each test case consists of three lines. The first one contains a single number N, the number of boxes. The second line contains a sequence of N characters (A-Z), B1B2...BN (no whitespace), representing the amount of items in each of the boxes in the same order as they're located on the loading dock. An A represents an empty box, B a box with 1 item, and so on until Z, which represents a box with 25 items in it. The third line contains the two numbers L and U. L is the number of items the driver is supposed to deliver, while U is the maximum number of items the truck can take before it'll break down.

Output
For each test case, output three floating point numbers on a single line. The first number gives the probability that the driver succeeds, the second one that that he brings along too few items, and the third one that the truck breaks down.

Notes and Constraints

0 < T <= 100

1 < B <= 200000

'A' <= Ai <= 'Z'

0 <= L <= U <= 50000

Both the starting and ending points of the segment are chosen with a uniform
probability distribution.

Any answer within 10^-6 of the correct one will be accepted.

Sample Input
2
4
KCHA
2 9
3
BCD
4 5

Sample Output
0.5 0.25 0.25
0.16666667 0.72222222 0.11111111

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 名为“Product”的列已属于此 DataTable
    • ¥15 安卓adb backup备份应用数据失败
    • ¥15 eclipse运行项目时遇到的问题
    • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
    • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
    • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
    • ¥50 成都蓉城足球俱乐部小程序抢票
    • ¥15 yolov7训练自己的数据集
    • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
    • ¥15 电力市场出清matlab yalmip kkt 双层优化问题