2013年2月22日

浮点数的比较

摘要: 首先,这个不算原创,原文是洋文的,我翻译了一下写这个文章的人绝对是个大师,虽然知识并不是很深奥,不过想法真的很不错,值得学习两个月前忽然看见的这篇文章,昨天仔细读了一遍,翻译了一下,原文在此http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm这是我翻译的,里面有些地方翻译的不太对,有些地方我也不懂,你们谁要是看懂了就告诉我浮点数的比较Bruce Dawson两数完全相等整型数是精确的,浮点数并不是那样。举个简单的例子,0.2这个数无法用二进制的浮点数精确表示,并且有限的精度意味着微小的误差在经过多次操 阅读全文
posted @ 2013-02-22 22:28 Primo... 阅读(3492) 评论(0) 推荐(3)

uva331 - Mapping the Swap

摘要: 题意不难理解,就是一个个排列排序的map的种数。对于4 3 2 1 , 可见可以先对4 3 交换,或者对3 2 交换,或者对 2 1 交换。然后分情况依次交换,共有16种map。还是回溯的简单利用。。。不难。。。代码如下:#include int num[10], _case, n; void swap(int a, int b) { int temp = num[a]; num[a] = num[b]; num[b] = temp; } void print_case(int cur) { int f = 1; for(int i = 1; i nu... 阅读全文
posted @ 2013-02-22 21:56 Primo... 阅读(118) 评论(0) 推荐(0)

uva10344 - 23 out of 5

摘要: 下面的东西,你知道几个:1、不同的排列相同的运算符得到的结果不同,2、在生成排列前必须要排序数据。好了,对于这个题,也没有什么好说的,直接贴代码把;代码如下:#include #include using namespace std; int num[5], possible; void print_product(int cur, int product) { if(possible)return; if(cur==5) { if(product==23&&!possible) {possible = 1; } return;} print_produc... 阅读全文
posted @ 2013-02-22 18:36 Primo... 阅读(149) 评论(0) 推荐(0)

uva301 - Transportation

摘要: 求取列车公司最大利润,对于某一区间的车票要拒则全拒,此题类似与子集生成问题,开始的时候想用子集生成+判断合理性,但是觉得比较耗时,所以就一边列子集,一边判断合理性,以至于及时回溯。代码如下:#include int capacity, n, m, max; int order[22][3], num[10]; void print_price(int cur, int price) { if(cur==m) { if(max<price) max = price; return; } int ff = 1, f[10] = {0... 阅读全文
posted @ 2013-02-22 17:32 Primo... 阅读(119) 评论(0) 推荐(0)