- 博客(27)
- 资源 (8)
- 收藏
- 关注
原创 数据结构之顺序栈
用数组去模拟栈,利用malloc和realloc函数去增加数据的大小//author:jwfy//time:2014-1-13 pm 4:30#include "stdafx.h"#include #include #include #define ElemType intusing namespace std;const int STACKSIZE = 3;c
2014-01-13 17:52:08
706
原创 数据结构之链表-多项式相加
多项式相加主要是利用了类似于排序的思想,从第一个开始找,直到找到合适的位置,如果幂是一样的,则直接相加,否则就插入一个新的节点。// ConsoleApplication2.cpp : Defines the entry point for the console application.//author:jwfy//time:2014-1-13 pm 4:19 #i
2014-01-13 16:19:23
1110
原创 数据结构之双线链表
双向链表的相关操作// ConsoleApplication2.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include #include #include using namespace std;typedef struct Node{ int
2014-01-13 14:46:07
790
原创 数据结构之单链表操作
主要是涉及到单链表的相关操作#include "stdafx.h"#include #include #include using namespace std;typedef struct Node{ int x; Node *next;}Node,*Lnode;bool Add(int i,int num,Node& node){ // 在链表的第i
2014-01-13 12:14:23
662
原创 浅谈并查序
其实在做题目的时候,这个并查序主要就是两个函数的应用,模版提吧 1:一个数找出该点的父亲节点 2:合并根节点 不过在这之前我们必须做好初始化的工作 int father[1000],fatherson[1000] // 这里随便取数据,自己看题目的要求 void init(int n) { for(int i=0;i {
2012-10-06 12:51:22
553
原创 hdu 1232
并查序问题,看代码URL:http://acm.hdu.edu.cn/showproblem.php?pid=1232#includeusing namespace std;int f[1000],sum;int find(int x){ if(f[x]!=x) f[x]=find(f[x]); return f[x];}void make(int a,int b)
2012-10-06 11:57:25
595
原创 hdu 1856
这也是一个并查序的问题,问的是亲戚最多有多少个,其实就是计算fatherson[i]的个数,输出最多的个数URL:http://acm.hdu.edu.cn/showproblem.php?pid=1856所以在这里,我们在union函数里面要记录好那个的父亲是哪点,而且有多少个儿子,而不是随意的就接上了代码如下:#include #include #include #def
2012-10-06 11:53:05
1563
原创 hdu 1272
又是一个并查序的问题,这里有两方面1:必须是并查集2:满足点的个数比边数多一URL:http://acm.hdu.edu.cn/showproblem.php?pid=1272代码如下#include#include#define M 100010using namespace std;int father[M], mark[M];int flag;void ini
2012-10-06 11:47:57
955
原创 hdu 1213
这其实就是并查序的简单题目,看可以构建多少个数而已URL :http://acm.hdu.edu.cn/showproblem.php?pid=1213在判断有几个桌子的时候,我们一般的都是在合并完成后扫描整个父亲数组,发现几个father[i]==i,就判断有多少个树,从而需要多少个桌子这只是个模板题,没什么说的,看代码#include#include#include#in
2012-10-06 11:43:05
1916
原创 hdu 1671
// url: http://acm.hdu.edu.cn/showproblem.php?pid=1671// 该题目也主要是字典树问题,就是看里面的某一个字符串是否完全属于另一个字符串,如果有的话输出no(无法拨打电话),否则就是yes#include#include#include#includeusing namespace std;typedef struct is
2012-08-22 17:13:30
1192
原创 hdu 1251
// 字典树模版// http://acm.hdu.edu.cn/showproblem.php?pid=1251/*自己由于能力有限,这种图,树之类的还没看,更别提做了,这个字典数的题目也是花了差不多一天才完全理解其中主要是看别人的代码,自己再思考,再写,这里推荐一个人的博客,从里面学到了很多,里面很多文章都是很好的 有兴趣的可以看看,我的这个代码几乎和他的一样,差不多背下
2012-08-21 10:25:44
1070
原创 hdu 1395
// http://acm.hdu.edu.cn/showproblem.php?pid=1395 #include using namespace std; int main() { int n; while(scanf("%d",&n)!=EOF) {
2012-08-16 17:06:01
711
原创 hdu 1215
// http://acm.hdu.edu.cn/showproblem.php?pid=1215// 这和以往的求因子之和的方法不同/* 这里的主要思想是把每个数字拆开 看函数二层循环 当j是二的倍数的时候,每个j都加上2(这个2就是他的因子),这样循环下去,就能把所有的因子之和求出来了 不会有超时的现象,时间复杂度是o(nlogn)*/#in
2012-08-16 16:58:03
846
原创 hdu 2161
// http://acm.hdu.edu.cn/showproblem.php?pid=2161// 这是个简单的判断是不是素数的题目,这里有一点要注意:这里的2当作非素数#include#includeint prime[16001];void fun(){int i,j; memset(prime,1,sizeof(prime)); f
2012-08-16 16:39:56
656
原创 hdu 1286
// http://acm.hdu.edu.cn/showproblem.php?pid=1286// 这是一个数论问题,求互质的数字有多少个//////////////////////////////////////////////////////////// 用素数删选法选出满足条件的// 法一:// Accepted 1286 156MS 348K 602
2012-08-15 16:26:37
1034
原创 hdu 1576
// http://acm.hdu.edu.cn/showproblem.php?pid=1576/* 一个数论题目欧几里德扩展运算n=A%9973 就有 n=A-9973*rA%B==0 A=l*B(A/B)%9973 ans= l%9973所以有 ans=l-m*9973其中ans就是我们需要的答案A=L*B=n+9973*r=B*(ans+m*99
2012-08-14 11:42:13
1489
原创 hdu 2529
// 这就是一个物理题目,在此之前,我们必须得把物理公式化简#includeint main(){ double h,l,v,g=9.8; while(scanf("%lf%lf%lf",&h,&l,&v)!=EOF && h+l+v!=0) { h+=0.5*v*v/g-0.5*g*l*l/(v*v); printf(
2012-08-10 20:29:11
1123
原创 lIS 问题
// lis问题#includeint main(){ int n,a[10001],i,j,k,l,temp; while(scanf("%d",&n)!=EOF) { for(i=1;i<=n;i++) scanf("%d",&a[i]); l=-1; for(i=2;i<=n;i
2012-08-10 20:15:15
836
原创 hdu 1029
//http://acm.hdu.edu.cn/showproblem.php?pid=1029// 这是解法1:直接利用hash就可以快速AC#include#includeint main(){ int n,hash[50000],tem,i,j; while(scanf("%d",&n)!=EOF) { memset(hash,0,sizeof(hash)
2012-08-10 20:14:08
2146
原创 hdu 2108
// http://acm.hdu.edu.cn/showproblem.php?pid=2108#include#includestruct point{ int x; int y;}a[50];int fun(int i,int j,int k) //分别是三个点{ return (a[j].x-a[i].x)*(a[k].y-a[j].y)-(a[
2012-08-10 20:02:13
1160
原创 hdu 2549
// http://acm.hdu.edu.cn/showproblem.php?pid=2549// 这里有一个比较坑爹的地方,就是当我们找的那个数字时,数据没那么长,这时候就要输出0,其他没社么可说的 #include#includeint main(){ char a[1000]; int t,n,i; while(scanf("%d",&n)!=EOF) {
2012-08-10 19:31:53
693
原创 hdu 2552
// http://acm.hdu.edu.cn/showproblem.php?pid=2551#includeint main(){ __int64 a[1001]={0},sum=0,x,i; int t; for(i=1;i<=1000;i++) { sum+=i*i*i; a[i]=sum; } while(scanf("%d",&t)!=EOF) {
2012-08-10 19:26:09
768
原创 hdu 2554
// http://acm.hdu.edu.cn/showproblem.php?pid=2554/*没办法,只能百度了,解决之道:准备知识:①n对数,共2*n个数。所以要有2*n个位置来放置这2*n个数。②sum()表示求和运算。正式解决:①设k(k=1,2,..,n)放置的第一个位置为ak,第二个位置为bk。显然有bk-ak=k+1(假定下一个位置在上一
2012-08-10 19:18:32
729
原创 hdu 2393
// http://acm.hdu.edu.cn/showproblem.php?pid=2393#include#include#includeusing namespace std;int main(){ int n,a[3],pos; while(scanf("%d",&n)!=EOF) { pos=0; while(n
2012-08-10 07:52:03
689
原创 hdu 2601
// http://acm.hdu.edu.cn/showproblem.php?pid=2601#include#includeint main(){ int n,pos,i,q; __int64 p; while(scanf("%d",&n)!=EOF) { while(n--) { pos=0;
2012-08-09 17:34:40
1027
原创 hdu 2600
// http://acm.hdu.edu.cn/showproblem.php?pid=2600#include#include#include#include#includeusing namespace std;int main(){ int a[101],b[101],i,n,m,t; char str[50]; while(scanf("%d
2012-08-09 16:43:54
652
原创 hdu 1003
//http://acm.hdu.edu.cn/showproblem.php?pid=1003#includeint main(){ int a[100001],max,sum,n,t,flag,flag1,flag2,i,m=0; while(scanf("%d",&t)!=EOF) { while(t--) {
2012-08-09 15:42:48
790
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人