| Wenbin's profileWenbin Dai's SpacePhotosBlogLists | Help |
|
November 17 How to choose between arrays and collections (.NET)Arrays are the fastest of all collection types, so unless you need special functionalities like dynamic extension of the collection, sorting, and searching, you should use arrays. If you need a collection type, choose the most appropriate type based on your functionality requirements to avoid performance penalties. ● Use ArrayList to store custom object types and particularly when the data changes frequently and you perform frequent insert and delete operations. Avoid using ArrayList for storing strings. ● Use a StringCollection to store strings. ● Use a Hashtable to store a large number of records and to store data that may or may not change frequently. Use Hashtable for frequently queried data such as product catalogs where a product ID is the key. ● Use a HybridDictionary to store frequently queried data when you expect the number of records to be low most of the time with occasional increases in size. ● Use a ListDictionary to store small amounts of data (fewer than 10 items). ● Use a NameValueCollection to store strings of key-value pairs in a presorted order. Use this type for data that changes frequently where you need to insert and delete items regularly and where you need to cache items for fast retrieval. ● Use a Queue when you need to access data sequentially (first in is first out) based on priority. ● Use a Stack in scenarios where you need to process items in a last–in, first-out manner. ● Use a SortedList for fast object retrieval using an index or key. However, avoid using a SortedList for large data changes because the cost of inserting the large amount of data is high. For large data changes, use an ArrayList and then sort it by calling the Sort method. November 12 Why loving LOTR so much1. My heroism and idealism. 2. It's a simple world, good is good, bad is bad. 3. Even if we're so small to understand why, we can change the world. 4. Love, courage, loyalty, faith. Pay attention to the overflow of Int32下面的代码计算Euler's Totient function。 #define MAXN 10000000 int mm[MAXN + 5]; void run() { FOR(i,2,MAXN-1) mm[i] = i; REP(i,pcount) { int p = plist[i]; for (int s = p; s < MAXN; s += p) { mm[s] = mm[s] * (p - 1) / p; } } } 其中pcount表示小于MAXN的素数的个数,plist则存储了这些素数。 代码looks good,但是仔细一看就会发现,虽然单个Int32的phi值是小于它自己的(这里的最大值是10^7所以看起来没问题),但是中间那一步计算 mm[s] = mm[s] * (p - 1) / p; 却有可能中间值溢出,导致最后的结果错误,改成下面酱紫就okay了 mm[s] = (LL) mm[s] * (p - 1) / p; November 08 纳斯里征服酋长球场阿森纳球迷可以容忍球队一年只赢两场球:一场是主场对曼联,一场是客场对曼联。 今天的比赛可以说是困难重重,阿德巴约、范佩西都不能上。不过窃以为范佩西不上反而倒是好事。 开场阿穆尼亚就手接回传球违例,被罚禁区内间接任意球,还好曼联射的也不咋的。然后第8分钟又几乎被曼联搞进去,幸好贝托越位进球无效。被打了两拳,厂队终于站稳脚跟,开始提出华丽的传接球。也亏的是曼联这种级别的对手,不会缩在后场打铁桶阵,大家放开了手脚踢对攻,厂队是不惧任何对手滴。于是有了两次极有威胁的边路传中,可惜小本子虽然很努力,还是与进球差之毫厘。不过此时就看出,纳斯里今天状态极佳,在曼联后场突来突去,游刃有余啊。 终于22分钟打破僵局,小法任意球被贝托解围,纳斯里禁区左路施舍,打中加里内维尔折射入网,1:0。但之后形式倒有点危险,加拉斯和萨尼亚先后吃到黄牌,C罗禁区左侧任意球又险些造成克里希乌龙。终于好不容易挺过上半场。 下半场开场纳斯里又给大家一个惊喜,小法中路妙传,纳斯里赶在维迪奇封铲前暴射入网,看得那叫一个爽啊。以后我厂都这么打就好了,不要老是想的要把球带进球门才作数。后面就开始处于守势了,但是反击也打得曼联很头疼,解说说的好,小法传球的那不是脚,是刀。中间阿穆尼亚英勇负伤,法比安斯基粉末登场,不过90分钟时被曼联小将拉斐尔打进一记漂亮进球。 然后裁判给出6分钟补时!不是不能超过5分钟的么!不过好歹挺过去了,继续保留夺冠希望。 纵观全场,纳斯里攻防有度,而且心理素质极佳,号称齐达内接班人并非浪得虚名啊。小法一如既往的组织全队,送出威胁球。小本子很努力,头球也有一定威胁,但脚下功夫确实糙了点,几个门前的准单刀换成大帝都不知道打进几个了。迪亚比给人眼前一亮的感觉,控球很好很稳啊,我还一直以为是糙哥呢。小老虎今天踢得一般,不过也至少保持对对方的冲击。阿穆开场脑子迟钝了,而且丫确实太小心了,不敢出击,不过英勇负伤了,大家还是给点掌声吧。还有要说的是萨尼亚的边路传中太烂了吧,换成埃布可以提两个档次了。 PS: This game began in incessant rain and ended in bright, brilliant sunlight. |
|
|