5. 参加聚会(你觉得这些菜怎么样?How do you like these dished?)

原文链接:http://talk.oralpractice.com/article_9978.html

- How do you like these dishes?

- Fine, they are colorful and tasty.

- Did you enjoy your dinner?

- Yes, I did. I have never tasted anything like this.

- Would you like some more rice?

- No, thanks. I' m full.

- Another peice of meat pie?

-No, thanks. I'm on diet.

- How about the dessert?

- Ice cream, please.

你觉得这些菜的味道如何?

很好,色香味美。

晚餐吃得满意吗?

很满意,我从来没有吃过像这么好吃的东西。

要再来点米饭吗?

不要,谢谢,我已经吃饱了。

再来一块肉馅饼吧?

不用,谢谢。我正在节食。

要甜点吗?

请来点冰淇淋。

展开阅读全文

How Long Do You Have to Draw

10-28

Problem DescriptionnThere are two horizontal lines on the XoY plane. One is y1 = a, the other is y2 = b(a < b). On line y1, there are N points from left to right, the x-coordinate of which are x = c1, c2, ... , cN (c1 < c2 < ... < cN) respectively. And there are also M points on line y2 from left to right. The x-coordinate of the M points are x = d1, d2, ... dM (d1 < d2 < ... < dM) respectively.nNow you can draw segments between the points on y1 and y2 by some segments. Each segment should exactly connect one point on y1 with one point on y2.nThe segments cannot cross with each other. By doing so, these segments, along with y1 and y2, can form some triangles, which have positive areas and have no segments inside them.nThe problem is, to get as much triangles as possible, what is the minimum sum of the length of these segments you draw?n nnInputnThe first line has a number T (T <= 20) , indicating the number of test cases.nFor each test case, first line has two numbers a and b (0 <= a, b <= 104), which is the position of y1 and y2.nThe second line has two numbers N and M (1 <= N, M <= 105), which is the number of points on y1 and y2.nThe third line has N numbers c1, c2, .... , cN(0 <= ci < ci+1 <= 106), which is the x-coordinate of the N points on line y1.nThe fourth line has M numbers d1, d2, ... , dM(0 <= di < di+1 <= 106), which is the x-coordinate of the M points on line y2.n nnOutputnFor test case X, output "Case #X: " first, then output one number, rounded to 0.01, as the minimum total length of the segments you draw.n nnSample Inputn1n0 1n2 3n1 3n0 2 4n nnSample OutputnCase #1: 5.66 问答

What do you do for Singleton?

06-20

I see many programmers do singleton like:rnclass Singleton implements Irnstatic Singleton _inst = null;rnstatic I getInstance()if(_inst==null)_inst = new Singleton();return _instrnrnrnWell, it works.rnBut, think hard. why wouldn't you dornclass Singleton implements Irnstatic final Singleton _inst=new Singleton();rnstatic I getInstance()return _inst;rnrn?rnMuch simpler, right?rnrnMany programmers would say: "the first one is lazy initialization. So should be better."rnrnReally? by using the first one, what do you save? a Singleton object, right? rnrnBut how big is that? From my experience, a singleton is normally quite small. For a small object with 10-20 bytes, is it worthy the extra code "if(......)"? rnthe extra code will not use memory space anyway? rnand it makes your code unnecessarily more complicated.rnrndoes it worth the extra runtime overhead to check the reference everytime the getInstance() is called?rnrnAlso, programmer often ignore the thread-safety of the first approach.rnrnWhat if there are threads calling getInstance() concurrently? Do you need to place "synchronized" on your getInstance()? rnAnd if you place "synchronized", you may also feel uncomfortable because even for non-concurrent usage of your Singleton, you are also paying the locking overhead for each call against getInstance(). Painful!rnrnOf course, for big object, the lazy intialization is certainly useful. But, there's still another approach you may want to consider if the memory space for this big object is really something.rnrnthink about this: if every user of the singleton has finished using this singleton, do I still need to hold this object? Can I reclaim the memory space for it?rnrnThen, you may want to use WeakReference to further optimize it.rnrnfor example:rnrnclass Singleton implements Irnstatic WeakReference _inst = null;rnstatic I getInstance()rnrnif(_inst==null || _inst.get()==null)rn _inst = new WeakReference(new Singleton());rnreturn (I)_inst.get();rnrnrnrnIt works? rnWell, looks like. But no!rn(I give this wrong demo to show that sometimes introducing more code is probably introducing more chances to get bug.)rnrnYou may just return "null" sometimes. This is because of the WeakReference! It does not guarantee to hold the new Singleton instance for you.rnrnSo, a possible version would be:rnclass Singleton implements Irn static WeakReference _inst = null;rn rn static synchronized I getInstance()rn rn I ret;rn if(_inst==null)rn ret = new Singleton();rn _inst = new WeakReference(ret);rn rn elsern rn ret = (I)_inst.get();rn if(ret == null)rn ret = new Singleton();rn _inst = new WeakReference(ret);rn rn rn return ret;rn rnrnquite something to do!rn 论坛

Would you tell me how to do ? [SOS] C++ ->ASM

11-07

