The Fourth Dimension Space

枯叶北风寒,忽然年以残,念往昔,语默心酸。二十光阴无一物,韶光贱,寐难安; 不畏形影单,道途阻且慢,哪曲折,如渡飞湍。斩浪劈波酬壮志,同把酒,共言欢! -如梦令

#

动态链表式堆栈 by abilitytao

//template_by_abilitytao_ACM
//many thanks to Mr Zhang Hong and Yu Ligong

#include 
<algorithm>
#include
<cstdio>
#include
<cmath>
#include
<cstdlib>
#include
<iostream>
#include
<cstdio>
using namespace std;
struct node {
    
int data;
    node 
*next;
}
;

class mystack 
{
private:
    node
* ptop;//定义栈顶指针
    int lenth;//定义堆栈的动态容量
public:
    mystack();
//重载默认构造函数
    int push(int num);//压栈操作
    int pop();//退栈操作
    int top();//返回栈顶元素
    int size();//返回堆栈的实际容量
    bool empty();
    
bool full();
}
;

mystack::mystack()
{

    ptop
=NULL;
    lenth
=0;
}



int mystack::push(int num)//操作成功,返回1;
{

    node 
*p=new node;
    p
->data=num;
    p
->next=ptop;
    ptop
=p;//由于链表式堆栈没有容量上线,故返回值为1;
    lenth++;
    
return 1;
    
return 0;
}


int mystack::pop()//堆栈为空返回0,操作成功返回所需要的整数;
{
    
if(ptop==NULL)
        
return 0;
    
int result;
    result
=ptop->data;
    node 
*p=ptop;
    ptop
=p->next;
    delete p;
    lenth
--;
    
return result;
}


int mystack::top()
{
    
if(ptop==NULL)
        
return 0;
    
return ptop->data;
}



int mystack::size()
{
    
return lenth;
}


bool mystack::empty()
{

    
if (ptop==NULL)
        
return true;
    
else
        
return false;
}


bool mystack::full()
{

    
return false;//仅仅为了提高模板的健壮性
}







//////////////////////////////////////////////////////////////////////////test data////////////////////////////////////////////////////////////////////////////
int main ()
{

    mystack test;
    test.push(
1);
    test.push(
2);
    test.push(
3);
    test.push(
4);
    test.push(
5);
    test.push(
6);
    test.push(
7);
    
int a=test.size();
    a
=test.top();
    a
=test.pop();
    a
=test.top();
    a
=test.pop();
    a
=test.top();
    a
=test.pop();
    a
=test.top();
    a
=test.pop();
    a
=test.pop();
    a
=test.pop();
    a
=test.top();
    a
=test.pop();
    a
=test.pop();
    a
=test.top();
    a
=test.empty();
}

posted @ 2009-03-02 21:48 abilitytao 阅读(1076) | 评论 (3)编辑 收藏

动态循环队列模板类——链表实现

 

//template_by_abilitytao_ACM
//Begin_template_myqueue
//这是一个非常高效的循环链表队列
#include<iostream>
#include
<cmath>
#include
<algorithm>
#include
<cstring>
#include
<cstdio>
using namespace std;

struct node {
    
int data;
    node
* next;
}
;

class myqueue
{
private:
    node 
*prear;
    
int lenth;
public:
    myqueue();
    
int push(int num);
    
int pop();
    
int front();
    
int rear();
    
int len();
    
bool empty();
    
bool full();
    
}
;


myqueue::myqueue()
{

    prear
=new node;
    prear
->data=0x7fffffff;
    prear
->next=prear;
    lenth
=0;
}



int myqueue::push(int num)//入队成功返回1,否则返回0 。问:(返回0有可能吗?如果内存不够系统内部有 返回值吗,猜:返回null?)
{
    
{
        node 
*p=new node;
        p
->data=num;
        p
->next=prear->next;
        prear
->next=p;
        prear
=p;
        lenth
++;
        
return 1;
    }

    
return 0;
}


int myqueue::pop()//如果出队成功返回1,勾着否则返回0;
{
    
if(prear->next==prear)
        
return 0;
    node 
*p=prear->next;
    node 
*q=prear->next->next;
    p
->next=q->next;
    delete q;
    
if(p=p->next)
        prear
=p;
    
--lenth;
}


int myqueue::front()//队列为空返回0,否则返回队首元素的值
{

    
if(prear->next==prear)
        
return 0;
    node
*p=prear->next->next;
    
return p->data;

}


