经典小程序
处变不惊
这个作者很懒,什么都没留下…
展开
-
数塔
#includeint fun1(int a,int b){ return a>b?a:b;}int fun2(int num){ int i,j,m,n; int a[10][10]={0},d[10][10]={0}; for (i=0;i<num;i++) for (j=0;j<=i;j++) scanf("%d",&a[i][j]); for原创 2015-08-14 22:13:49 · 285 阅读 · 0 评论 -
HDU 2088 Calculate S(n)
Calculate S(n)Time Limit: 10000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 9599 Accepted Submission(s): 3479Problem DescriptionCalculate S(n).S原创 2016-01-15 16:20:22 · 338 阅读 · 0 评论 -
Hdu 1085 Holding Bin-Laden Captive!
Problem DescriptionWe all know that Bin-Laden is a notorious terrorist, and he has disappeared for a long time. But recently, it is reported that he hides in Hang Zhou of China!“Oh, God! How ter原创 2016-05-03 16:18:59 · 209 阅读 · 0 评论 -
子集生成(三种办法)
下面附上三种生成子集的算法代码,来自算法竞赛入门经典#include#include#include#include#include#include#includeusing namespace std;#define ll long longconst int INF=0x7fffffff;const int N=100000+2;int n,A[16],B[16];原创 2016-09-12 20:39:46 · 652 阅读 · 0 评论 -
最大约数
算法导论中的题目,老师让用素数去实现查找最大约数个数#include#include#include#include#include#include#includeusing namespace std;#define ll long longconst int INF=0x7fffffff;const int N=100000+2;int prime[1005];vo原创 2016-09-14 15:32:36 · 350 阅读 · 0 评论 -
hdu 1025 Constructing Roads In JGShining's Kingdom
Problem DescriptionJGShining's kingdom consists of 2n(n is no more than 500,000) small cities which are located in two parallel lines.Half of these cities are rich in resource (we call them ri原创 2016-10-19 18:58:56 · 195 阅读 · 0 评论 -
常用小方法的整理(1)
求组合数int fun(int m,int n){ int i; __int64 sum=1; for (i=1;i<=m;i++) sum=sum*(n-i+1)/i; return sum;}用异或实现两个数字的交换int main(){ int m,n; scanf("%d%d",&m,&n); m^=n;原创 2016-05-07 18:03:59 · 455 阅读 · 0 评论 -
斐波那契数列+大数加法
#include int main(int argc, char* argv[]){ int nBinary = 0; int nDigital = 1; int nTemp = 0; int nMark = 0; int nNumber = 0; int nNumberArrayOne[10000] = {0}; int nNumberArrayTwo[1000原创 2015-08-14 21:57:57 · 1269 阅读 · 0 评论 -
排列的字典序问题 算法与设计
问题描述:n个元素{1,2,, n }有n!个不同的排列。将这n!个排列按字典序排列,并编号为0,1,…,n!-1。每个排列的编号为其字典序值。例如,当n=3时,6 个不同排列的字典序值如下:字典序值 0 1 2 3 4 5排列 123 132 213 231 312 321算法设计:给定n以及n个元素{1,2,,原创 2016-10-12 16:10:41 · 1965 阅读 · 3 评论 -
矩阵连乘
问题描述:给定n个矩阵:A1,A2,...,An,其中Ai与Ai+1是可乘的,i=1,2...,n-1。确定计算矩阵连乘积的计算次序,使得依此次序计算矩阵连乘积需要的数乘次数最少。输入数据为矩阵个数和每个矩阵规模,输出结果为计算矩阵连乘积的计算次序和最少数乘次数。 问题解析:由于矩阵乘法满足结合律,故计算矩阵的连乘积可以有许多不同的计算次序。这种计算次序可以用加括号的方式来确定。若一原创 2017-01-04 14:48:55 · 414 阅读 · 0 评论 -
HDU 5907 Find Q
Problem DescriptionByteasar is addicted to the English letter 'q'. Now he comes across a string S consisting of lowercase English letters.He wants to find all the continous substrings of S,原创 2017-02-21 22:35:14 · 412 阅读 · 0 评论 -
高精度模板 大数的基本运算
#include #include #include #include #include #include using namespace std;const int MAXN = 410; //数字的最大长度,根据情况自己调整struct bign{ int len, s[MAXN]; bign () { memset(s, 0, sizeof(s));转载 2017-05-02 15:59:30 · 227 阅读 · 0 评论 -
常用小方法整理(2)
欧拉函数整理,能够快速计算与n互质的或者叫互素的数字个数,利用的是容斥原理int eular(int n) { int ans=1,i; for (i=2;i*i<=n;i++) if (n%i==0) //(1) { n/=i; ans*=(i-1);原创 2016-11-01 22:22:02 · 273 阅读 · 0 评论 -
常用小方法整理3
错排公式n各有序的元素应有n!种不同的排列。如若一个排列式的所有的元素都不在原来的位置上,则称这个排列为错排。核心递推公式:D(n) = (n-1) [D(n-2) + D(n-1)]特殊地,D(1) = 0, D(2) = 1.欧拉回路的判定一.无向图一个无向图存在欧拉路径,当且仅当 该图所有顶点的度数为偶数 或者 除了两个度数为奇数外其余的全是偶数。原创 2017-05-03 09:47:28 · 260 阅读 · 0 评论 -
牛客网 成绩排序
题目描述查找和排序题目:输入任意(用户,成绩)序列,可以获得成绩从高到低或从低到高的排列,相同成绩 都按先录入排列在前的规则处理。 例示: jack 70 peter 96 Tom 70 smith 67 从高到低 成绩 peter 96 jack 70 ...原创 2018-03-06 15:35:16 · 853 阅读 · 3 评论 -
最长连续子序列
#includeint main(){ int n,a[100],i,start,end; while (~scanf("%d",&n)) { int b=0,max=-999999,j=0; for (i=1;i<=n;i++) { scanf("%d",&a[i]); b+=a[i]; j++; if (b>max原创 2015-09-22 21:00:43 · 346 阅读 · 0 评论 -
链表的普通应用
#include#includetypedef struct Node{ int ID; float salary; struct Node* next;}Employee;Employee *Create_T(int n) //尾插法{ Employee *Head,*cur,*pNew; int i; Head=cur=NULL; //很重要,原创 2015-08-14 22:25:15 · 264 阅读 · 0 评论 -
快速求幂的最后一位
这存在一个规律,每四次一循环#includeint main(){ __int64 m,n; while (~scanf("%I64d %I64d",&m,&n)) { int c,a[5]; a[1]=m%10; a[2]=a[1]*m%10; a[3]=a[2]*m%10; a[4]=a[3]*m%10; c=n%4; if (原创 2015-08-14 22:07:05 · 167 阅读 · 0 评论 -
默认函数实现全排列
#include#include#include#includeusing namespace std;#define N 1047int num[N];int main(){ int n,m,i,k; while (~scanf("%d%d",&n,&m)) { memset(num,0,sizeof(num)); for原创 2015-08-14 21:22:28 · 293 阅读 · 0 评论 -
Max Sum
#includeint main(){ int a,b,c,d,k,i,j,m,n,s,p=0; scanf("%d",&k); while (k--) { a=0;j=0;s=-1000; scanf("%d",&d); for (i=0;i<d;i++) { scanf("%d",&b); a=a+b; j++;原创 2015-08-14 21:44:00 · 208 阅读 · 0 评论 -
多数求最大公倍数
#includeint fun(int m,int n){ return n==0?m:fun(n,m%n);}int main(){ int m,n,k,a; while (~scanf("%d",&m)) { int i; scanf("%d",&a); for (i=1;i<m;i++) { scanf("%d",&n);原创 2015-08-14 21:55:54 · 117 阅读 · 0 评论 -
一维数组实现01背包
若刚开始接触0-1背包问题,建议自己打印出表,结合着程序来理解。原创 2015-08-14 21:20:08 · 354 阅读 · 0 评论 -
二维数组实现0-1背包
#include using namespace std;int m[1001][1001]={0};void beibao(int n,int v,int c[],int w[]){ int i,j; for(i=1;i<=n;i++) for(j=1;j<=v;j++) //i表示物品种类,j表示背包容原创 2015-08-14 21:35:18 · 554 阅读 · 0 评论 -
免费馅饼
当真正理解这题的意思时,会发现这个题真的很水,是动态规划的一个很好的引例#includeint fun1(int a,int b,int c){ int max; max=a>b?a:b; max=max>c?max:c; return max;}int fun2(int num){ int a[11][12]={0},count=-1; int i,原创 2015-08-14 22:09:24 · 259 阅读 · 0 评论 -
字符串查找最大值问题
#include#includeint main(){ int n,len_max,j,i,m=1; char c[20],a[20]; scanf("%d",&n); while (n--) { printf("Case %d:\n",m); m++; scanf("%s",c); len_max=0; for (i=0;i<s原创 2015-08-14 22:20:50 · 1057 阅读 · 0 评论 -
孪生素数
#include#include#includeint is_prime(int x){ int i,m; assert(x>=0); if (x==1) return 0; m=floor(sqrt(x)+0.5); for (i=2;i<=m;i++) if (x%i==0) return 0; return 1;}int mai原创 2015-08-14 22:26:35 · 603 阅读 · 0 评论 -
母数拆分
#include int a[1000];int backtrack(int n,int t,int temp){ int i; if(n==0){ for(i=0;i<t-1;i++) printf("%d+",a[i]); printf("%d\n",a[t-1]); } else for(i=n;i>0;i--) if(i<=temp){ a[原创 2015-08-14 22:23:05 · 363 阅读 · 0 评论 -
大数加法(补零)
#include#includeint main(){ int max,m,n,k=0,i,j,min; char a[100],b[100],c[100]; int sum[100]; scanf("%s%s",a,b); m=strlen(a); n=strlen(b); if(m>n) { for (i=0;i c[i]='原创 2015-08-14 21:53:30 · 371 阅读 · 0 评论 -
编程实现全排列
#includevoid swap(int *a,int *b){ int m; m=*a; *a=*b; *b=m;}void fun(int a[],int m,int n){ int i;if (m>n){ for (i=0;i printf("%d ",a[i]); printf("\n"原创 2015-08-14 21:24:39 · 1087 阅读 · 0 评论 -
大数加法1
#include #include int main() { char a1[1100],b1[1100]; int T; while(scanf("%d",&T)!=EOF) { int i1,i,j,k,k1,La,Lb,t,L; for(i1=1;i1<=T;i1++)原创 2015-08-14 21:52:02 · 522 阅读 · 0 评论 -
6174问题
#include#includeint num[200],count;int Get(int x){ int a,i,b,n; char s[10]; sprintf(s,"%d",x); //将数字以字符串的形式保存到字符s中; n=strlen(s); for (i=0;i<n;i++) for (int j=i+1;j<n;j++) if (s[i]原创 2015-08-14 21:41:33 · 260 阅读 · 0 评论 -
开灯问题
#include #include#define MAX 1010int main(){ int a[MAX]; int i,j,k,n,m=1; memset(a,0,sizeof(a)); scanf("%d%d",&n,&k); for (i=1;i<=k;i++) for (j=1;j<=n;j++) if (j%i==0) a[原创 2015-08-14 22:03:31 · 278 阅读 · 0 评论 -
二分法控制精度
#include<stdio.h>const double EPSINON=1e-10;// 二分法控制精度 例子:求sqrt(2) 的精确值int main(){ double low=1.4; double high=1.5; double mid=(low+high)/2; while (high-low>EPSINON){...原创 2019-06-17 16:00:07 · 1970 阅读 · 1 评论