恒邪

上一页 1 ··· 8 9 10 11 12 13 下一页

2014年3月20日 #

[蓝桥杯历届题目] 黄金队列

摘要: 黄金分割数0.618与美学有重要的关系。舞台上报幕员所站的位置大约就是舞台宽度的0.618处,墙上的画像一般也挂在房间高度的0.618处,甚至股票的波动据说也能找到0.618的影子....黄金分割数是个无理数,也就是无法表示为两个整数的比值。0.618只是它的近似值,其真值可以通过对5开方减去1再除以2来获得,我们取它的一个较精确的近似值:0.618034有趣的是,一些简单的数列中也会包含这个无理数,这很令数学家震惊!134711182947....称为“鲁卡斯队列”。它后面的每一个项都是前边两项的和。如果观察前后两项的比值,即:1/3,3/4,4/7,7/11,11/18...会发现它越来越 阅读全文

posted @ 2014-03-20 14:39 恒邪 阅读(179) 评论(0) 推荐(0) 编辑

2014年3月19日 #

数据结构上机实验:单链表操作

摘要: #include #include using namespace std;typedef struct Node{ char c; struct Node *next;}*LinkList,LNode;//初始化单链表hLinkList Init(LinkList &h){ h=(LNode*)malloc(sizeof(LNode)); if(h==NULL) { coutnext=NULL; return h;}//尾差法插入元素void InsertNum(LinkList &h,int n){ LinkList r,s; ... 阅读全文

posted @ 2014-03-19 21:02 恒邪 阅读(165) 评论(0) 推荐(0) 编辑

筛选求n以内素数并返回个数

摘要: #include using namespace std;const int maxn=10000;int prime[maxn];bool is_prime[maxn+1];int sieve(int n)//返回n以内素数的个数{ int p=0; for(int i=0;i<=n;i++) is_prime[i]=true; is_prime[0]=is_prime[1]=false; for(int i=2;i<=n;i++) { if(is_prime[i]) { prime[p++]=i;... 阅读全文

posted @ 2014-03-19 20:13 恒邪 阅读(200) 评论(0) 推荐(0) 编辑

优先队列

摘要: #include #include #include using namespace std;struct node{ friend bool operatorq1; for(i=0;i,greater >q2; for(i=0;iq3; node b[len]; b[0].priority=6;b[0].value=1; b[1].priority=9;b[1].value=5; b[2].priority=2;b[2].value=3; b[3].priority=8;b[3].value=2; b[4].priority=1;b[4]... 阅读全文

posted @ 2014-03-19 20:12 恒邪 阅读(116) 评论(0) 推荐(0) 编辑

最长递增子序列

摘要: #include using namespace std;//int num[8]={0,0,3,1,2,4,1,5};//原始序列int num[8]={0,1,3,4,2,5,6,7};int d[8];//保存最长递增子序列的元素,第二种方法,复杂度低int dp[8];//第一种方法,复杂度高,dp[i]存储从num[1]到num[i]之间最长递增子序列的长度,num[i]一定在里边int BinSearch(int key,int i,int low,int high)//二分搜索,找到road[i]在d[]数组中的位置{ int l=low,r=high; while(... 阅读全文

posted @ 2014-03-19 20:10 恒邪 阅读(148) 评论(0) 推荐(0) 编辑

2014年3月18日 #

string.find()函数用法

摘要: 1.返回字符串s1在s中的位置,如果没有找到,则返回-1#include #include using namespace std;int main(){ string s="what are you dong"; string s1="are"; int position; position=s.find(s1); if(position==-1) cout#include using namespace std;int main(){ string s="hahahaha"; string s1="a"; in 阅读全文

posted @ 2014-03-18 19:51 恒邪 阅读(1766) 评论(0) 推荐(0) 编辑

substr(),strstr()函数用法

摘要: #include #include using namespace std;int main(){ string s="abcdefg"; string s1=s.substr(2,6);//s1为字符串s起始位置为2,长度为6的一段字符串,注意s的位置是从0开始的,即‘a'的位置为0 cout#include using namespace std;int main(){ char a[]="my dream will come true"; char *p; p=strstr(a,"dream");//a中找到字符串dre 阅读全文

posted @ 2014-03-18 19:21 恒邪 阅读(240) 评论(0) 推荐(0) 编辑

[蓝桥杯历届题目] 正六面体染色 ; 取字母组成串

摘要: 1. 正六面体染色正六面体用4种颜色染色。共有多少种不同的染色样式?要考虑六面体可以任意旋转、翻转。参考答案:240解答:Burnside引理,正方体涂色问题(n^6+3*n^4+12*n^3+8*n^2)/24 把n=4d带入公式就行了。2.取字母组成串A B C D中取5次,每个字母都可以重复取出,形成一个串。现在要求,串中A出现的次数必须为偶数(0次也算偶数)。求可以形成多少种可能的串。参考答案:528代码:#include using namespace std;char a[4]={'A','B','C','D'};in 阅读全文

posted @ 2014-03-18 10:22 恒邪 阅读(401) 评论(0) 推荐(0) 编辑

[练习] 求组合数

摘要: C(m,n) 从m个中取出n个,问一共有多少种情况。代码:#include using namespace std;int c(int m,int n){ if(n==0) return 1; if(m<n) return 0; return c(m-1,n)+c(m-1,n-1);}int cc(int m,int n){ int cmn=1; for(int i=0;i<n;i++) { cmn=cmn*(m-i)/(i+1); } return cmn;}int main(){ cout<<c... 阅读全文

posted @ 2014-03-18 09:53 恒邪 阅读(153) 评论(0) 推荐(0) 编辑

2014年3月17日 #

[练习] dfs输出全排列

摘要: 代码:#include #include using namespace std;int visit[11],num[11];int n;void dfs(int depth){ if(depth>n)//注意是大于号,不是大于等于,因为在等于的时候num[depth]还没有赋值 { for(int j=1;j>n) { memset(visit,0,sizeof(visit)); dfs(1); }}另一种写法,只改动了dfs函数#include #include using namespace std;int visit[1... 阅读全文

posted @ 2014-03-17 20:59 恒邪 阅读(165) 评论(0) 推荐(0) 编辑

上一页 1 ··· 8 9 10 11 12 13 下一页

导航