随笔分类 - 数据结构
摘要:#include #include #include #include #include using namespace std; int a[1000],n; void CRpx(){ for(int i=1;i>n){ for(int i=1;i>a[i]; } CRpx(); for(int i=1;i<=n;i++){ cout<<a[i]<<endl; ...
阅读全文
摘要:#include #include #include using namespace std; int a[100]; int n,m; void sdown(int i){ if(i==n) return ; int flag=0; while(i*2n){ if(a[i*2]=1;i--){ sdown(i); } } void ssort(){ while...
阅读全文
摘要:#include #include #include #include using namespace std; void bubsort(int *a){ for(int i=1;ia[j+1]) swap(a[j+1],a[j]); } } return ; } int main(){ int a[6]={0,9,5,1,3,7}; bubsort(a); for(...
阅读全文
摘要:#include #include #include #include using namespace std; void Choicesort(int *a){ for(int i=1;ia[j]) swap(a[i],a[j]); } } return ; } int main(){ int a[6]={0,4,5,1,3,7}; Choicesort(a); fo...
阅读全文
摘要:#include using namespace std; int s[3]={1,5,19}; void shellsort(int *a,int n){ for(int i=2;i>=0;i--){ if(s[i]>n) continue; for(int j=s[i];j<=n;j+=s[i]){ for(int k=1;k<=j;k+=s[i]){ if(a[...
阅读全文
摘要:#include using namespace std; void merge(int *arr,int l,int m,int r){ int ls=m-l,lr=r-m+1; int la[ls],ra[lr]; for(int i=l;i<=m-1;i++) la[i-l+1]=arr[i]; for(int j=m;j<=r;j++) ra[j-m+1]=...
阅读全文
摘要:#include using namespace std; int f[1000],n,m,k,sum=0; void init(){ int i; for(int i=1;i>n>>m; init(); for(int i=1;i>x>>y; merge(x,y); } f...
阅读全文
摘要:能被2整除的数的特征:如果一个数能被2整除,那么这个数末尾上的数为偶数,“0”、“2”、“4”、“6”、“8”。 能被3整除的数的特征:如果一个数能被3整除,那么这个数所有数位上数字的和是3的倍数。例如:225能被3整除,因为2 2 5=9,9是3的倍数,所以225能被3整除。 能被4整除的数的特征
阅读全文
摘要:完美代价 问题描述 回文串,是一种特殊的字符串,它从左往右读和从右往左读是一样的。小龙龙认为回文串才是完美的。现在给你一个串,它不一定是回文的,请你计算最少的交换次数使得该串变成一个完美的回文串。 交换的定义是:交换两个相邻的字符 例如mamad 第一次交换 ad : mamda 第二次交换 md
阅读全文
摘要:分巧克力 问题描述 儿童节那天有K位小朋友到小明家做客。小明拿出了珍藏的巧克力招待小朋友们。 小明一共有N块巧克力,其中第i块是Hi x Wi的方格组成的长方形。 为了公平起见,小明需要从这 N 块巧克力中切出K块巧克力分给小朋友们。切出的巧克力需要满足: 1. 形状是正方形,边长是整数 2. 大小
阅读全文
摘要:#include #include #include #include using namespace std; int book[9],n,m,o; char map[9][9]; void dfs(int num,int y){ if(num==m){ o++; return ; } if(y>n) return ; f...
阅读全文
摘要:#include #include struct node{ int x; int s; }s[400005]; int main(){ int n,m,book[400005]={0}; scanf("%d %d",&n,&m); if(n==m) printf("0\n"); else{ ...
阅读全文
摘要:1 #include 2 using namespace std; 3 struct node{ 4 int num; 5 struct node *next; 6 }; 7 int main(){ 8 struct node *p,*p1,*head; 9 head=p=(struct node *)malloc(sizeof(stru...
阅读全文
摘要:1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 int f[1000],i,ans; 7 char s[1000],a[1000]; 8 void ppx(string a){ 9 memset(f,0,sizeof(f)); 10 for(i=1;i>s){ 37 ans=0; ...
阅读全文
摘要:中国剩余定理介绍 在《孙子算经》中有这样一个问题:“今有物不知其数,三三数之剩二(除以3余2),五五数之剩三(除以5余3),七七数之剩二(除以7余2),问物几何?”这个问题称为“孙子问题”,该问题的一般解法国际上称为“中国剩余定理”。具体解法分三步: 找出三个数:从3和5的公倍数中找出被7除余1的最
阅读全文