Card game and answer program

xiaoxiao2021-04-08  445

Card game

Program file name

: card.cpp / card.pas / ...

NKPC

The players of the competition and Xiao Li often play a small game.

This game rule is simple

:

Xiaojin is holding in the hand

N

The card is written, and a positive integer is written on each card.

Xiao Li knows that the number of cards is different, but he doesn't know which one is the maximum.

At the beginning of the game, Xiao Jin alone took a card to Xiao Li, and asked Xiao Li.

"

Is this number bigger?

"

.

If Xiao Li replied

"

Yes

"

Then the game is ending; otherwise, a small re-draw a different card, repeat the above problems.

When only the last card left in the small gold hand,

So Xiao Li can only answer

"

Yes

"

.

If Xiao Li is just guessing the biggest value, that is, when Xiao Jin took the largest number, Xiao Li replied

"

Yes

"

He won.

recent

,

Xiao Li came up with a good way to find the biggest value:

For the first one to the first

M (1 <= m

Zhang card is answered

"

Do not

"

;

Then, from the first

M 1

Zhang begins, if the number on the current card is larger than the previously owned number

,

So answer

"

Yes

"

Otherwise answer

"

Do not

"

.

Maybe you have noticed

,

How is the most important thing in the method of Xiao Li?

M

Value.

Your goal is to make a program to help Xiao Li found the best.

M

value

,

Let Xiao Li win this game with the biggest probability.

enter

(Please use standard input and output, not to read and write)

Only one integer

N (3 <= n <= 100000)

Output

(Please use standard input and output, not to read and write)

Output is an integer

M

, Indicating the maximum probability of winning the effectiveness

M

.

Sample input

1

Sample output

1

3

1

Sample input

2

Sample output

2

5

2

#include #include #include #include #include #include

#define Number 100000INT A [Number] [100]; int N = 1000; int N = 5;

Void initiala () {TIME_T T; T = Time (null); clock_t goal; srand (unsigned) T); for (int i = 0; i <100; i ) {for (int J = 0; J clock ()); cout << "/ 1"; if (i% 10 = = 9) cout << i 1 << "%" << endl;}}

BOOL CMPI (INT I, INT M) // Treatment A [i], prior M. {INT mmax, max = 0; BOOL FLAG = false; mmax = a [i] [0]; for (int J = 1 J mmax && j max &&! flag) // puts the M sheet first than MMax value to max {MAX = a [i] [j]; flag = true;} else if (a [ I] [J]> Max && Flag) // Returns false return false;} if (! flag) Return False; Return True;}

INT DEALM (INT M) // Successful number of m-numbered {int SUC = 0; for (int i = 0; i

Void main () {int index = 0; int big = 0; int Temp = 0; char CH [10]; MEMSET (CH, 0, 10); Clock_t Goal; Cout << "Initialization Sequence ... << Endl; initiala (); cout << "input N, (1 > n; start: BIG = 0; for (int i = 1; i BIG) {BIG = Temp; INDEX = I;} IF (i * 100 / n% 1 == 0) // Output Progress IF (Clock () -goal> 5) cout << (i * 100 / n 1) << "%" << Endl;} Cout << "success rate:" << (float) BIG / (Number / 100) < <"%" << endl; cout << "selected best M =" << index << Endl; cout << "Continue calculation Please enter the number:" << Endl; cin >> CH; int K = 0 ; If (CH [0]> 0 '&& ch [0] <=' 9 ') {n = 0; while (ch [k]! =' / 0 ') {n = n * 10 ch [K] -'0 '; k ;} MEMSET (CH, 0, 10); goto start;} cout << "Press any key to end! << endl; getchar ();

转载请注明原文地址:https://www.9cbs.com/read-132738.html

New Post(0)