自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(240)
  • 问答 (1)
  • 收藏
  • 关注

原创 6-11 Shortest Path [1] (25 分)【非权值图 - BFS求单源最短路径】

void ShortestDist( LGraph Graph, int dist[], Vertex S ){ for(int i=0;i<Graph->Nv;i++){ dist[i]=-1; } int vis[MaxVertexNum]={0}; PtrToAdjVNode p; vis[S]=1;// printf("%d ",S); dist[S]=0; int queue[MaxVertexNum]={

2021-04-15 16:53:04 247

原创 图的广度遍历【BFS】

邻接矩阵:#include <stdio.h>#define MAXV 10#define INF 0int n=5,G[MAXV][MAXV]={ { 0, 1, 1, 0, 0 }, { 0, 0, 1, 1, 0 }, { 0, 1, 1, 1, 0 }, { 1, 0, 0, 0, 0 },

2021-04-15 16:10:07 95

原创 图的深度遍历【DFS】

邻接矩阵:#include <stdio.h>#define MAXV 10#define INF 0int n=5,G[MAXV][MAXV]={ { 0, 1, 1, 0, 0 }, { 0, 0, 1, 0, 1 }, { 0, 0, 1, 0, 0 }, { 1, 1, 0, 0, 1 }, { 0, 0,

2021-04-15 13:56:32 100

原创 6-9 Sort Three Distinct Keys (20 分)

void MySort( ElementType A[], int N ){ ElementType Map[3]={0}; for(int i=0;i<N;i++){ Map[A[i]]++; } int j=0; while(Map[1]--) A[j++]=1; while(Map[2]--) A[j++]=2; while(Map[0]--) A[j++]=0;}

2021-04-15 10:23:44 192

原创 三色球排序

#include <stdio.h>#define BLUE -1#define RED 0#define YELLOW 1void swap(int *a,int *b){ int t=*a; *a=*b; *b=t;}void MySort( int A[], int N ){ int head=0,end=N-1; for(int i=0;i<end;){ if(A[i]==YELLOW){

2021-04-15 10:17:05 309

原创 6-8 Percolate Up and Down (20 分)【堆结点的插入与删除】

堆节点的插入:void PercolateUp( int p, PriorityQueue H ){ //插入时,小的数字向上调整 int i; int temp=H->Elements[p]; for(i=H->Size;temp<H->Elements[i/2];i/=2){ //当插入的数字小于父节点则向上调整 H->Elements[i]=H->Elements[i/2]; } H->Element

2021-04-14 17:04:02 1417

原创 6-7 Isomorphic (20 分)

int Isomorphic( Tree T1, Tree T2 ){ if(!T1&&!T2) return 1; else if(T1&&T2){ if(T1->Element==T2->Element){ int b1=Isomorphic(T1->Left,T2->Left)||Isomorphic(T1->Left,T2->Right);

2021-04-14 14:56:13 277

原创 6-5 Evaluate Postfix Expression (25 分)

ElementType EvalPostfix( char *expr ){ double s1[10],t; int top1=-1,top2=-1,l=strlen(expr),neg=0; char s2[10]; for(int i=0;i<l;){ if(expr[i]=='-'&&expr[i+1]!=' '&&i!=l-1){ neg=1; i++;

2021-04-14 12:33:47 379

原创 6-3 Add Two Polynomials (20 分)

Polynomial Add( Polynomial a, Polynomial b ){ Polynomial s=(Polynomial)malloc(sizeof (struct Node)); Polynomial p=a->Next,q=b->Next,r=s; while(p&&q){ if(p->Exponent>q->Exponent){ r->Next=p;

2021-04-14 09:55:42 226

原创 6-12 二叉搜索树的操作集 (30 分)

插入代码A:BinTree Insert( BinTree BST, ElementType X ){ BinTree p=BST,pre=NULL; BinTree q=(BinTree)malloc(sizeof (struct TNode)); q->Data=X; q->Left=q->Right=NULL; if(BST==NULL) BST=q; else{ while(p){

2021-04-13 14:31:40 166

原创 6-10 二分查找 (20 分)

Position BinarySearch( List L, ElementType X ){ int head=1,end=L->Last,mid; while(head<=end){ mid=(head+end)/2; if(L->Data[mid]==X){ return mid; } else if(L->Data[mid]>X){ end=m

2021-04-13 11:30:11 103

原创 6-9 二叉树的遍历 (25 分)

void InorderTraversal( BinTree BT ){ if(BT){ InorderTraversal(BT->Left); printf(" %c",BT->Data); InorderTraversal(BT->Right); }}void PreorderTraversal( BinTree BT ){ if(BT){ printf(" %c",BT->Data);

2021-04-13 11:20:35 124

原创 6-8 求二叉树高度 (20 分)

int GetHeight( BinTree BT ){ if(!BT) return 0; else{ int h1=GetHeight(BT->Left); int h2=GetHeight(BT->Right); return h1>h2?h1+1:h2+1; }}

2021-04-13 10:45:13 121

原创 6-7 在一个数组中实现两个堆栈 (20 分)

Stack CreateStack( int MaxSize ){ Stack s=(Stack)malloc(sizeof(struct SNode)); s->Data= (int *)malloc(MaxSize*sizeof(int)); s->MaxSize=MaxSize; s->Top1=-1; s->Top2=MaxSize; return s;}bool Push( Stack S, ElementType X,

2021-04-12 20:00:53 157

原创 6-6 带头结点的链式表操作集 (20 分)

List MakeEmpty(){ List L=(List)malloc(sizeof(struct LNode)); L->Next=NULL; return L;}Position Find( List L, ElementType X ){ List p=L->Next; while(p){ if(p->Data==X){ return p; } p=p->N

2021-04-12 19:22:15 127

原创 6-5 链式表操作集 (20 分)

Position Find( List L, ElementType X ){ List p=L; while(p){ if(p->Data==X) break; p=p->Next; } if(!p) return ERROR; else return p;}List Insert( List L, ElementType X, Position P ){

2021-04-12 15:20:54 206

原创 6-2 顺序表操作集 (20 分)

List MakeEmpty(){ List L=(List)malloc(sizeof(struct LNode)); //malloc来创建 memset(L->Data,0,sizeof(L->Data)); L->Last=-1; return L;}Position Find( List L, ElementType X ){ for(int i=0;i<=L->Last;i++){ if(L->D

2021-04-11 19:23:41 230

原创 6-1 单链表逆转 (20 分)

List Reverse( List L ){ List q,p=L; L=NULL; while(p){ q=p; p=p->Next; q->Next=L; L=q; } return L;}

2021-04-11 18:28:41 124

原创 C语言考试练习题_时间间隔

#include <iostream>#include <cstring>#include <algorithm>#include <cmath>using namespace std;int main(){ int h1,m1,s1,h2,m2,s2; scanf("%d:%d:%d",&h1,&m1,&s1); scanf("%d:%d:%d",&h2,&m2,&s2);

2021-03-25 20:06:03 575

原创 括号匹配

代码:利用栈#include <iostream>#include <cstring>#include <stack>#include <algorithm>using namespace std;int main(){ int t; string a; cin>>t; cin.get(); while(t--){ stack<char> s; ci

2021-03-25 11:56:27 145

原创 加法与减法

代码:这题吐了,我还以为只有两个加数,但是想要AC,必须是累加器。#include <iostream>#include <cstring>#include <map>using namespace std;int main(){ int n; cin>>n; cin.get(); string s,t; while(n--){ cin>>s; int b=0,s

2021-03-25 11:27:52 137

原创 万众期待GCD

#include <iostream>#include <cstring>using namespace std;int get(int a,int b){ int r; while(r=a%b){ a=b; b=r; } return b;}int main(){ int gcd,lcm; while(cin>>gcd>>lcm){ int a=gcd

2021-03-25 10:40:13 114

原创 K公好色【动态规划】

#include <cstring>#include <cstdio>#include <iostream>using namespace std;long long dp[35][35];long long fun(int n,int k){ if(dp[n][k]>=0){ return dp[n][k]; } long long ans; if(n==0){ if(k%2==0)

2021-03-25 10:16:23 185

原创 恶毒的P

思路:0<x<=1000000000的范围太多,不适合遍历,反向思考S(x)的范围在1~81;代码:#include <iostream>#include <cstring>using namespace std;int getsum(int n){ int s=0; while(n){ s+=n%10; n/=10; } return s;}int main(){ int a,

2021-03-25 09:53:40 116

原创 Extra又做算数

代码:不用pow提高效率#include <cstring>#include <cstdio>#include <iostream>#include <map>using namespace std; int main(){ int a; int n[32]; while(cin>>a&&a!=0){ int k=0,t=0; while(a){

2021-03-24 21:55:31 106

原创 Extra玩弹珠

代码:原本写了一个O(n^3),发现第二个数据都过不去,直接降到O(n)#include <cstring>#include <cstdio>#include <iostream>#include <map>using namespace std; int main(){ long long n; int t; scanf("%d",&t); while(t--){ cin>>

2021-03-24 21:54:25 115

原创 Extra爱嘚瑟

思路:所有数值尾数不断幂次相乘,都会每四轮一循环。通过这个规律可以很简单的求解高次幂。2¹=2 2²=4 2³=8 2⁴=6 2⁵=23¹=3 3²=9 3³=7 3⁴=1 3⁵=34¹=4 4²=6 4³=4 4⁴=6 4⁵=45¹=5 5²=5 5³=5 5⁴=5 5⁵=56¹=6 6²=6 6³=6 6⁴=6 6⁵=67

2021-03-24 20:39:17 111

原创 Extra 做算术

#include <cstring>#include <cstdio>#include <iostream>#include <map>using namespace std;int main(){ int t; cin>>t; string a,b; int k=1; while(t--){ cin>>a>>b; int l1=a.size

2021-03-24 19:10:50 144

原创 Extra炮女胖友【两种方法】

空间换时间:#include <cstring>#include <cstdio>#include <iostream>#include <map>using namespace std;int main(){ int t; cin>>t; int a[1001]; while(t--){ map<int,int> MAP; int n,x;

2021-03-24 18:40:24 166

原创 字符串替换【find()和replace()函数】

代码:#include <cstring>#include <cstdio>#include <iostream>using namespace std;int main(){ string a; string b="you",c="we"; while(getline(cin,a)){ while(a.find(b)!=string::npos){ a.replace(a.find(b),3,

2021-03-24 12:16:41 786

原创 分数加减法

#include <string.h>#include <stdio.h>int get(int a,int b){ int r; if(a<0){ a=-a; } while(r=a%b){ a=b; b=r; } return b;}int main(){ int a,b,c,d; char o; while(scanf("%d/%d%c%d/%

2021-03-24 11:59:20 130

原创 马戏团【动态规划】

#include <iostream>#include <cstring>using namespace std;int dp[21][21];int fun(int n,int k){ //k表示余额份数 if(dp[n][k]>=0) return dp[n][k]; int ans; if(k<0||k>n) //当余额小于0,或者余额超过n份 ans = 0; else if(n==

2021-03-23 19:23:22 213

原创 我删我删,删删删

#include <iostream>#include <cstring>using namespace std;int main(){ string a,t; int n; while(cin>>a>>n){ string mi=a; for(int i=0;i<n;i++){ int l=mi.size(); string temp=mi

2021-03-23 18:51:22 758

原创 KY180 堆栈的使用

利用stack:#include <iostream>#include <cstring>#include <algorithm>#include <stack>using namespace std;int main(){ int n; stack<int> s; while(cin>>n){ if(n==0) break; char c;

2021-03-22 21:36:31 142

原创 KY179 搬水果

思路:哈夫曼编码代码:#include <iostream>#include <cstring>#include <algorithm>#include <map>using namespace std;int main(){ int n,a[10005]; map<int,bool> MAP; while(cin>>n){ if(n==0) break;

2021-03-22 21:19:06 134

原创 KY176 排列与二进制

思路:归根结底就是在问n*(n-1)……(n-m+1)能整除几次2。也就是上述乘积里面能分解出几个2。那么,可以把每个乘数分别判其断能分解出的2的数量,然后加在一起就是乘积能分解出的2的数量。代码:#include <iostream>#include <cstring>#include <algorithm>#include <map>using namespace std;int main(){ int n,m; whi

2021-03-22 20:44:44 142

原创 KY171 计算两个矩阵的乘积

#include <iostream>#include <cstring>#include <algorithm>#include <map>using namespace std;int main(){ int a[2][3],b[3][2]; for(int i=0;i<2;i++){ for(int j=0;j<3;j++){ cin>>a[i][j];

2021-03-22 15:11:50 94

原创 KY167 数字阶梯求和

#include <iostream>#include <cstring>#include <algorithm>#include <map>using namespace std;int main(){ int n; string a; while(cin>>a>>n){ string s="",t=""; for(int i=0;i<n;i++){

2021-03-22 14:33:38 117

原创 KY151 ZOJ问题

#include <iostream>#include <cstring>#include <algorithm>#include <map>using namespace std;int main(){ string a; while(getline(cin,a)){ int fro=0,mid=0,rear=0; int i=0; for(;i<a.length();i++)

2021-03-21 15:16:40 119

原创 KY150 最小长方形

#include <iostream>#include <cstring>#include <algorithm>#include <map>using namespace std;int main(){ int a,b; while(scanf("%d %d",&a,&b)){ if(a==0&&b==0){ break; }

2021-03-21 14:59:31 95

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除