#include <bits/stdc++.h> using namespace std; int gra[1002][1005]; int vis[1002]; int n,m; void dfs(int x) { vis[x] = 1; for(int i = 1; i <= n ; i ++) { if(gra[x][i] == 1 && !vis[i]) { dfs(i); } } } int main() { while(~scanf("%d%d&qu…
#include <stdio.h> #include <string.h> struct node { char data; struct node *l,*r; }; struct node *root; char st[51]; int i; int count; struct node *creat() { struct node *root; if(st[i++] == ',') root = NULL; else { root = (struct node *)mall…
数据结构实验之数组三:快速转置 Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description 转置运算是一种最简单的矩阵运算,对于一个m*n的矩阵M( 1 = < m < = 10000,1 = < n < = 10000 ),它的转置矩阵T是一个n*m的矩阵,且T( i , j )=M( j , i ).显然,一个稀疏矩阵的转置仍然是稀疏矩阵.你的任务是对给定一个m*n的稀疏矩阵( m , n < = 100…
数据结构实验之串三:KMP应用 Time Limit: 1000MS Memory Limit: 65536KB Submit Statistic Problem Description 有n个小朋友,每个小朋友手里有一些糖块,现在这些小朋友排成一排,编号是由1到n.现在给出m个数,能不能唯一的确定一对值l和r(l <= r),使得这m个数刚好是第l个小朋友到第r个小朋友手里的糖块数? Input 首先输入一个整数n,代表有n个小朋友.下一行输入n个数,分别代表每个小朋友手里糖的数量. 之后再输…
数据结构实验之数组三:快速转置 Time Limit: 1000MS Memory Limit: 65536KB Submit Statistic Problem Description 转置运算是一种最简单的矩阵运算,对于一个m*n的矩阵M( 1 = < m < = 10000,1 = < n < = 10000 ),它的转置矩阵T是一个n*m的矩阵,且T( i , j )=M( j , i ).显然,一个稀疏矩阵的转置仍然是稀疏矩阵.你的任务是对给定一个m*n的稀疏矩阵( m…
数据结构实验之二叉树三:统计叶子数 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Description 已知二叉树的一个按先序遍历输入的字符序列,如abc,,de,g,,f,,, (其中,表示空结点).请建立二叉树并求二叉树的叶子结点个数. Input 连续输入多组数据,每组数据输入一个长度小于50个字符的字符串. Output 输出二叉树的叶子结点个数. Sample Input ab…
数据结构实验之串三:KMP应用 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Description 有n个小朋友,每个小朋友手里有一些糖块,现在这些小朋友排成一排,编号是由1到n.现在给出m个数,能不能唯一的确定一对值l和r(l <= r),使得这m个数刚好是第l个小朋友到第r个小朋友手里的糖块数? Input 首先输入一个整数n,代表有n个小朋友.下一行输入n个数,分别代表每个小朋友手…
数据结构实验之排序三:bucket sort Time Limit: 250 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Description 根据人口普查结果,知道目前淄博市大约500万人口,你的任务是帮助人口普查办公室按年龄递增的顺序输出每个年龄有多少人,其中不满1周岁的按0岁计算,1到2周岁的按1岁计算,依次类推,大于等于100岁的老人全部按100岁计算. Input 输入第一行给出一个正整数N(<=500000…
数据结构实验之排序三:bucket sort Time Limit: 150MS Memory Limit: 65536KB Submit Statistic Problem Description 根据人口普查结果,知道目前淄博市大约500万人口,你的任务是帮助人口普查办公室按年龄递增的顺序输出每个年龄有多少人,其中不满1周岁的按0岁计算,1到2周岁的按1岁计算,依次类推,大于等于100岁的老人全部按100岁计算. Input 输入第一行给出一个正整数N(<=5000000),随后连续给出N个…
数据结构实验之查找三:树的种类统计 Time Limit: 400MS Memory Limit: 65536KB Submit Statistic Problem Description 随着卫星成像技术的应用,自然资源研究机构可以识别每一个棵树的种类.请编写程序帮助研究人员统计每种树的数量,计算每种树占总数的百分比. Input 输入一组测试数据.数据的第1行给出一个正整数N (n <= 100000),N表示树的数量:随后N行,每行给出卫星观测到的一棵树的种类名称,树的名称是一个不超过20…
数据结构实验之二叉树三:统计叶子数 Time Limit: 1000MS Memory Limit: 65536KB Submit Statistic Problem Description 已知二叉树的一个按先序遍历输入的字符序列,如abc,,de,g,,f,,, (其中,表示空结点).请建立二叉树并求二叉树的叶子结点个数. Input 连续输入多组数据,每组数据输入一个长度小于50个字符的字符串. Output 输出二叉树的叶子结点个数. Example Input abc,,de,g,,f…
数据结构实验之栈三:后缀式求值 Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 对于一个基于二元运算符的后缀表示式(基本操作数都是一位正整数),求其代表的算术表达式的值. 输入 输入一个算术表达式的后缀式字符串,以‘#’作为结束标志. 输出 求该后缀式所对应的算术表达式的值,并输出之. 示例输入 59*684/-3*+# 示例输出 57 提示 基本操作数都是一位正整数!      代码: #include <stdio.h>…
数据结构实验之排序三:bucket sort Time Limit: 250 ms Memory Limit: 65536 KiB Problem Description 根据人口普查结果,知道目前淄博市大约500万人口,你的任务是帮助人口普查办公室按年龄递增的顺序输出每个年龄有多少人,其中不满1周岁的按0岁计算,1到2周岁的按1岁计算,依次类推,大于等于100岁的老人全部按100岁计算. Input 输入第一行给出一个正整数N(<=5000000),随后连续给出N个整数表示每个人的年龄,数字间…
数据结构实验之查找三:树的种类统计 Time Limit: 400 ms Memory Limit: 65536 KiB Problem Description 随着卫星成像技术的应用,自然资源研究机构可以识别每一个棵树的种类.请编写程序帮助研究人员统计每种树的数量,计算每种树占总数的百分比. Input 输入一组测试数据.数据的第1行给出一个正整数N (n <= 100000),N表示树的数量:随后N行,每行给出卫星观测到的一棵树的种类名称,树的名称是一个不超过20个字符的字符串,字符串由英文…
数据结构实验之二叉树三:统计叶子数 Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description 已知二叉树的一个按先序遍历输入的字符序列,如abc,,de,g,,f,,, (其中,表示空结点).请建立二叉树并求二叉树的叶子结点个数. Input 连续输入多组数据,每组数据输入一个长度小于50个字符的字符串. Output 输出二叉树的叶子结点个数. Sample Input abc,,de,g,,f,,, Sample Outp…
数据结构实验之串三:KMP应用 Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description 有n个小朋友,每个小朋友手里有一些糖块,现在这些小朋友排成一排,编号是由1到n.现在给出m个数,能不能唯一的确定一对值l和r(l <= r),使得这m个数刚好是第l个小朋友到第r个小朋友手里的糖块数? Input 首先输入一个整数n,代表有n个小朋友.下一行输入n个数,分别代表每个小朋友手里糖的数量. 之后再输入一个整数m,代表下面有m个…
#define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<stdlib.h> #include<string.h> //定义结构体 typedef struct _student{ int num; struct _student *pNext; }Student; //创建链表(顺序创建链表) Student * SList_Create(int *len/*out*/); //创建链表(逆序创建链表) St…
我们可以看到在javascript概念中的队列与栈都是一种特殊的线性表的结构,也是一种比较简单的基于数组的顺序存储结构.由于javascript的解释器针对数组都做了直接的优化,不会存在在很多编程语言中数组固定长度的问题(当数组填满后再添加就比较困难了,包括添加删除,都是需要把数组中所有的元素全部都变换位置的,javascript的的数组确实直接给优化好了,如push,pop,shift,unshift,split方法等等…) 线性表的顺序存储结构,最大的缺点就是改变其中一个元素的排列时都会引起…
描述 实现一个函数CreateLinkList,能够完成不带头节点链表的创建. 部分代码已经给出,请补充完整,提交时请勿包含已经给出的代码. void PrintLinkList(Node *head) { int flag = 0; Node *p = head, *q; while(p) { if(flag) printf(" "); flag = 1; printf("%d", p->data); q = p; p = p->next; free(…
Problem Description 转置运算是一种最简单的矩阵运算,对于一个m*n的矩阵M( 1 = < m < = 10000,1 = < n < = 10000 ),它的转置矩阵T是一个n*m的矩阵,且T( i , j )=M( j , i ).显然,一个稀疏矩阵的转置仍然是稀疏矩阵.你的任务是对给定一个m*n的稀疏矩阵( m , n < = 10000 ),求该矩阵的转置矩阵并输出.矩阵M和转置后的矩阵T如下图示例所示.       稀疏矩阵M          …
Given a linked list, swap every two adjacent nodes and return its head. For example, Given 1->2->3->4, you should return the list as 2->1->4->3. Your algorithm should use only constant space. You may not modify the values in the list, on…
桶排序: #include <stdio.h> #include <string.h> int a[5555555]; int main() { int n,m; scanf("%d",&n); memset(a,0,sizeof(a)); for(int i = 0; i < n; i ++) { scanf("%d",&m) ; if(m >= 100) a[100]++; else a[m]++; } for…
C: #include <stdio.h> #include <stdlib.h> #include <string.h> struct node { char data[30]; struct node *lc; struct node *rc; int num; }; char a[30]; int n; struct node *creat(struct node *root) { if(root == NULL) { root = (struct node *)…
#include <stdio.h> #include <string.h> #include <stdlib.h> struct node { char data[15]; struct node *next; //存放名字 }; struct node *head[2018]; // 每个课程都有一个相应的开始 int num[2018]; // 存放每个课程选的人数 char name[15]; int main() { int n,m,sum,cnt; whil…
#include <stdio.h> #include <stdlib.h> #include <string.h> void Swap(int a[], int i, int j) // 交换函数 { int t = a[i]; a[i] = a[j]; a[j] = t; } void HeapMerge(int *a,int i,int n) //调整函数,也是核心地方 // 以下的树的概念都是把这个堆转变成树来说的 { int lc = 2*i; // 因为我们…
(不知道为啥开个数组就 TLE .QAQ) #include <stdio.h> #include <stdlib.h> #include <string.h> //const int maxn = 100005; // //int a[maxn]; int main() { int n,k,ans,x; while(~scanf("%d%d",&n,&k)) { ans = -1; for(int i = 1; i <= n;…
#include <stdio.h> #include <string.h> #include <stdlib.h> int a[1000005]; int fin(int x,int l,int r) { int m = (l + r) / 2; if(l > r) return -1; if(a[m] == x) return m; else if(a[m] > x) return fin(x,l,m - 1); //别忘记了 m 需要变化 else r…
#include <bits/stdc++.h> using namespace std; struct node { char data; struct node *lc, *rc; }; char a[100]; int num = 0; struct node *creat() { struct node *root; if(a[num++] == ',') { root = NULL; } else { root = new node; root -> data = a[num…
#include <bits/stdc++.h> using namespace std; struct node { char data; struct node *lc, *rc; }; char s[505]; int num; struct node *creat() { struct node *root; if(s[num ++] == ',') { root = NULL; } else { root = new node; root -> data = s[num - 1…
Problem Description 数组--矩阵的转置 给定一个m*n的矩阵(m,n<=100),求该矩阵的转置矩阵并输出. Input 输入包含多组测试数据,每组测试数据格式如下: 第一行包含两个数m,n 以下m行,每行n个数,分别代表矩阵内的元素. (保证矩阵内的数字在int范围之内) Output 对于每组输出,输出给定矩阵的转置矩阵.两组输出之间用空行隔开. Sample Input 2 3 1 2 3 4 5 6 1 1 1 Sample Output 1 4 2 5 3 6 1…