我想将下面程式中的init_port和send_port改成汇编。但我不识汇编,你能帮个忙吗?因我在Delphi 5.x开发了一个系统,在Delphi 5.x可使用ASM。rnrn#include rn#include rn#include rn#include rn#include rnrnvoid init_port(code)rnunsigned char code;rnrn union REGS r;rn rn r.x.dx = 0; /* com1 */ rn r.h.ah = 0; rn r.h.al = code;rn int86(0x14,&r,&r);rnrnrnvoid send_port(c)rnchar c;rnrn union REGS r;rnrn r.x.dx = 0; /* com1 */rn r.h.al = c;rn r.h.ah = 1;rn int86(0x14,&r,&r);rn if (r.h.ah & 128) rn printf("send error !\n");rn exit(-1);rn rnrnrn/************************/rnvoid setmode(mode)rnint mode;rnrn send_port(27);rn if (mode==1) send_port(17); /* mode 1: overwrite mode */rn if (mode==2) send_port(18); /* mode 2: overwrite mode */rn if (mode==3) send_port(19); /* mode 3: overwrite mode */rnrnrnvoid cleardisplay()rnrn send_port(12);rnrnrnvoid initdisplay()rnrn send_port(27);rn send_port(64);rnrnrnvoid writestring(cc)rnchar *cc;rnrn int i,len;rnrn len=strlen(cc);rnrn send_port(27);rn send_port(81);rn send_port(65);rn for (i=0;i<=len;i++) rn send_port(toascii(cc[i]));rn rn send_port(13);rnrnrnvoid setstatus(s1,s2,s3,s4,s5)rnint s1,s2,s3,s4,s5;rnrn send_port(27);rn send_port(81);rn send_port(67);rn send_port(s1+0x30);rn send_port(s2+0x30);rn send_port(s3+0x30);rn send_port(s4+0x30);rn send_port(s5+0x30);rnrn send_port(13);rnrnrnvoid setpoint(k,n)rnint k,n; /* n=1 On, n=0 Off 1=0;i--) rn setpoint(i,1);rn delay(1500);rn setpoint(i,0);rn rn printf("clear screen and display '888888888888' !\n");rn printf("cursor to home and 5 kinds of status LED on, press any key\n");rn getch();rn cleardisplay();rn cursorhome();rn writestring("888888888888\n");rn setstatus(1,1,1,1,1);rn printf("move cursor,press any key\n");rn getch();rnrn for (i=1;i<13;i++)rn rn cursorhome();rn setcursor(i);rn delay(1500);rn cleardisplay(); rn rn printf("press any to exit!"); rn getch();rn 论坛

How do you display progress to the user via LotusScript?

11-16

REM "From Erden Eruc @ NGSINC"rnrnrnDim i As IntegerrnDim s As Stringrn rn'Is this 100 meter dash? no it is a meter with 100 dashes :)rn rns = "--------------------------------------------"&_rn"--------------------------------------------------------"rnFor i = 1 To 100rn s = Left( Chr(1) & s, 100 )rn If i<10 Thenrn Print "Percent Done: "& Str(i)&"% - " & s rn Elseif i = 100 Thenrn Print "Percent Done:"& Str(i)&"% - " & srn Elsern Print "Percent Done: "& Str(i)&"% - " & srn End IfrnNextrnPrint "Percent Done: 100% - Job complete..."rnrnFor a Win32-specific version that uses Notes functions (note: this is a dangerous thing to do, but if you really must have a graphical progress bar..):rnConst NPB_TWOLINE% = 1rnConst NPB_STATUSBAR% = 32rnrnrnDeclare Function NEMProgressBegin Lib "nnotesws.dll" ( Byval wFlags As Integer ) As LongrnDeclare Sub NEMProgressDeltaPos Lib "nnotesws.dll" ( Byval hwnd As Long, Byval dwIncrement As Long )rnDeclare Sub NEMProgressEnd Lib "nnotesws.dll" ( Byval hwnd As Long )rnDeclare Sub NEMProgressSetBarPos Lib "nnotesws.dll" ( Byval hwnd As Long, Byval dwPos As Long)rnDeclare Sub NEMProgressSetBarRange Lib "nnotesws.dll" ( Byval hwnd As Long, Byval dwMax As Long )rnDeclare Sub NEMProgressSetText Lib "nnotesws.dll" ( Byval hwnd As Long, Byval pcszLine1 As String, Byval pcszLine2 As String )rnrn' From Mark Dixon @ IvesrnrnrnDim hwnd As LongrnDim i As LongrnDim j As Longrn rn'Create the progress barrnhwnd = NEMProgressBegin( NPB_TWOLINE )rn rn'Set the bar range - the default is 100rnNEMProgressSetBarRange hwnd, 200rn rn'Display some text on the dialog. The second line is ignored if NPB_TWOLINE not specifiedrnNemProgressSetText hwnd, "Calculating..", "Start"rn rnFor i = 0 To 200rn 'Simple delay loop to give us time to see whats going onrn For j = 0 To 5000 rn Nextrn 'Update the bar position - we could also use NEMProgressDeltaPos hwnd, 1 herern NEMProgressSetBarPos hwnd, i rn 'Update the text at halfwayrn If i = 100 Thenrn NEMProgressSetText hwnd, "Calculating", "Half way"rn End IfrnNextrnrn'Destroy the dialog when we're donernNEMProgressEnd hwndrn 论坛

没有更多推荐了,返回首页