书山有径勤为路>>>>>>>>

<<<<<<<<学海无涯苦作舟!

2011年10月16日

最基本的位运算

摘要: === 1. and运算 ===( & ) and运算通常用于二进制取位操作,例如一个数 and 1的结果就是取二进制的最末位。这可以用来判断一个整数的奇偶,二进制的最末位为0表示该数为偶数,最末位为1表示该数为奇数. 相同位的两个数字都为1,则为1;若有一个不为1,则为0。 00111 11100 (&或者and) ---------------- 00100=== 2. or运算 ===( | ) or运算通常用于二进制特定位上的无条件赋值,例如一个数or 1的结果就是把二进制最末位强行变成1。如果需要把二进制最末位变成0,对这个数or 1之后再减一就可以了,其实际意义就是 阅读全文

posted @ 2011-10-16 19:53 More study needed. 阅读(1787) 评论(0) 推荐(5) 编辑

DFS解决USACO——Mother's Milk

摘要: DescriptionFarmer John has three milking buckets of capacity A, B, and C liters. Each of the numbers A, B, and C is an integer from 1 through 20, inclusive. Initially, buckets A and B are empty while bucket C is full of milk. Sometimes, FJ pours milk from one bucket to another until the second bucke 阅读全文

posted @ 2011-10-16 18:45 More study needed. 阅读(751) 评论(0) 推荐(0) 编辑

经典进制转换——USACO Palindromic Squares

摘要: DescriptionPalindromes are numbers that read the same forwards as backwards. The number 12321 is a typical palindrome.Given a number base B (2 <= B <= 20 base 10), print all the integers N (1 <= N <= 300 base 10) such that the square of N is palindromic when expressed in base B; also pri 阅读全文

posted @ 2011-10-16 11:00 More study needed. 阅读(229) 评论(0) 推荐(0) 编辑

动态规划解决USACO——Number Triangles

摘要: DescriptionConsider the number triangle shown below. Write a program that calculates the highest sumof numbers that can be passed on a route that starts at the top and ends somewhere on the base. Each step can go either diagonally down to the left or diagonally down to the right. 7 3... 阅读全文

posted @ 2011-10-16 10:50 More study needed. 阅读(910) 评论(0) 推荐(0) 编辑

导航

书山有径勤为路>>>>>>>>

<<<<<<<<学海无涯苦作舟!