ÉèΪÊ×Ò³ ¼ÓÈëÊÕ²Ø

TOP

C++±à³Ì£¬Êý¾Ý½á¹¹£¬Ëã·¨ÀàÃæÊÔÌ⼯(6)(Ò»)
2014-11-24 01:26:01 ¡¾´ó ÖРС¡¿ ä¯ÀÀ:255´Î
Tags£º±à³Ì Êý¾Ý½á¹¹ Ëã·¨ ÊÔÌ⼯

151. ¸øÄãÒ»´®Êý×Ö£¬ÈÃÄãд³ÌÐò£¬°Ñ²Ù×÷·û£¨¿ÉÒÔÊÇÈÎÒâ¶à¸ö + ¨C * / %£©·Å½ø¸÷¸öÊý×ÖÖ®¼ä£¬Í¬Ê±»¹¿ÉÒÔÔÚÈÎÒâλÖ÷ŽøÀ¨ºÅ£¬ÈÃÕâ¸öËãÊõ±í´ïʽµÄÖµµÈÓÚÒ»¸ö¸ø¶¨µÄÊý×Ö¡£±ÈÈ磺¸øÄã 5 3 8 9 = 6ÄãµÄ³ÌÐòÓ¦¸ÃÊä³ö 5 * (4 + 8) % 9 = 6


CODE, 24µã


152. Ò»µÀ±à³ÌÌ⣬´óÒâÊǸø¶¨Ò»¸öÀàread1£¬ËüÓÐÒ»¸öº¯Êýread4096£¬Ã¿´Îµ÷ÓÃËü¿ÉÒÔ´ÓÎļþÖжÁÈ¡4K¸ö×Ö½Ú£¬Í¬Ê±Òƶ¯ÎļþÖ¸Õë4K¸öλÖã¨ÈôÎļþÖÐÊ£ÓàÊý¾Ý²»×ã4K£¬Ôò¶ÁȡʣϵÄËùÓÐÊý¾Ý£©£¬Õâ¸öº¯Êý·µ»Øʵ¼Ê¶ÁÈ¡µÄ×Ö½ÚÊý£¬intÐÍ£»ÒªÇóʵÏÖÁíÒ»¸öÀàread2ÖеÄÒ»¸öº¯Êýread£¬ËüÓÐÒ»¸ö²ÎÊýint n_byte£¬Õâ¸öº¯Êý¿ÉÒÔ´ÓÎļþÖжÁÈ¡ÓÉn_byteÖ¸¶¨µÄ×Ö½ÚÊý£¬Í¬Ñù·µ»Øʵ¼Ê¶ÁÈ¡µÄ×Ö½ÚÊý£»È»ºóÓÖ¸ø³öÒ»¸öº¯Êýreset£¬Ëü¿ÉÒÔ½«ÎļþÖ¸ÕëÖØÖõ½ÆðʼλÖã¬ÒªÇóʵÏÖread2ÖеÄÁíÒ»¸öº¯Êýseek£¬ÓÐÒ»¸ö²ÎÊýint pos
£¬Ëü¿ÉÒÔ½«»º³åÇøµÄÖ¸ÕëÒƶ¯µ½µÚpos¸ö×Ö½ÚµÄλÖ㬷µ»Øʵ¼ÊÖ¸ÕëÒƶ¯µ½µÄλÖ᣿ÉÒÔÔÚread2ÖÐÌí¼ÓÈÎÒâ±äÁ¿À´Íê³ÉÕâÁ½¸öº¯Êý¡£


¶à´Î×öread4096¼´¿É£¬ÎªÁ˼ÓËÙ£¬¿ÉÒÔÖØÓÃÉÏ´ÎseekµÄ½á¹û