int myqueue::rear()//队列为空返回值为0,否则返回队尾元素的值
{
    
if(prear->next==prear)
        
return 0;
    
return prear->data;
}


int myqueue::len()
{
    
return lenth;
}


bool myqueue::empty()
{

    
if(prear->next==prear)
        
return true;
    
else
        
return false;
}


bool myqueue::full()//为了提高本模板的兼容性,故提供此函数,其实函数的返回值永远不可能为1;
{
    
return false;
}

//endtemplate_by_abilitytao_ACM

////////////////////////////////////////////////////////////////////下面是测试数据////////////////////////////////////////////////////////////////////////////
int main ()
{

    myqueue test;
    
int a=test.len();
    
bool b=test.empty();
    test.push(
1);
    test.push(
2);
    a
=test.front();
    a
=test.rear();
    a
=test.len();
    b
=test.empty();
    b
=test.full();
    a
=test.pop();
    a
=test.front();
    a
=test.rear();
    a
=test.pop();
    a
=test.front();
    a
=test.rear();

}


posted @ 2009-03-02 21:00 abilitytao 阅读(1614) | 评论 (0)编辑 收藏

A*算法详解——by Sunway

     摘要: 写这篇文章的初衷是应一个网友的要求,当然我也发现现在有关人工智能的中文站点实在太少,我在这里抛砖引玉,希望大家都来热心的参与。还是说正题,我先拿A*算法开刀,是因为A*在游戏中有它很典型的用法,是人工智能在游戏中的代表。A*算法在人工智能中是一种典型的启发式搜索算法,为了说清楚A*算法,我看还是先说说何谓启发式算法。1、何谓启发式搜索算法  在说它之前先提提状态空间搜索。状态空间搜索,如果按专业点...  阅读全文

posted @ 2009-03-01 21:34 abilitytao 阅读(6387) | 评论 (9)编辑 收藏

ACRUSH-楼天成 百度之星答题源码

     摘要: 初赛一 #include <stdio.h> #include <stdlib.h> #include <string.h> #define _MAXL 2000000 void GetN(char *s,long long &am...  阅读全文

posted @ 2009-03-01 20:51 abilitytao 阅读(6500) | 评论 (4)编辑 收藏

梦想从这里开始——观奥运圣火传递感言

昨天晚上11点钟,其实我正在写那个pots,俺们班长突然跑过来叫我写份观奥运圣火的感言,汗~没办法,奥运啊,不能拒绝的,所以就写了份,反正也不是太重要,发到博客上也可以顺便保存下 呵呵。

 

 

梦想从这里开始

527,对于每一个南京人都有着特殊的意义,因为今天——奥运圣火将在在南京传递,为了亲自迎接奥运圣火,计算机学院07级的全体同学,穿着整齐的奥运T恤衫,早早的等候在火炬手将要出现的地方。当奥运圣火出现的那一刻,我非常的激动,在我有生之年能和奥运圣火零距离的接触,那种感觉真是无法表达出来来的!!我们手中挥舞着奥运五环旗和鲜艳的五星红旗,高喊着:“北京加油!奥运加油!汶川挺住,中国加油。”即使嗓子嘶哑了,也无法浇灭我们心中的那股激动之情。因为国殇之后生活传递已经被赋予了更多的内涵,是我们民族信心传递,也是我们民族爱心的传递,象征着我们的奥运情,爱国心!

我想:奥运圣火就像太阳一样照亮每个人的心灵,点燃每个人心中深埋已久的梦想。其实我们每个人的心里都有一把火炬,不同的是,火炬手们传递的是和平团结的奥运精神,而我们志愿者,传递的则是中国人——南京人的热情与文明!

--weitao

 


posted @ 2009-03-01 13:27 abilitytao 阅读(187) | 评论 (0)编辑 收藏

POJ 3414-Pots BFS (代码好长啊 ,建议大家不要看了)

     摘要: 有史以来写的最烂的一个程序,居然写到5000B,勉强16MS AC.题意就是有名的倒水游戏,给你2个一定容量的容器,然后要求你配出一定两的溶液并输出每一步的决策;此题的算法当然是BFS啦,不过貌似有人告诉我说数论里有更好的方法,我感觉也是这样,我写的代码实在是有点冗长。。。    algorithm=搜索+回溯。   有这几个字就足够了;值得一提的...  阅读全文

posted @ 2009-03-01 01:10 abilitytao 阅读(1033) | 评论 (0)编辑 收藏

