摘要: #include #include using namespace std;int cmp(const void *a,const void *b){ return *(int*)a-*(int*)b;}int cn(int x){ int c=0; for(;x;x=x>>1) { if(x&1) c++; } return c;}int a[... 阅读全文
posted @ 2013-03-24 06:05 码代码的猿猿 阅读(123) 评论(0) 推荐(0) 编辑
摘要: 一上午才看懂一个:动态规划是用空间换时间的一种方法的抽象。其关键是发现子问题和记录其结果。然后利用这些结果减轻运算量。比如01背包问题。因为背包最大容量M未知。所以,我们的程序要从1到M一个一个的试。比如,开始任选N件物品的一个。看对应M的背包,能不能放进去,如果能放进去,并且还有多的空间,则,多出来的空间里能放N-1物品中的最大价值。怎么能保证总选择是最大价值呢?看下表。测试数据:10,33,4... 阅读全文
posted @ 2013-03-23 19:32 码代码的猿猿 阅读(193) 评论(0) 推荐(0) 编辑
摘要: 写了个特别挫的: #include #include #include using namespace std;int main(){ int llc=0; cin>>llc;for(int j=0;j>str; H=(str[0]-48)*10+(str[1]-48); M=(str[3]-48)*10+(str[4]-48); S=(str[6]-48)*10+(... 阅读全文
posted @ 2013-03-23 08:03 码代码的猿猿 阅读(188) 评论(0) 推荐(0) 编辑
摘要: qsort(T,n,sizeof(Note),cmp); int ans=1; int me=T[0].e; int i=1; while(ime) { me=T.e; ans++; } i++; } 阅读全文
posted @ 2013-03-23 00:50 码代码的猿猿 阅读(107) 评论(0) 推荐(0) 编辑
摘要: 贪心入门题#include #include using namespace std;struct Note{ int s; int e;}T[102];int cmp(const void *a,const void *b){ if(((Note*)a)->e>((Note*)b)->e) return 1; else return -1;}i... 阅读全文
posted @ 2013-03-22 23:52 码代码的猿猿 阅读(84) 评论(0) 推荐(0) 编辑
摘要: 起床了,先水一个#include #include using namespace std;int main(){ int m,n; while(cin>>m>>n) { int num; int mm=-111; int mm2; int t=0; for(int i=0;i>num; ... 阅读全文
posted @ 2013-03-22 22:27 码代码的猿猿 阅读(165) 评论(0) 推荐(0) 编辑
摘要: #include using namespace std;void reverse(char* c,int n,int m){ int i,j; for(i=n,j=m;i>k; move(c,k,8); for(int i=0;i<8;i++) cout<<c<<" "; return 0;} 阅读全文
posted @ 2013-03-15 05:39 码代码的猿猿 阅读(122) 评论(0) 推荐(0) 编辑
摘要: 简单。易懂。。#include using namespace std;void func(int* a,int*b,int * s,int c){ int i,j; for(i=0;ib[j]&&a[j]+1>a) { a=a[j]+1; s=b; } } }}... 阅读全文
posted @ 2013-03-15 01:46 码代码的猿猿 阅读(162) 评论(0) 推荐(0) 编辑
摘要: 转贴一文章,供大家参考浮点数的比较 在数学运算当中经常会涉及到判断两个数是否相等的情况对于整数很好处理 A==B这样的一个语句就可以解决全部的问题但是对于浮点数是不同的首先,浮点数在计算机当中的二进制表达方式就决定了大多数浮点数都是无法精确的表达的现在的计算机大部分都是数字计算机,不是模拟机,数字机的离散化的数据表示方法自然无法精确表达大部分的数据量的。其次计算机浮点数的精度在单精度float类型... 阅读全文
posted @ 2013-03-14 05:47 码代码的猿猿 阅读(274) 评论(0) 推荐(0) 编辑
摘要: 用对数#include #include using namespace std;int main(){ int y;while(cin>>y&&y){ int i; double sum=0.0; int t=(y-1960)/10+2; t=1=1e-8) { sum+=(log(i)/log(2.)); // ... 阅读全文
posted @ 2013-03-14 05:39 码代码的猿猿 阅读(86) 评论(0) 推荐(0) 编辑