Solving the problem of Baidu 3-channel algorithm

Source: Internet
Author: User

First question:
A company held a badminton game, there are 1001 individuals to participate, now in order to evaluate the " most powerful person ", the knockout, ask at least how many times to play.

Second question
There are three bulbs, the first round of all the bulbs are turned on, the second round of the odd bit of the light bulb off, the third round every two bulbs, one off, open one, and so on. Light bulb after the wheel.

The second topic is wrong: re-describing it again,sorry:

100 light bulbs in a row, the first round will be all the bulbs open;
Turn off one bulb at a second round every other. The even-numbered bulbs are turned off,
The third round of every two bulbs, will open the light bulb off, turn off the light bulb to open.
And so on, at the end of the nth round, there are a few light bulbs on.


Third question
There are a number of groups, each array has a number of groups, descending order, each number is the unit of the three-bit , to find out the 10000 number of the largest 500 A.

One

1. If the internal rankings are not considered, only the " strongest " person is sought. The number of nodes with a full binary tree with 1001 nodes at the lowest level of 2
2. three Loops
3.5 Road Merge sort?

Two

The first cannot use the binary number can only use the N2 time Correlation algorithm , because must choose the most formidable , because is the race is not the sort So there will be a situation that is the case of stone scissors cloth, so 22 to play a game, to see who won more than the number of innings.

Three

#include <stdio.h>

#define PRINT {for (i = 0; i < i++) printf ("%d", Ar[i]);p rintf ("\ n");}

0 off.

Not 0 open.

int main (void)

{

int ar[100] = {0};

int i;

int times;

int n;

int t;

printf ("n =?:");

scanf ("%d", &n);

for (i = 0; i <; i++)

Ar[i] = 1;

for (t = 1; t < (n%); t++)

{

for (i = 0; i <; i + = (t + 1))

Ar[i] =!ar[i];

PRINT

}

for (i = 0, times = 0; i <; i++)

if (ar[i]! = 0)

times++;

printf ("%d", times);

return 0;

}

Four

1.1000
2. The bulb is numbered starting from 1, and all bulbs with a full square number (1,4,9,..., 100) will be lit at the end. PS. This is a classic question.
3. I just saw a similar topic yesterday. The following n=10000,m=500, there are three methods.
[1] sort. O (NLOGN)
[2] The first array is established MIN-HEAP, all other array members are inserted sequentially into min-heap, each time the insertion is completed, the current minimum value, the root element, is deleted. After all the elements have been sifted, the elements in the Min-heap are the largest 500. O (NLOGM).
[3] Merging 20 arrays into 1, connected next to each other, does not have to be guaranteed to be orderly. Randomly selects an element in the merged array, and then places all elements smaller than this element on its left side, greater than to the right. If the original selected element is just in the No. 500 position of the right number, the element that starts right from it is the desired one. Otherwise, if the number of right-side elements is greater than 500, this method is used recursively for the right-end sequence, or, if the number of left-side sequences is greater than 10000-500, this method is used recursively for the leftmost sequence. Complexity of expected O (n).
[2] and [3] are not used in the original array of ordered characteristics, I think it should be improved.

Solving the problem of Baidu 3-channel algorithm

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.