无界
If the only tool you have is a hammer, you tend to see every problem as a nail.
BlogJava | 首页 | 发新随笔 | 发新文章 | 联系 | 聚合 | 管理

DP啊,为啥我还是不会呢……
高中的时候对DP就没有感觉,到现在还是不行,尽管对于递推这种东西已经比原来有感觉的多了

但是还是没办法弄出来状态划分啊什么的,难道真的需要多做题积累经验么

一直觉得DP是很神奇的东西,因为感觉很玄乎,不像其他的算法那样,基本都有固定套路的

DP相对来说很灵活,也正是如此所以难以掌握吧

没办法啦,还是多多努力吧,多做题,多见识一下,大概就能掌握了

熟能生巧么,谁让我天生没长懂DP的脑袋呢

Dev+Algo两不误,我的追求

posted @ 2009-03-29 22:55 杨磊 阅读(129) | 评论 (0) | 编辑 收藏
 
Unit Testing Tips from TopCoder
  • ALWAYS implement a tested version of the demonstration from the component specification.
  • ALWAYS provide a meaningful message in assert and fail calls.
  • ALWAYS document your test code as well as you document your component code.
  • Break up your tests into discrete TestCase classes. If one TestCase becomes unmanageable, don't hesitate to break it into two or more classes.
  • Break up your tests within those classes into the smallest functions possible; this way, it is clear which areas of the component are failing. You can then use the number of tests passing and failing as a completion metric, as well.
  • Reduce code duplication and increase robustness with setUp() and tearDown().
  • Test every public function for as much valid and invalid input as time allows.
  • Test expected component processes: loading, processing data, and saving data, for instance.
  • Don't forget to clean up your environment! Unit tests should leave the system in the same state they found it in; there should be no persistent changes. This is checked during development review.
  • Test classes are normal classes in every respect, except that they have special significance to the testing framework. These classes can inherit from a class intermediate between themselves and the final test. They may contain methods other than test methods. They may have state.
  • Because they are in the same package or namespace as the component classes they test, the unit tests can access package-private and protected classes and their members.
  • Interfaces cannot be tested directly, but methods that accept interface arguments can be presented with alternative implementations. This technique has great potential for verifying that the component does the expected things with and to its interface-typed fields and method arguments, and that it reacts correctly to exceptions thrown by methods invoked on such arguments.
posted @ 2009-03-28 21:38 杨磊 阅读(168) | 评论 (0) | 编辑 收藏
 
抽屉原理
对一块3行7列的长方形阵列中的小方格的每一格任意染成黑色或白色,求证:在这个长方形中,一定有一个由小方格组成的长方形,它的四个角上的小方格同色。
证法1:每一列的三个格用黑、白两种颜色染色.所有可能的染法只有如下图中的八种


如果在所染色的3行7列阵列中某一列是第(1)种方式,即三格均为白色,则其余6列中只要再有第(1)(2)(3)(4)种方式之一(即该列中至少有两个白格),那么显然存在一个四角格都是白色的长方形.若第(1)、(2)、(3)、(4)种方式均未出现,那么其余6列就只能是(5)、(6)、(7)、(8)这四种方式,根据抽屉原理,其中至少有两列染色方式完全一样.又(5)~(8)中每一列至少有两格染黑色,所以一定存在一个长方形,它的四角格颜色都是黑色。
同理可知,如果有一列是第(8)种方式,即三格均为黑色,那么也存在四角同色的长方形。
如果在7列中(1)、(8)两种方式都未出现,则只有(2)、(3)、(4)、(5)、(6)、(7)这六种方式染这7列,根据抽屉原理,至少有两列染色方式完全一样,所以仍然存在四角同色的长方形。
证法2:第一行有7个小方格,用黑白两种颜色去染,根据抽屉原理,至少有四个方格所染颜色相同,不妨设第一行有4个黑方格.再看第二行,如果在第一行的四个黑方格下面的四格中有两格是黑色,则结论显然成立.否则第二行这四个格中至少有3个白色方格。
再看第三行.根据抽屉原理,在第三行的位于第二行的3个白格下面的3个格中必至少有两格同色.如果有两格为白色,则与第二行构成四角白色的长方形;如果没有两格白色,那么必有两格为黑色,则与第一行构成四角黑色的长方形。