153. ±à³ÌÌâÎʵÄÊÇboggleÓÎÏ·µÄÎÊÌ⣺¸ø¶¨Ò»¸ö4*4µÄ¾ØÕó£¬Ã¿¸öλÖÃÓÐÒ»¸ö×Öĸ£¬¿ÉÒÔ´ÓÒ»¸öλÖÃÌøתµ½ÖÜΧ°Ë¸öÏàÁÚλÖÃÖеÄÈκÎÒ»¸ö£¬µ«²»ÄÜÌøµ½ÒѾ­·ÃÎʹýµÄλÖã¬ÒªÇóÕÒ³öËùÓеĵ¥´Ê£¨¼ÙÉè¸ø¶¨ÁËÒ»¸ö´Êµä£©¡£http://en.wikipedia.org/wiki/Boggle


¹¹ÔìÒ»¸öµ¥´ÊµÄprefix×ֵ䣬ȻºóÔٵݹé+»ØËÝ¡£¡£¡£



154. Find median for k sorted arrays


Éèk¸ösorted arrayΪa1, a2, ¡­, ak.


ÏÈÕÒ³öÕâk¸ösorted arrayµÄmedian, m1, m2, ¡­ mk.


ÔÙÕÒ³öÕâk¸ömedianµÄmedian: mm


È»ºó¿ÉÒÔ°ÑËùÓбÈmmСµÄÊýºÍ´óµÄÊý¶¼È¥µô£¬´óÖÂÓÐÒ»°ë


È»ºóÔÙÕÒʣϵÄÊýµÄmedian£¨µÝ¹é£©£¬¸´ÔÓ¶ÈO(klogn)



155. ¡°Count and Say problem¡± Write a code to do following:
n String to print
0 1
1 1 1
2 2 1
3 1 2 1 1
¡­
Base case: n = 0 print ¡°1¡å
for n = 1, look at previous string and write number of times a digit is seen and the digit itself. In this case, digit 1 is seen 1 time in a row¡­ so print ¡°1 1¡å
for n = 2, digit 1 is seen two times in a row, so print ¡°2 1¡å
for n = 3, digit 2 is seen 1 time and then digit 1 is seen 1 so print ¡°1 2 1 1¡å
for n = 4, you will print ¡°1 1 1 2 2 1¡å


Consider the numbers as integers for simplicity. e.g. if previous string is ¡°10 1¡å then the next will be ¡°1 10 1 1¡å and the next one will be ¡°1 1 1 10 2 1¡å 10


CODE



156. ¸ø¶¨Ò»¸öÊý×飬 A[ 0 .... N ]×÷ΪÊäÈëÊý×é¡£¸ø¶¨Ò»¸öº¯Êý f(i,j) ,Õâ¸öº¯ÊýÒÔÁ½¸öϱí(i,j)ΪÊäÈ룬 ·µ»ØÒ»¸öÖµ¡£(Õâ¸öº¯ÊýÊǸöblackbox, ΨһµÄÐÅÏ¢¾ÍÊÇÊäÈëÁ½¸öÕûÊý·µ»ØÒ»¸öÖµ)¡£ÒªÇó°ÑÊý×éA·ÖΪ3·Ý£¬Ê¹µÃ f(0,a) + f(a,b) + f(b,N)×îС¡£
LEARN



157. ¸øn£ªmµÄ×Ö·û¾ØÕó¡£È»ºó¸øÄãÒ»¸ö×Ö·û´®¡£ÎÊÊÇ·ñ¿ÉÒÔÔÚ¾ØÕóÖÐÕÒµ½ËûµÄtrack¡£trackÊÇÖ¸´ÓÆä
ÖÐÒ»¸ö·û³ö·¢£¬¿ÉÒÔÏòËÄÖÜ×ߣ¬¿ÉÒÔÖظ´£¬¿ÉÒÔ»ØÍ·¡£
e.g:
a b
c d
string: ¡®bdba¡¯ could be found but not for ¡®bcd¡¯.


µÝ¹é+»ØËÝ£¬Ò²¿ÉÒÔÓÃDPÓÅ»¯



158. Given three linked list of integers, all sorted. Find the first shared integer in all three. What is the time complexity


ÂÔ¡£¡£¡£



