6-2.社交友谊(她总是迟到 She's Always late)

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

- I guess you're just wasting your breath then. Time means nothing to Jenny. 

- You're right. I guess I should just stop doing things with her.

- You don't have to go that far. Just don't waste your time waiting for her.

- I guess you're right. I could just tell her to meet me at the restaurant or movie.

- Right. Then if she's late, you know, it's her problem not yours.

- Thanks for your advice! I appreciate it! 

那我想你确实是徒劳了。时间对珍尼来说是没有用的。

是啊。我想我以后不跟她交往了。

你倒没必要那么过分。只要别再浪费时间等她就行了。

我想你说得对。那我就让她在饭馆或是电影院等我。

对。那样的话,她若迟到就是她的问题而与你无关。

谢谢你的建议。非常感谢!

展开阅读全文

It's Never Too Late

05-05

A shepherd has several sheep, and every evening when he finishes herding, he just encloses all sheep in the sheepfold and then goes to bed. The sheepfold, which can be regarded as a polygon on the ground, is made up with many pieces of wooden fences. This morning the shepherd found that one of his sheep is missing. After examining, he found that a piece of fence is broken. And the unlucky sheep is possibly eaten by a wolf which came through the broken fence last night. The shepherd soon recognized that if he does not mend the sheepfold, he will lose a sheep every night from now on. However, since the broken piece cannot be used anymore, he has to reorganize the other pieces to make a new enclosure. As shorter fences are more likely to be broken (the broken piece is the shortest one), he decide to join some of the original fences to make longer fences, and make the new sheepfold as a rectangle, which is a shape with both long edges and large area. But since the original fences are all manufactured separately, they can only be joined at the ends. And if an original piece is divided into two or more pieces, all of them will be useless. Now with all the lengths of fences in the original sheepfold measured, the shepherd wonders how large the new sheepfold can be at most. (Sheep need large space to grow well) But he is only good at herding and do not know how to calculate it, can you help him?nnInputnnEach test case begins with a line with only an integer N (3 <= N <= 17), the number of pieces in the original sheepfold. The next line contains N integers L1, L2 ... LN, (0 < Li <= 10,000, 1 <= i <= N), represent the length of each piece.nnThere are no more than 120 test cases in the input, processing to the end of file.nnOutputnnFor each test case, print a line with the maximum area of the new sheepfold on its own. If it is impossible to make a valid sheepfold, print -1 instead.nnSample Inputnn7n1 1 3 3 4 5 7n7n9 1 9 5 6 2 10nSample Outputnn15n-1n 问答

SHE的疑问?

10-26

先介绍了一下SEH在VC中的体现,就是__try/__except关键字,在__excep后面的()中是一个表达式,值可以是:rnEXCEPTION_CONTINUE_EXECUTION(–1):异常被忽略,控制流将在异常出现的点之后,继续恢复运行。rnrnEXCEPTION_CONTINUE_SEARCH(0):异常不被识别,也即当前的这个__except模块不是这个异常错误所对应的正确的异常处理模块。系统将继续到上一层的try-except域中继续查找一个恰当的__except模块。rnrnEXCEPTION_EXECUTE_HANDLER(1):异常已经被识别,也即当前的这个异常错误,系统已经找到了并能够确认,这个__except模块就是正确的异常处理模块。控制流将进入到__except模块中。rnrn其中例子有:rn[code=C/C++]rn#include "stdafx.h"rn#include rnrn#define VAR_WATCH() printf("nDividend=%d, nDivisor=%d, nResult=%d.\n",\rn nDividend, nDivisor, nResult)rnrnint _tmain(int argc, _TCHAR* argv[])rnrn int nDividend = 22, nResult = 100;rn volatile int nDivisor = 0;rnrn /*nDividend++;rnrn _asm INT 3;rnrn _asmrn rn mov eax, eaxrn __asm _emit 0xcd __asm _emit 0x03rn noprn noprn rnrn DebugBreak();*/rnrn __tryrn rn printf("Before div in __try block.\n");rn VAR_WATCH();rnrn nResult = nDividend / nDivisor;rnrn printf("After div in __try block.\n");rn VAR_WATCH();rn rn __except(printf("In __except block.\n"), VAR_WATCH(),rn GetExceptionCode() == EXCEPTION_INT_DIVIDE_BY_ZERO ? rn (nDivisor = 1, printf("Divide zero exception detected.\n"), VAR_WATCH(), EXCEPTION_CONTINUE_EXECUTION) : rn (EXCEPTION_CONTINUE_SEARCH))rn rn printf("In handler block.\n");rn rnrn return 0;rnrn[/code]rn这段程序想演示一个recover exception的技巧,在C/C++中,用逗号串起来的表达式还是一个表达式,这个整体表达式的值是最后一个表达式的值,所以如果GetExceptionCode()结果是EXCEPTION_INT_DIVIDE_BY_ZERO,那么结果就是EXCEPTION_CONTINUE_EXECUTION,而之前的表达式也会被evaluate,nDivisor = 1,prinf函数也会执行,这样,在这个thread回去再次执行nResult = nDividend / nDivisor的时候,nDivisor已经是1了,于是是不会再次有异常发生。真的是这样吗?rn如果是VC 6.0执行结果正确,如果是VC 6.0以后那么执行会导致死循环?rnrn我分别用VC6.0 和 VC2008 的Debug mode去追这个问题,发现生成的asm code不同,一个是rnVC2008:rnidiv eax,ecx //ecx即为变量nDivisor的值,后面当nDivisor的值修改后,ecx的值也会变为1rnVC 6.0 rnidiv eax, [nDivisor Address] //这个更不用讲了,当nDivisor修改后,重新去执行idiv这条指令的话,nDivisor也为1.rnrn这个问题真是找不到原因?rnrn[color=#FF0000]不过大家要注意一点:[/color]1) __except(EXCEPTION_CONTINUE_EXECUTION)是让thread回到发生exception的机器指令,不是回到发生exception的C/C++语句;rn 论坛

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