posted @ 2009-03-03 14:34 杨磊 阅读(296) | 评论 (0) | 编辑 收藏
 
今天开始看The Art of Computer Programming
att
posted @ 2009-02-28 00:08 杨磊 阅读(172) | 评论 (0) | 编辑 收藏
 
二维图最大匹配--匈牙利算法
bool find(int a)
{
        
for(int i=1;i<=m;i++)
        {
                
if(g[a][ i ]==1&&!b[ i ])
                {
                        b[ i ]
=true;
                        
if(link[ i ]==0||find(link[ i ]))
                        {
                                link[ i ]
=a;
                                
return true;
                        }
                }
        }
        
return false;
}

int main()
{
        
while(init())
        {
                
for(int i=1;i<=n;i++)
                {
                        memset(b,
0,sizeof(b));
                        
if(find(i))ans++;
                }
                printf(
"%d\n",ans);
        }
}
posted @ 2009-02-25 14:42 杨磊 阅读(171) | 评论 (0) | 编辑 收藏
 
Problems Left To Do
 SRM144 DIV1 1100  图形学
   
   
   

posted @ 2009-02-20 23:50 杨磊 阅读(108) | 评论 (0) | 编辑 收藏
 
Games Wanted To Play
 X  Titan Quest
 V  Warhammer 40,000 Dawn of War II
   StarCraft II
   Diablo III


Titan Quest 实在是没心思玩,这个ARPG的游戏,居然没有大范围杀伤的技能,或者是我没找到

而且就算有,比如战斗专精的战风,也是伤害低的可怜,根本不想Diablo里面法师的魔法那么强大

差不多是完全靠剧情来打的游戏,屏幕上的怪,无论大的小的,我都只能一个一个的打,太费神了,还是算了

Warhammer 40,000 Dawn of War II,真是好游戏啊!可惜电脑不行,否则效果全开的话,一定是非常非常震撼的

也许等过个几年,我换电脑了,到时候再来尝试一下效果全开是什么感觉

To Be Continued....

有朝一日希望我有机会能玩上这些游戏,但我估计是梦想了

“游戏你的游戏,不要被游戏所游戏”
posted @ 2009-02-16 18:41 杨磊 阅读(107) | 评论 (0) | 编辑 收藏
 
Endianness from wikipedia
http://en.wikipedia.org/wiki/Endianness
posted @ 2009-02-14 00:27 杨磊 阅读(174) | 评论 (0) | 编辑 收藏
 
Big and Little Endian zz from UMD

Big and Little Endian

Basic Memory Concepts

In order to understand the concept of big and little endian, you need to understand memory. Fortunately, we only need a very high level abstraction for memory. You don't need to know all the little details of how memory works.

All you need to know about memory is that it's one large array. But one large array containing what? The array contains bytes. In computer organization, people don't use the term "index" to refer to the array locations. Instead, we use the term "address". "address" and "index" mean the same, so if you're getting confused, just think of "address" as "index".

Each address stores one element of the memory "array". Each element is typically one byte. There are some memory configurations where each address stores something besides a byte. For example, you might store a nybble or a bit. However, those are exceedingly rare, so for now, we make the broad assumption that all memory addresses store bytes.

I will sometimes say that memory is byte-addresseable. This is just a fancy way of saying that each address stores one byte. If I say memory is nybble-addressable, that means each memory address stores one nybble.

Storing Words in Memory

We've defined a word to mean 32 bits. This is the same as 4 bytes. Integers, single-precision floating point numbers, and MIPS instructions are all 32 bits long. How can we store these values into memory? After all, each memory address can store a single byte, not 4 bytes.

The answer is simple. We split the 32 bit quantity into 4 bytes. For example, suppose we have a 32 bit quantity, written as 90AB12CD16, which is hexadecimal. Since each hex digit is 4 bits, we need 8 hex digits to represent the 32 bit value.