159. Initially you have a 2¡Á2 matrix, say zoom1:
a b
c d
zooming it results in a 4¡Á4 matrix (zoom2) as follows:
aa ab ba bb
ac ad bc bd
ca cb da db
cc cd dc dd
zooming it again will result in an 8¡Á8 matrix and so on..
aaaa aaab abaa abab baba babb bbba bbbb
aaac aaad abac abad babc babd bdba bdbb
acaa acab adaa adab bcba bcbb bdba bdbb
acac acad adac adad bcbc bcbd bdbc bdbd
caca cacb cbca cbcb dada dadb dbda dbda
cacc cacd cbcc cbcd dadc dadd dbdc dbdd
ccca cccb cdca cdcb dcda dcdb ddda dddb
cccc cccd cdcc cdcd dcdc dcdd dddc dddd
The question is, given a sequence say abaaccda¡­ we need to find out the
sequence coming just left to it. For e.g. if the given sequence is ¡°bd¡± for
zoom2, the sequence coming just left to it is ¡°bc¡±. For ¡°cd¡± it¡¯s ¡°cc¡± etc.


CODE



160. ÈçºÎÔÚbinary treeÕÒÒ»¸öpath ´Óroot µ½leaf, ºÍÊÇsum
2)
ÈçºÎÐòÁл¯Ò»¸öbinary treeµ½Ò»¸öÎļþ
3)
Èç¹ûÓÐÒ»¸öÒѾ­ÐòÁл¯µÄtree, ºÜ´ó£¬Òª×ö1)µÄËã·¨£¬Ôõô×ö£¬2£©ÖÐÈç¹ûÓжà¸ö·½·¨Ñ¡ÔñÄÄÖÐÐòÁл¯µÄ·½·¨±È½ÏºÃ£¿
4
£© Èç¹ûÓÐ1000w¸öÒѾ­ÐòÁл¯µÄСÎļþ£¬¶ÔËûÃǶ¼Òª×ö3£©£¬ÈçºÎÌá¸ßÐÔÄÜ£¬ÏµÍ³ÊÇ5̨»úÆ÷


TO LEARN



161. Programming: interval halving. Given a continuous function ¡®f(x)¡¯ and an interval on the x-axis from ¡®start¡¯ to ¡®end¡¯. It is know that ¡®f(x)=0¡ä for exactly one value of ¡®x¡¯ between ¡®start¡¯ and ¡®end¡¯, and that ¡®f(x)¡¯ crosses the x-axis at this point. Write a program that repeatedly cuts in half the interval until the interval containing ¡®f(x)=0¡ä is equal or less than ¡®epsilon¡¯ wide.


ÂÔ¡£¡£¡£



162 [Facebook] You are given N ranges of date offsets when N employees are present in an organization. Something like
1-4 (i.e. employee will come on 1st, 2nd, 3rd and 4th day )
2-6
8-9
..
1-14
You have to organize an event on mi

Ê×Ò³ ÉÏÒ»Ò³ 1 2 ÏÂÒ»Ò³ βҳ 1/2/2
¡¾´ó ÖРС¡¿¡¾´òÓ¡¡¿ ¡¾·±Ìå¡¿¡¾Í¶¸å¡¿¡¾Êղء¿ ¡¾ÍƼö¡¿¡¾¾Ù±¨¡¿¡¾ÆÀÂÛ¡¿ ¡¾¹Ø±Õ¡¿ ¡¾·µ»Ø¶¥²¿¡¿
ÉÏһƪ£º.net³ÌÐòÔ±ÃæÊÔÊÔÌâ(Ò») ÏÂһƪ£ºC++±à³Ì£¬Êý¾Ý½á¹¹£¬Ëã·¨ÀàÃæÊÔÌâ..

×îÐÂÎÄÕÂ

ÈÈÃÅÎÄÕÂ

Hot ÎÄÕÂ

Python

C ÓïÑÔ

C++»ù´¡

´óÊý¾Ý»ù´¡

linux±à³Ì»ù´¡

C/C++ÃæÊÔÌâÄ¿