
算法竞赛
文章平均质量分 78
Mustache_ACM
这个作者很懒,什么都没留下…
展开
-
stringstream的基本用法
stringstream是字符串流。它将流与存储在内存中的string对象绑定起来。在多种数据类型之间实现自动格式化。1 stringstream对象的使用#include#includeusing namespace std;int main(){ string line,word; while(getline(cin,line转载 2017-10-24 21:57:52 · 467 阅读 · 0 评论 -
《算法竞赛入门经典》6-8树TREE UVA548——二叉树的递归遍历/深度优先遍历DFS
You are to determine the value of the leaf node in a given binary tree that is the terminal node of apath of least value from the root of the binary tree to any leaf. The value of a path is the sum o...原创 2019-04-06 21:12:25 · 270 阅读 · 0 评论 -
《阿哈!算法》2-1解密QQ号——队列
新学期开始了,小哈是小哼的新同桌(小哈是个小美女哦~),小哼向小哈询问QQ号,小哈当然不会直接告诉小哼啦,原因嘛你懂的。所以小哈给了小哼一串加密过的数字,同时小哈也告诉了小哼解密规则。规则是这样的:首先将第1个数删除,紧接着将第2个数放到这串数的末尾,再将第3个数删除并将第4个数再放到这串数的末尾,再将第5个数删除……直到剩下最后一个数,将最后一个数也删除。按照刚才删除的顺序,把这些删除的数连在一...原创 2019-04-07 19:49:08 · 532 阅读 · 0 评论 -
《阿哈!算法》2-2解密回文——栈
栈的实现之需要一个一维数组和一个指向栈顶的变量top即可。通过top对栈进行插入和删除操作。初始化栈只需要top=0;入栈:top++;s[top]=x;简写为s[++top]=x;栈可以用来判断回文,验证括号的匹配等题目代码如下:#include <stdio.h>#include <stdlib.h>#include <math.h>...原创 2019-04-07 22:45:59 · 346 阅读 · 2 评论 -
《阿哈!算法》2-4链表
指针:存储一个地址,确切地说是存储一个内存空间的地址。malloc函数的作用是从内存中申请分配指定字节大小的分配空间。可以用 malloc(sizeof(int));申请。我们用指针来对这空间进行操作。用一个指针指向这个空间,即存储这个空间的首地址。 struct node *q; p=(struct node *)malloc(sizeof(struct ...原创 2019-04-07 23:56:11 · 209 阅读 · 0 评论 -
《阿哈!算法》2-5 模拟链表——用数组来实现链表
链表中的每一个结点只有两个部分。即data和struct node * next;构成:第一个整型数组data是用来存放序列中具体数字的。另一个整型数组right是用来存放当前序列中每一个元素右边的元素在数组data中位置的。例如right[1]的值为2,就表示当前序列中的1号元素右边的元素存放在data[2]中:如果是0,例如right[9】的值为0,就表示当前序列中9号元2s 素的右边没有...原创 2019-04-08 10:43:36 · 289 阅读 · 0 评论 -
《阿哈!算法》4-1不撞南墙不回头 4-2 解救小哈——深度优先搜索
深度优先搜索关键在于解决“当下该如何做”。至于“下一步如何做”则与当下该如何做“是一样的。深度优先搜索模型:void dfs(int step){ 判断边界,一般在这里输出最终的结果 尝试每一种可能for(int i=1;i<=n;i++) { 标记 继续下一步dfs(step+1); 收回标记 }...原创 2019-04-08 12:00:43 · 493 阅读 · 0 评论 -
十进制转二进制递归求解
#include <iostream>#include <cstdio>#include "cstring"#include "algorithm"#include <vector>#include <list>#include <stack>#include <queue>#include <map&...原创 2019-04-02 16:37:16 · 680 阅读 · 0 评论 -
算法竞赛入门经典第四章(自顶向下,逐步求精 编写程序)
4-1古老的密码 //古老的密码 WRONG ANSWR #define maxn 100+10 int cmp(const void* a,const void* b){ return *(int *)a-*(int *)b;//从小到大排序 } int main() { char a[maxn]; char b[maxn]; while(scanf("%s %s",a...原创 2019-04-03 11:17:41 · 380 阅读 · 1 评论 -
《算法竞赛入门经典》6-7 Trees on the level UVA122——二叉树的层次遍历(宽度优先遍历BFS)
Trees on the level UVA - 122Trees are fundamental in many branches of computer science (Pun definitely intended). Current state- of-the art parallel computers such as Thinking Machines’ CM-5 ...原创 2019-04-06 16:50:19 · 344 阅读 · 0 评论 -
《算法竞赛入门经典》6-6小球下落——二叉树的编号
6.3.1 二叉树的编号6-6 Dropping BallsA number of K balls are dropped one by one from the root of a fully binary tree structure FBT. Each time the ball being dropped first visits a non-terminal node. It the...原创 2019-04-06 14:52:41 · 325 阅读 · 0 评论 -
An easy problem HDU - 2055(对char和int的理解;Xcode中字符输入分输入法)
we define f(A) = 1, f(a) = -1, f(B) = 2, f(b) = -2, ... f(Z) = 26, f(z) = -26;Give you a letter x and a number y , you should output the result of y+f(x).InputOn the first line, contains a numb...原创 2019-04-05 11:40:48 · 189 阅读 · 0 评论 -
C语言求最小公倍数和最大公约数
最小公倍数:数论中的一种概念,两个整数公有的倍数成为他们的公倍数,其中一个最小的公倍数是他们的最小公倍数,同样地,若干个整数公有的倍数中最小的正整数称为它们的最小公倍数,维基百科:定义点击打开链接求最小公倍数算法:最小公倍数=两整数的乘积÷最大公约数求最大公约数算法:(1)辗转相除法有两整数a和b:① a%b得余数c② 若c=0,则b即为转载 2017-11-03 00:09:24 · 265 阅读 · 0 评论 -
分割问题
(1) n条直线最多分平面问题 题目大致如:n条直线,最多可以把平面分为多少个区域。 析:可能你以前就见过这题目,这充其量是一道初中的思考题。但一个类型的题目还是从简单的入手,才容易发现规律。当有n-1条直线时,平面最多被分成了f(n-1)个区域。则第n条直线要是切成的区域数最多,就必须与每条直线相交且不能有同一交点。这样就会得到n-1个交点。这些交点将第n条直线分为2转载 2017-11-17 21:41:24 · 376 阅读 · 0 评论 -
X - 折线分割平面 HDU - 2050 (分割问题)
X - 折线分割平面 HDU - 2050 我们看到过很多直线分割平面的题目,今天的这个题目稍微有些变化,我们要求的是n条折线分割平面的最大数目。比如,一条折线可以将平面分成两部分,两条折线最多可以将平面分成7部分,具体如下所示。 Input输入数据的第一行是一个整数C,表示测试实例的个数,然后是C 行数据,每行包含一个整数n(0Output对于每个测试实例,请输出平面的最大分原创 2017-11-17 22:02:08 · 305 阅读 · 0 评论 -
《算法问题实战策略》6-3郊游
#include <iostream>#include <cstdio>#include "cstring"using namespace std;//6-4 PICNICint n,m;bool areFriends[10][10]={0};bool taken[10]={0};//判断taken[i]是否已经配对,初始化为false,没有配对//若...原创 2019-03-04 16:42:55 · 424 阅读 · 0 评论 -
阿牛的EOF牛肉串
`#include <iostream>#include <stack>#include <cstdio>#include <cstdlib>#include <queue>#include <algorithm>#include <list>using namespace std;//分析题...原创 2019-03-29 21:33:42 · 636 阅读 · 0 评论 -
HDU - 2054 A == B ?(string操作复习)
Give you two numbers A and B, if A is equal to B, you should print "YES", or print "NO".Inputeach test case contains two numbers A and B.Outputfor each case, if A is equal to B, you should p...原创 2019-04-03 23:06:48 · 269 阅读 · 0 评论 -
不容易系列之(4)——考新郎 (组合数+错排分析)
#include <iostream>#include <stack>#include <cstdio>#include <cstdlib>#include <queue>#include <algorithm>#include <list>using namespace std;long lon...原创 2019-03-30 23:45:18 · 312 阅读 · 0 评论 -
神、上帝以及老天爷 HDU - 2048 (错排分析)
#include <iostream>#include <stack>#include <cstdio>#include <cstdlib>#include <queue>#include <algorithm>#include <list>using namespace std;long lon...原创 2019-03-31 00:44:56 · 209 阅读 · 0 评论 -
《阿哈!算法》4-3 解救小哈——广度优先搜索
广度优先搜索:使用队列实现广度优先搜索代码:#include <stdio.h>#include <stdlib.h>#include <math.h>#include <ctype.h>#include <string.h>const int max=1000;struct note{ int x; ...原创 2019-04-09 14:48:49 · 517 阅读 · 0 评论