"UVA11384" help was needed for Dexter (math problem ...) )

Source: Internet
Author: User

Problem H

Help are needed for Dexter

Time Limit:3 Second

Dexter is tired of Dee Dee. So he decided to keep Dee Dee busy in a game. The game he planned for she's quite easy-to-play but isn't easy-to-win at least don't for Dee Dee. But Dexter does not has time to spend on this silly task, so he wants your help.

There would be a button and when it would be pushed a random number N would be chosen by computer. Then on screen there'll be numbers from 1 to N. Dee Dee can choose any number of numbers from the numbers on the screen, And then she'll command computer to subtract a positive number chosen by hers (not necessarily on screens) from the Selec Ted numbers. Her objective'll be and make all the numbers 0.

For example if N = 3, then on screen there'll be 3 numbers on Screen:1, 2, 3. Say She now selects 1 and 2. Commands to subtract 1, then the numbers on the screen would be:0, 1, 3. Then she selects 1 and 3 and Commands to subtract 1. Now the numbers is 0, 0, 2. Now she subtracts 2 from 2 and all the numbers become 0.

Dexter is isn't so dumb to understand the This can be do very easily, so-make a twist he'll give a limit L for each N and surely L'll be as minimum as possible so it's still possible to win within L moves. But Dexter does not has time to think how to determine L for each n, so he asks you to write a code which would take N as Input and give L as output.

Input and Output:

Input consists of several lines each with N such that 1≤n≤1,000,000,000. Input would be terminated by end of file. For each N output L in separate lines.

SAMPLE INPUT

OUTPUT for SAMPLE INPUT

1

2

3

1

2

2

Problemsetter: Md. Mahbubul Hasan


Give the number n to program all the numbers in the sequence 1-n with the least number of operations 0 each operation can select one or more numbers from the sequence and subtract an identical positive integer

Through the analysis of the topic we can consider the next question if there are n numbers but these numbers are only 1, 2, and 3 of the cases according to the rules of the game they and the n=3 of the problem can be said to be equivalent you can try to say that in order to be a problem simple one n problem must be resolved into a simpler problem than this For this we will find a recursive formula for this problem.

Think about it if every time we subtract a N/2 from the average number, the problem becomes N/2.

For example, when N=6 is 4,5,6, and subtracting a 3, the data becomes {1,2,3,1,2,3} This problem is equivalent to n=3.

So get the recursive formula F (n) =f (N/2) +1

#include <iostream> #include <cstdio> #include <cstring>using namespace Std;int alpha (int m); int main ( ) {    int n;    while (scanf ("%d", &n)!=eof) {        printf ("%d\n", Alpha (n));    }    return 0;} int alpha (int m) {    return m = = 1? 1:alpha (M/2) + 1;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

"UVA11384" help was needed for Dexter (math problem ...) )

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.