编程介的小学生 2017-03-23 12:13 采纳率: 20.5%
浏览 772
已采纳

Edison

It is said that Columbus once invented card games. After thousands of years, all kinds of card games have spread all over the world. Shuffling the deck is an inevitable task, because no one wants to play the same game twice. There are usually 54 cards in a deck, and we usually shuffle the deck by repeatedly taking out a sequence of cards and put them onto the top of the deck. The following figure illustrates the effect of a single shuffle.

A single shuffle with P = 2 and L = 3 will move the white cards onto the top

To help people shuffle, Edison invented a machine, namely Automated Card-shuffling Machine. The machine is controlled by instructions, which give the starting position P and the length L of the sequence. Of course the instructions are generated by a randomizer. Unfortunately it is discovered that the randomizer has a bug that leads to repetitive instructions. That is, several consecutive instructions may be exactly the same. Though despaired, Edison decides to pack the repetitive instructions into a single "extended instruction" and ship this machine off to the market. An extended instruction consists of not only P and L for a sequence, but also the number of times R it repeats.

Input Description

Standard input will contain multiple test cases. The first line of the input is a single integer T (1 <= T <= 10) which is the number of test cases. T test cases follow, each preceded by a single blank line.

The first line of each test case contains two integers C (0 < C <= 1,000,000) and S (0 <= S <= 5,000). The deck holds C cards, numbered from 0 to C - 1, and we will do S shuffles.

The following S lines contain three integers each, Pi (0 <= Pi < C), Li (1 <= Li <= C) and Ri (1 <= Ri <= 100), 1 <= i <= S. Each line represents an extended instruction. Note that the card on the top has a position of 0. It is guaranteed that Pi + Li <= C.

Output Description

Results should be directed to standard output. Start each case with "Case #:" on a single line, where # is the case number starting from 1. Two consecutive cases should be separated by a single blank line. No blank line should be produced after the last test case.

For each test case, print the sum of the card numbers at odd positions of deck after shuffling.

Sample Input
2

10 1
5 3 1

10 3
5 3 1
2 4 1
7 2 2

Sample Output
Case 1:
24

Case 2:
23

HINT: The cards on the decks after shuffling would be:
Case 1 �C 5 6 7 0 1 2 3 4 8 9 (5 + 7 + 1 + 3 + 8 = 24)
Case 2 �C 6 3 4 8 7 0 1 2 5 9 (6 + 4 + 7 + 1 + 5 = 23)

  • 写回答

2条回答 默认 最新

查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误