POJ 3087-Shuffle'm Up(洗牌游戏) 模拟题

题目大意就洗两副牌,重复不停地洗,直到出现给定的顺序为止 输出洗牌步数即可,简单模拟一下洗牌和分牌的动作 这道题就不难了
呵呵 AC这道题只用了20分钟;
不过我有点弄不明白的是网上都说这个题是BFS?我怎么感觉一点也不像啊???
#include <iostream>
#include
<algorithm>
#include
<cmath>
#include 
<cstring>
using namespace std;

char origin1[200];
char origin2[200];
char mix[1000];
char des[1000];
int c;

void shuffle(char a[],char b[])
{
    
int i=0;
    
int j=0;
    
int pos=0;
    
int flag=1;

    
while(pos<=2*c-1)
    
{
        
if(flag==1)
        
{

            mix[pos]
=b[i];
            j
++;
            pos
++;
            flag
=2;
        }

        
else if(flag==2)
        
{
            mix[pos]
=a[i];
            i
++;
            pos
++;
            flag
=1;
        }

        mix[pos]
='\0';


    }

}


void separate()
{
    
int i;
    
for(i=0;i<c;i++)
        origin1[i]
=mix[i];
    
for(i=c;i<2*c;i++)
        origin2[i
-c]=mix[i];
    origin1[c]
='\0';
    origin2[c]
='\0';
}



int main ()
{
    
int step;
    
int testcase;
    
int i;
    
char test1[200];
    
char test2[200];
    
int flag;
    scanf(
"%d",&testcase);
    
for(i=1;i<=testcase;i++)
    
{
        flag
=0;
        step
=0;
        scanf(
"%d",&c);
        scanf(
"%s",origin1);
        scanf(
"%s",origin2);
        scanf(
"%s",des);
        strcpy(test1,origin1);
        strcpy(test2,origin2);
        
while(1)
        
{
            shuffle(origin1,origin2);
            step
++;
            
if(strcmp(mix,des)==0)
                
break;

            separate();
            
if(strcmp(test1,origin1)==0&&strcmp(test2,origin2)==0)
            
{
                flag
=1;
                
break;
            }


        }

        
if(flag==0)
            printf(
"%d %d\n",i,step);
        
else
            printf(
"%d -1\n",i);
    }

    system(
"pause");
    
return 0;
}

posted @ 2009-02-28 20:06 abilitytao 阅读(1375) | 评论 (5)编辑 收藏

POJ 3126-Prime Path 广度优先搜索BFS

     摘要: 不知道数论里面是不是有相关的公式,总之这道题我做的有点暴力,呵呵,一个BFS搞定;要说具体的算法的话,就是【】【】【】【】这 四个数位按从左到右的顺序每次改变一个位置上的数字,如果这个数字是质数,就把它放入队列,并记录下到达这个数字所要经历的步数即可,然后循环搜索,搜到跳出。。。有点遗憾的是,这道题我写的有点长,如果你有更好的想法,不妨告诉我哦 谢谢啦O(∩_∩)O~ #...  阅读全文

posted @ 2009-02-27 22:31 abilitytao 阅读(1296) | 评论 (0)编辑 收藏

数学建模——商人过河问题 Beta2.0

     摘要: 早知道要写这么长 就用类写了 呵呵//copyright by abilitytao,Nanjing University of Science and Technology//thanks to Mr Xu Chungen//本程序在商人数<=1000,随从数<=1000时测试通过,其余数据不能保证其正确性.#include<iostream>#include <w...  阅读全文

posted @ 2009-02-26 20:06 abilitytao 阅读(3536) | 评论 (9)编辑 收藏

数学建模之——商人过河问题 算法核心:搜索法

     摘要: 问题描述: 三个商人各带一个随从乘船过河,一只小船只能容纳2人,由他们自己划船。三个商人窃听到随从们密谋,在河的任意一岸上,只要随从的人数比商人多,就杀掉商人。但是如何乘船渡河的决策权在商人手中,商人们如何安排渡河计划确保自身安全?数学建模课上,老师给我们出了这样一个问题,要我们编程解决,呵呵,于是,就写了下面这个程序,这个程序适用于商人数和随从数都《=1000的情况,并且约定小船的容量为2,此程...  阅读全文

posted @ 2009-02-26 11:07 abilitytao 阅读(9094) | 评论 (15)编辑 收藏

仅列出标题
共42页: First 34 35 36 37 38 39 40 41 42