摘要: 原理:对于每个不超过N的非负整数p,删除2*p,3*p,4*p,...,当处理完所有数之后,没有被删除的数就是素数 int vis[1001];void isprime(){ for(int i=2;i*i<=m;i++)//假设p=i; { if(!vis[i])//p不在之前的倍数行列 { fo 阅读全文
posted @ 2017-04-16 10:26 天道酬勤之菜鸟先飞 阅读(149) 评论(0) 推荐(0) 编辑
摘要: #include<cstdio> #include<algorithm>using namespace std;const int maxn=1000;int main(){ int n,q,x,a[maxn],kase=0; while(scanf("%d%d",&n,&q)==2&&n) { p 阅读全文
posted @ 2017-04-15 10:12 天道酬勤之菜鸟先飞 阅读(2659) 评论(0) 推荐(0) 编辑
摘要: #include<iostream>#include<string>#include<sstream>//stringstream的头文件 using namespace std;int main(){ string line; while(getline(cin,line)) { int sum= 阅读全文
posted @ 2017-04-15 09:57 天道酬勤之菜鸟先飞 阅读(3448) 评论(0) 推荐(0) 编辑
摘要: #include #include #include #include #include using namespace std; /*第一个函数是vector的引用,不用每次复制;而第二个函数每次都要对vector复制,第一个更优*/ void fill_random_int(vector &v,int cnt) { v.clear(); for(int i=0;i fill_random... 阅读全文
posted @ 2017-04-14 21:57 天道酬勤之菜鸟先飞 阅读(429) 评论(0) 推荐(0) 编辑
摘要: 题目: 丑数是指不能被2,3,5以外的其他素数整除的数。把丑数从小到大排列起来,结果如下: 1,2,3,4,5,6,8,9,10,12,15,。。。 求第1500个丑数 解题思路: 假设x是丑数,则2*x,3*x,5*x都是丑数,因此 用优先队列(升序)存储x,删除x,如是1500个丑数,则退出,否 阅读全文
posted @ 2017-04-14 21:26 天道酬勤之菜鸟先飞 阅读(362) 评论(0) 推荐(0) 编辑
摘要: 思路: 输入字符串S;设sum要插入字符的最小值 从两端出发前端x=0;后端y=L-1; 首先,如果S[0]!=S[L-1],此时要么在最前面添字符,要么在末尾添字符,sum++;(这是无法避免的) 然后,S[0]=S[L-1],此时前端x +1,后端y-1; 注意递归出口:前段>后端(x>y),此 阅读全文
posted @ 2017-04-14 19:47 天道酬勤之菜鸟先飞 阅读(358) 评论(0) 推荐(0) 编辑
摘要: 理解 理解: 实现循环队列 队首Q->Front=(Q->Front+1)%Q->MaxSize; 队尾Q->Rear=(Q->Front+Q->Count)%Q->MaxSize; 删除操作:移动队首,计数器Count--; 插入操作:先执行计数器Count++,在执行向后移动队尾(这里也可以先移 阅读全文
posted @ 2017-04-11 21:32 天道酬勤之菜鸟先飞 阅读(2498) 评论(0) 推荐(0) 编辑
摘要: 难点:>>递归函数的实现int Isomorphic(Tree R1,Tree R2){ if(R1==Null&&R2==Null) return 1; if(R1==Null&&R2!=Null) return 0; if(R1!=Null&&R2==Null) return 0; if(T1[ 阅读全文
posted @ 2017-04-11 18:10 天道酬勤之菜鸟先飞 阅读(2465) 评论(0) 推荐(1) 编辑
摘要: #include #include #define MAXSIZE 100 #define N 2 struct car { int ID;//汽车牌照号 int Time; // 汽车到达或离去时间 char Su;//汽车到达还是离去 int position;//汽车在停车场或过道的位置 }; typedef struct car Car; struct SNode//两个栈共... 阅读全文
posted @ 2017-04-08 15:52 天道酬勤之菜鸟先飞 阅读(200) 评论(0) 推荐(0) 编辑
摘要: 注意点: 第一,带头结点的链表,头结点是没有实际意义的结点,申请头结点的链表:p=(List)malloc(sizeof(struct Node));p->Next=NULL; 第二,要记得更新L1,L2链表。 阅读全文
posted @ 2017-04-05 09:26 天道酬勤之菜鸟先飞 阅读(559) 评论(0) 推荐(0) 编辑