October 9, 2012 Alibaba Test (C + +)

Source: Internet
Author: User

Turn from: http://blog.csdn.net/liuzhanchen1987/article/details/8058177


1.BMP format image, the depth of the image is 24 bits, the space of a 512*1024 lattice image is how much. [HTML] view plain copy answer: (24/8) B*512*1024=1.5m


2. The decimal number-3 is converted to 3 in the complement of the result is how much. [CPP] view plain copy Answer:-3 can be expressed as: sign bit minus sign can be expressed as 1, 3 is decimal, can be expressed as 13, converted into a three to 110 (symbol bit unchanged, 3 conversion to 10), the calculation of the complement is the source code plus 1, 110 of the Counter Code is 112 (the highest bit is the symbol bit unchanged, 10 back code is 12 (because the inverse code of the triple in 1 is the 1,2 of the inverse code for the 0,0 is 2)), the counter code plus 1 is 120.


3. Two processes execute the following code at the same time, where the impossible result is: [HTML] view plain copy code as follows: a=5;   a=a+1; printf ("%d", A);


A 5,6 B 6,5 C 6,7 D 7,6

A: b,d, the option is not very clear, the answer is not very sure, look at Daniel Pointing.

4.pid_t pid=fork ();

if (pid<0)

cout<<-1<<endl;

else if (pid==0)

cout<<0<<endl;

Else

cout<<1<<endl;

The Impossible answer is:

A 0 B 1 C 1,0 D 0,1 [CPP] view plain copy answer to be determined. C,d should be possible.


5 forgot.

6.6 pairs of different socks, four, just have a pair of socks situation there are several. [CPP] view plain copy: 6* (C (10,2)-5) =240. Of these, C (10,2) is the type of 2 selected from 10 socks.


7.32 bits and can handle more than 4G of memory. [CPP] view plain copy cannot because 32 is the largest 4G, even if all of the memory storage address, and do not store data, can only put 4G of memory.


8. Trees are sometimes faster than hashes.

I'm not sure.

9. Briefly describe the LRU algorithm[CPP]View plain copy What is the LRU algorithm?   LRU is the abbreviation for least recently used, the least recently used page replacement algorithm, for virtual-page storage Management services. As for the memory management of the operating system, how to save the use of small capacity of memory to provide resources for the most process has been an important direction of research. and the virtual storage management of memory, is now the most common, most successful way--in the case of limited memory, the expansion of a part of the external memory as virtual RAM, the real memory only to store the current run-time use of information. This undoubtedly greatly expands the function of memory, greatly increasing the concurrency of the computer.   Virtual page Storage Management, it is the process required to divide the space into multiple pages, in memory only the current required pages, the rest of the page into the management of external storage. However, the benefits have disadvantages, and virtual page storage management reduces the memory space required for the process, but it also brings the shortcoming that the running time becomes longer: During the process of running, it is unavoidable to exchange some information stored in the store and in memory, due to the low speed of external storage, the time that this step takes cannot be neglected.   Therefore, the use of the best possible algorithm to reduce the number of memory to read, but also a very meaningful thing. For virtual page storage, the replacement of the inside and outside of the information is in the page for the unit-when you need a place in the external memory of the page, put it into the RAM, at the same time in order to maintain the size of the original space, but also to the memory page out to the external storage. Naturally, the fewer such transfers, the greater the efficiency of process implementation. So, which page to pull out can achieve the goal of less mobility.   We need an algorithm. Naturally, the algorithm to achieve such a situation is the most ideal-every time the page is swapped out is the latest in all memory pages will be used-this can be the maximum Delay page exchange, this algorithm, known as the ideal page replacement algorithm. Unfortunately, this algorithm is not possible. Edit this gap in order to minimize the gap with the ideal algorithm, resulting in a variety of subtle algorithms, the least recently used page replacement algorithm is one of them. The LRU algorithm is based on the fact that pages that are frequently used in the previous instructions are likely to be used frequently in the following instructions. Conversely, pages that have not been used for a long time are likely to not be used for a longer period. This is known as the local principle-faster than the memory speed cache, but also based on the same principle of operation. Therefore, we only need to find the most recently used page to recall the memory each time we swap. This is the entire content of the LRU algorithm.


10. There is a, B two boxes, a box of 800 red balls, 200 blue ball, B in the 200 red ball, 800 blue ball (back of the forgotten, remember to write again)

11.N unordered Integer, known as number I in the sorted sequence of the position of J, satisfying |i-j|<=k, please design a sorting algorithm, the sequence is sorted. Note: The algorithm time complexity of O (NLGN) is 0 points, the complexity of O (NK)

Scored two points, with a total score of 20 points. [CPP] view Plain copy a: the smallest number from the above conditions must be in the first k, so you can speak the number of K to build a minimum heap, and then take the root element out, the root element is the smallest number, and then the number of k+1 into the heap, Because the second small number is certainly in the subscript 1 to k+1 position range, so after adjusting the minimum heap, the root element is the second small element, take out the element, put the first k+2 elements into the heap, ... And so on, the order in which elements are taken out of the heap is the sequence that is already sorted. The algorithm has a time complexity of O (NLGK), specifically (N-K) lgk,


12. There is a string arrangement a,b,c,d,aa,ba,ca,da,ab,bb,cb,db,ac,bc,cc,dc,ad,bd,cd,dd ....

Programming implementation: 1.ababab is the first few strings.

2, what is the 78th string.

3. The nth string is what. [CPP]   View plain copy looks more abstract at first, but if we invert each string backwards, the problem becomes much clearer and we add the following mappings: a---1, b---2,c---3, D---4, then the above each string backwards and forwards before the digital mapping becomes: 1,2,3,4,11,12,13,14,21,22,23,24,.......... is not very familiar with, very much like the four-way coding bar. Just change 0 to 4, if you find the position of a string, then do a digital mapping after the calculation is much simpler, such as Ababab Flip after the Bababa, converted to the number is: 212121, Position is ((((2*4+1) +2) *4+1 *4+2) *4+) 1 is to make a special four to decimal conversion. With this idea the following topic is good long.   

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.