
C语言入门
文章平均质量分 57
Mustache_ACM
这个作者很懒,什么都没留下…
展开
-
杨辉三角
还记得中学时候学过的杨辉三角吗?具体的定义这里不再描述,你可以参考以下的图形: 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 Input输入数据包含多个测试实例,每个测试实例的输入只包含一个正整数n(1Output对应于每一个输入,请输出相应层数的杨辉三角,每一层的整数之间用一个空格隔开,每一个杨辉三角后面加一个空行。原创 2017-11-11 11:47:43 · 246 阅读 · 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 评论 -
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 评论 -
《算法竞赛入门经典》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 评论 -
《算法竞赛入门经典》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-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 评论 -
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 评论 -
阿牛的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 评论 -
K - 改革春风吹满地
#include #include #include #include #define max 100K - 改革春风吹满地 HDU - 2036 #include #include #include #include #define max 100原创 2017-11-11 12:10:38 · 267 阅读 · 0 评论 -
O - 超级楼梯 (斐波那契数列应用)
超级楼梯Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 63748 Accepted Submission(s): 32651Problem Description有一楼梯共M级,刚开始时你在第一级,若原创 2017-11-12 02:49:43 · 324 阅读 · 0 评论 -
R - 一只小蜜蜂(斐波那契数列的进阶应用)
一只小蜜蜂...Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 52783 Accepted Submission(s): 19141Problem Description有一只经过训练的蜜蜂只能爬转载 2017-11-12 20:14:12 · 706 阅读 · 0 评论 -
S - 不容易系列之(3)—— LELE的RPG难题
人称“AC女之杀手”的超级偶像LELE最近忽然玩起了深沉,这可急坏了众多“Cole”(LELE的粉丝,即"可乐"),经过多方打探,某资深Cole终于知道了原因,原来,LELE最近研究起了著名的RPG难题: 有排成一行的n个方格,用红(Red)、粉(Pink)、绿(Green)三色涂每个格子,每格涂一色,要求任何相邻的方格不能同色,且首尾两格也不同色.求全部的满足要求的涂法. 以上就原创 2017-11-12 22:47:52 · 223 阅读 · 0 评论 -
V - 神、上帝以及老天爷
V - 神、上帝以及老天爷 HDU - 2048 #include #include #include #include #include const int max=40;//n个编号元素放到n个编号位置,元素编号与位置编号各不对应的方法数用M(n)表示,那么M(n-1)就表示n-1个编号元素放在n-转载 2017-11-17 20:26:25 · 387 阅读 · 0 评论 -
W - 不容易系列之(4)——考新郎 HDU - 2049 (错排思想和排列组合)
#include #include #include #include #include const int max=40;//相同的错排思想。m个新郎全部找错。则从n中选出n-m个新郎找对了新娘//错排公式M(n)=(n-1)*(M(n-1)+M(n-2))long long f(int m){ if(m原创 2017-11-17 21:11:30 · 256 阅读 · 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 评论 -
Y - 奇数阶魔方 HDU - 1998
Y - 奇数阶魔方 HDU - 1998 #include #include #include #include #include const int max=110;int main(){ int t; scanf("%d",&t); int n;原创 2017-11-18 07:46:49 · 170 阅读 · 0 评论 -
单链表插入函数优化(C和指针)
//链表实现插入函数#define FALSE 0#define TRUE 1//单链表插入思想:始终保存一个指向链表当前节点之前的那个节点的指针。`typedef struct NODE { struct NODE *link; int value;}Node;//插入到一个有序的单链表。函数的参数是一原创 2017-11-24 16:01:15 · 675 阅读 · 0 评论 -
双向链表(一)
struct Node{ int key; Node *prev,*next;};//初始化双向链表,创建一个空表Node *nil;void init(){ nil=(Node *)malloc(sizeof(Node)); nil->prev=nil; nil->next=nil;原创 2017-11-24 16:43:33 · 146 阅读 · 0 评论 -
《算法问题实战策略》6-7 解决旅行商问题的递归调用算法
//6-7 解决旅行商问题的递归调用算法const int Max=1000;int n;//城市个数double dist[Max][Max];//保存两城间距的数组//path:城市个数//visited:对各城市访问与否//currentLendth:所有已检索路径的长度//在访问所有剩余城市的路径的中。返回最短路径double shortesPath(vector<...原创 2019-03-07 00:00:17 · 652 阅读 · 0 评论 -
不容易系列之(3)—— LELE的RPG难题
#include <iostream>#include <stack>#include <cstdio>#include <cstdlib>#include <queue>#include <algorithm>#include <list>using namespace std;//如果有n个方...原创 2019-03-29 20:38:26 · 196 阅读 · 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 评论