Home > other >  Blue cup problem
Blue cup problem

Time:10-26


Win tickets to

Some institutions hold grand prix tickets, winning players a chance to win a number of seats,

Host out of N CARDS (with 1 ~ N number), order, arranged in a circle,
You can count clockwise from any card: 1, 2, 3...
If the count to the number and card Numbers are the same, just put the card, again from the next card counting,
Until no longer gain any CARDS, game over, card number and the weights is the winning ticket number,

For example:
CARDS are listed: 1 2 3
We start with 1 card number, just take 1 card, again from the beginning of the 2nd card, but the number of figures with CARDS,
Number increasing quickly, and could no longer take the card, so this time we won only 1 tickets,

It's not too bad! Silly if we start to count from 2 or 3 CARDS, then couldn't get her a card,

With luck, card arrangement is 1 2 3
That we can get all the CARDS!

Subject's aim is: clockwise card sequence is known,
Whatever you where to start, how many tickets for up to win (is the card number with the sum)

Data input:
The first line of an integer N (N<100), said the card number
The second line of N integers, said clockwise order CARDS

The output data:
A line, an integer, best can win how many tickets

For example:
User input:
3
1 2 3

The program should output:
1

For example:
User input:
3
1 2 3

The program should output:
6


Resources agreed:
Peak memory consumption & lt;
256 mCPU consumption & lt; 1000 ms



Output according to request, please don't gild the lily print similar: "please enter... "The redundant content,

All in the same source code file, after debugging through, copy submitted to the source code,
Note: do not use package statements, do not use jdk1.7 and version of the above characteristics,
Note: the Main class name must be: the Main, or else the invalid code processing,

CodePudding user response:

Save me, and give some ideas
  • Related