So, the 4 bytes are: 90, AB, 12, CD where each byte requires 2 hex digits.

It turns out there are two ways to store this in memory.

Big Endian

In big endian, you store the most significant byte in the smallest address. Here's how it would look:
Address Value
1000 90
1001 AB
1002 12
1003 CD

Little Endian

In little endian, you store the least significant byte in the smallest address. Here's how it would look:
Address Value
1000 CD
1001 12
1002 AB
1003 90
Notice that this is in the reverse order compared to big endian. To remember which is which, recall whether the least significant byte is stored first (thus, little endian) or the most significant byte is stored first (thus, big endian).

Notice I used "byte" instead of "bit" in least significant bit. I sometimes abbreciated this as LSB and MSB, with the 'B' capitalized to refer to byte and use the lowercase 'b' to represent bit. I only refer to most and least significant byte when it comes to endianness.

Which Way Makes Sense?

Different ISAs use different endianness. While one way may seem more natural to you (most people think big-endian is more natural), there is justification for either one.

For example, DEC and IBMs(?) are little endian, while Motorolas and Suns are big endian. MIPS processors allowed you to select a configuration where it would be big or little endian.

Why is endianness so important? Suppose you are storing int values to a file, then you send the file to a machine which uses the opposite endianness and read in the value. You'll run into problems because of endianness. You'll read in reversed values that won't make sense.

Endianness is also a big issue when sending numbers over the network. Again, if you send a value from a machine of one endianness to a machine of the opposite endianness, you'll have problems. This is even worse over the network, because you might not be able to determine the endianness of the machine that sent you the data.

The solution is to send 4 byte quantities using network byte order which is arbitrarily picked to be one of the endianness (not sure if it's big or little, but it's one of them). If your machine has the same endianness as network byte order, then great, no change is needed. If not, then you must reverse the bytes.

History of Endian-ness

Where does this term "endian" come from? Jonathan Swift was a satirist (he poked fun at society through his writings). His most famous book is "Gulliver's Travels", and he talks about how certain people prefer to eat their hard boiled eggs from the little end first (thus, little endian), while others prefer to eat from the big end (thus, big endians) and how this lead to various wars.

Of course, the point was to say that it was a silly thing to debate over, and yet, people argue over such trivialities all the time (for example, should braces line in parallel or not? vi or emacs? UNIX or Windows).

Misconceptions

Endianness only makes sense when you want to break a large value (such as a word) into several small ones. You must decide on an order to place it in memory.

However, if you have a 32 bit register storing a 32 bit value, it makes no sense to talk about endianness. The register is neither big endian nor little endian. It's just a register holding a 32 bit value. The rightmost bit is the least significant bit, and the leftmost bit is the most significant bit.

There's no reason to rearrange the bytes in a register in some other way.

Endianness only makes sense when you are breaking up a multi-byte quantity, and attempting to store the bytes at consecutive memory locations. In a register, it doesn't make sense. A register is simply a 32 bit quantity, b31....b0, and endianness does not apply to it.

With regard to endianness, You may argue there's a very natural way to store 4 bytes in 4 consecutive addresses, and that the other way looks strange. In particular, it looks "backwards". However, what's natural to you may not be natural to someone else. The fact of the matter is that the word is split in 4 bytes, and most people would agree that you need some order to place it in memory.

C-style strings

Once you start thinking about endianness, you begin to think it applies to everything. Before you see big or little endian, you may have had no idea it even existed. That's because it's reasonably well-hidden from you.

If you do bitwise/bitshift operations on an int, you don't notice the endianness. The machine arranges the multiple bytes so the least significant byte is still the least significant byte (e.g., b7-0) and the most significant byte is still the most significant byte (e.g., b31-24).

So, it's natural to think whether strings might be saved in some sort of strange order, depending on the machine.

This is where it's useful to think about all the facts you know about arrays. A C-style string, after all, is still an array of characters.

