随笔分类 -  ACM-C/C++

摘要:本文转载自:http://www.cnblogs.com/yangecnu/p/Introduce-B-Tree-and-B-Plus-Tree.html 维基百科对B树的定义为“在计算机科学中,B树(B-tree)是一种树状数据结构,它能够存储数据、对其进行排序并允许以O(log n)的时间复杂度 阅读全文
posted @ 2018-09-19 11:13 小学弟- 阅读(246) 评论(0) 推荐(0) 编辑
摘要:Problem Description 学会了单向链表,我们又多了一种解决问题的能力,单链表利用一个指针就能在内存中找到下一个位置,这是一个不会轻易断裂的链。但单链表有一个弱点——不能回指。比如在链表中有两个节点A,B,他们的关系是B是A的后继,A指向了B,便能轻易经A找到B,但从B却不能找到A。一个简单的想法便能轻易解决这个问题——建立双向链表。在双向链表中,A有一个指针指向了节点B,同时,B... 阅读全文
posted @ 2018-08-10 14:27 小学弟- 阅读(73) 评论(0) 推荐(0) 编辑
摘要:Problem Description n个人想玩残酷的死亡游戏,游戏规则如下: n个人进行编号,分别从1到n,排成一个圈,顺时针从1开始数到m,数到m的人被杀,剩下的人继续游戏,活到最后的一个人是胜利者。 请输出最后一个人的编号。 Input 输入n和m值。 Output 输出胜利者的编号。 Example Input 5 3 Example Output 4 Hint 第一轮:3... 阅读全文
posted @ 2018-08-10 14:26 小学弟- 阅读(133) 评论(0) 推荐(0) 编辑
摘要:Problem Description 按照数据输入的相反顺序(逆位序)建立一个单链表,并将单链表中重复的元素删除(值相同的元素只保留最后输入的一个)。 Input 第一行输入元素个数n; 第二行输入n个整数。 Output 第一行输出初始链表元素个数; 第二行输出按照逆位序所建立的初始链表; 第三行输出删除重复元素后的单链表元素个数; 第四行输出删除重复元素后的单链表。 Example I... 阅读全文
posted @ 2018-08-10 14:25 小学弟- 阅读(573) 评论(0) 推荐(0) 编辑
摘要:Problem Description 输入N个整数顺序建立一个单链表,将该单链表拆分成两个子链表,第一个子链表存放了所有的偶数,第二个子链表存放了所有的奇数。两个子链表中数据的相对次序与原链表一致。 Input 第一行输入整数N;; 第二行依次输入N个整数。 Output 第一行分别输出偶数链表与奇数链表的元素个数; 第二行依次输出偶数子链表的所有数据; 第三行依次输出奇数子链表的所有数据。... 阅读全文
posted @ 2018-08-10 14:22 小学弟- 阅读(1682) 评论(0) 推荐(0) 编辑
摘要:任意一个大于1的正整数都能表示成若干个质数的乘积,且表示的方法是唯一的。换句话说,一个数能被唯一地分解成质因数的乘积。因此这个定理又叫做唯一分解定理。 阅读全文
posted @ 2018-08-10 14:19 小学弟- 阅读(1267) 评论(0) 推荐(0) 编辑
摘要:#include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define maxn 205 int d[6][3]={{1,0,0},{-1,0,0}... 阅读全文
posted @ 2018-08-10 14:15 小学弟- 阅读(227) 评论(0) 推荐(0) 编辑
摘要:#include #include #include #define N 10000 int main() { char str[N]; int len;int i; int mod; int ans=0; int Case; scanf("%d",&Case); while(Case--){ scanf("%s",str); ... 阅读全文
posted @ 2018-08-10 12:22 小学弟- 阅读(103) 评论(0) 推荐(0) 编辑
摘要:#include #include #include #include #include using namespace std; typedef long long ll; ll ksm(ll a, ll b, ll c) { ll ans=1; a=a%c; while(b>0) { if(b%2==1) ans=(an... 阅读全文
posted @ 2018-08-10 12:21 小学弟- 阅读(98) 评论(0) 推荐(0) 编辑
摘要:#include using namespace std; #include #include void sqrt(char *str) { double i,r,n; int j,l,size,num,x[1005]; size=strlen(str); if (size==1&&str[0]=='0') { cout=size)... 阅读全文
posted @ 2018-08-10 12:05 小学弟- 阅读(465) 评论(0) 推荐(0) 编辑
摘要:大数除法,应该算是四则运算里面最难的一种了。不同于一般的模拟,除法操作步数模仿手工除法,而是利用减法操作实现的。 其基本思想是反复做除法,看从被除数里面最多能减去多少个除数,商就是多少。 逐个减显然太慢,要判断一次最多能减少多少个整的10的n次方。 以7546除23为例。 先减去23的100倍,就是2300,可以减3次,余下646。 此时商就是300; 然后646减去23的10倍,就是230... 阅读全文
posted @ 2018-08-10 12:04 小学弟- 阅读(320) 评论(0) 推荐(0) 编辑
摘要:#include #include #include void reverseOrder(char* str, int p, int q) { char temp; while(p < q) { temp = str[p]; str[p] = str[q]; str[q] = temp; p ++; ... 阅读全文
posted @ 2018-08-10 12:02 小学弟- 阅读(90) 评论(0) 推荐(0) 编辑
摘要:#include #include #include // 功能:实现两个大数减法运算 // 参数:source1--被减数 // source2--减数 // result --计算结果 // 返回值:计算结果为正数,返回'+',否则返回'-' char Minus(char *source1, char *source2, char *result) { ... 阅读全文
posted @ 2018-08-10 12:01 小学弟- 阅读(151) 评论(0) 推荐(0) 编辑
摘要:#include #include #include #include #include using namespace std; string bigmun(string a,string b){ string c; reverse(a.begin(),a.end()); reverse(b.begin(),b.end()); char ans[2... 阅读全文
posted @ 2018-08-10 12:00 小学弟- 阅读(74) 评论(0) 推荐(0) 编辑
摘要:#include #include #include using namespace std; #define INF 10000 const int maxn = 300; int r[maxn][maxn]; int main() { int n, m; while (cin>>n>>m) { memset (r, INF, sizeof(r)... 阅读全文
posted @ 2018-08-09 10:14 小学弟- 阅读(83) 评论(0) 推荐(0) 编辑
摘要:#include #include #include #define MAXLEN 1005 #define inf 1> b >> e >> v; map[b][e] = map[e][b] = v; } } bool SPFA(int x, int n) { queue Q; memset(vis,0,sizeof(vis)); mem... 阅读全文
posted @ 2018-08-09 08:37 小学弟- 阅读(108) 评论(0) 推荐(0) 编辑
摘要:#include "iostream" #include "cstdio" #include "queue" #include #include #include "algorithm" using namespace std; #define Maxn 1005 #define inf 1 Q; memset(vis, 0, sizeof(vis)); memset(inq... 阅读全文
posted @ 2018-08-09 08:36 小学弟- 阅读(88) 评论(0) 推荐(0) 编辑
摘要:#include using namespace std; const int Max=99999999; int map[105][105]; int d[105]; int middist; bool s[105]; void dijkstra(int n,int m) { for(int i=1;i>N>>M&&N!=0&&M!=0) { for(int ... 阅读全文
posted @ 2018-08-09 08:33 小学弟- 阅读(117) 评论(0) 推荐(0) 编辑
摘要:#include #include #include #include #include #define N 110 #define INF 0x7ffffff using namespace std; int n,val[N],mp[N][N],d[N],v[N],num[N],r[N][N]; void floyd() { for(int k=1;k q; q.push(s... 阅读全文
posted @ 2018-08-09 08:33 小学弟- 阅读(98) 评论(0) 推荐(0) 编辑
摘要:#include #include #include #include using namespace std; typedef struct { int a,b; double v; }node; typedef struct { int a,b; }P; const int maxn=109; double ans; int father[maxn]; nod... 阅读全文
posted @ 2018-08-08 14:46 小学弟- 阅读(91) 评论(0) 推荐(0) 编辑