Here are some facts you should know about C-style strings and arrays.

  • C-style strings are stored in arrays of characters.
  • Each character requires one byte of memory, since characters are represented in ASCII (in the future, this could change, as Unicode becomes more popular).
  • In an array, the address of consecutive array elements increases. Thus, & arr[ i ] is less than & arr[ i + 1 ].
  • What's not as obvious is that if something is stored in increasing addresses in memory, it's going to be stored in increasing "addresses" in a file. When you write to a file, you usually specify an address in memory, and the number of bytes you wish to write to the file starting at that address.
So, let's imagine some C-style string in memory. You have the word "cat". Let's pretend 'c' is stored at address 1000. Then 'a' is stored at 1001. 't' is at 1002. The null character '"0' is at 1003.

Since C-style strings are arrays of characters, they follow the rules of characters. Unlike int or long, you can easily see the individual bytes of a C-style string, one byte at a time. You use array indexing to access the bytes (i.e., characters) of a string. You can't easily index the bytes of an int or long, without playing some pointer tricks (using reinterpret cast, for example, in C++). The individual bytes of an int are more or less hidden from you.

Now imagine writing out this string to a file using some sort of write() method. You specify a pointer to 'c', and the number of bytes you wish to print (in this case 4). The write() method proceeds byte by byte in the character string and writes it to the file, starting with 'c' and working to the null character.

Given that explanation, is it clear whether endianness matters with C-style strings? Hopefully, it is clear.

As an aside, since C++ strings are objects, it may have complicated inner structures, and so it's less obvious what a C++ string would look like when print out to a file. It's well-known what a C-style string looks like (a sequence of characters ending in a null character), which is why I've been careful to call them C-style strings.

posted @ 2009-02-14 00:25 杨磊 阅读(233) | 评论 (0) | 编辑 收藏
 
Space Ranger 2 Reboot Text Quest
     摘要: Feeding the xenomorphs

While landing a local caretaker tells you that a little mischievous xenomorph
mixed up the tablets showing the animals name in 5 cages around the zoo .
Read the books about their shape and feeding habits - a couple of hints in a
water of nonsense - and check the tubes with food. If you don`t like to wait  阅读全文
posted @ 2009-02-13 10:18 杨磊 阅读(2883) | 评论 (0) | 编辑 收藏
 
仅列出标题
共10页: 上一页 1 2 3 4 5 6 7 8 9 下一页 Last 
随笔:99 文章:-1 评论:17 引用:0
<2025年7月>
日一二三四五六
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789

留言簿(1)

  • 给我留言
  • 查看公开留言
  • 查看私人留言

随笔分类

  • ACM(43) (rss)
  • Boost(5) (rss)
  • 开发感言(2) (rss)
  • 心情日记(3) (rss)

随笔档案

  • 2009年5月 (12)
  • 2009年4月 (26)
  • 2009年3月 (5)
  • 2009年2月 (7)
  • 2009年1月 (1)
  • 2008年12月 (1)
  • 2008年11月 (4)
  • 2008年10月 (1)
  • 2008年8月 (10)
  • 2008年7月 (1)
  • 2008年6月 (7)
  • 2008年5月 (16)
  • 2008年4月 (3)
  • 2008年3月 (2)
  • 2008年2月 (1)
  • 2007年12月 (1)

相册

  • BlogPicture

搜索

  •  

最新评论

  • 1. re: Boost Thread学习笔记三
  • Mediator的构造函数也许缺少一句如下:
    for ( int i = 0; i < _slotCount; i++ ) _pSlot[i] = NULL;
  • --Harly
  • 2. re: SGU 102
  • 博主这个代码的原理是什么啊?看不大懂欸
  • --lph
  • 3. re: Boost Thread学习笔记五
  • 确实厉害
  • --12
  • 4. re: USACO 终于做完了
  • TOPCODER的数据更坑爹。各种challenge会导致各种刁钻数据都被选手钻研出来了
  • --cot
  • 5. re: 各种话题
  • 评论内容较长,点击标题查看
  • --zvin

Powered by: 博客园
模板提供:沪江博客
Copyright ©2025 杨磊