#
//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;//定義堆棧的動態(tài)容量
public:
mystack();//重載默認(rèn)構(gòu)造函數(shù)
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,操作成功返回所需要的整數(shù);


{
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();
}
摘要: 寫這篇文章的初衷是應(yīng)一個網(wǎng)友的要求,當(dāng)然我也發(fā)現(xiàn)現(xiàn)在有關(guān)人工智能的中文站點實在太少,我在這里拋磚引玉,希望大家都來熱心的參與。還是說正題,我先拿A*算法開刀,是因為A*在游戲中有它很典型的用法,是人工智能在游戲中的代表。A*算法在人工智能中是一種典型的啟發(fā)式搜索算法,為了說清楚A*算法,我看還是先說說何謂啟發(fā)式算法。1、何謂啟發(fā)式搜索算法 在說它之前先提提狀態(tài)空間搜索。狀態(tài)空間搜索,如果按專業(yè)點...
閱讀全文
摘要: 初賽一
#include <stdio.h> #include <stdlib.h> #include <string.h> #define _MAXL 2000000 void GetN(char *s,long long &am...
閱讀全文
昨天晚上11點鐘,其實我正在寫那個pots,俺們班長突然跑過來叫我寫份觀奧運(yùn)圣火的感言,汗~沒辦法,奧運(yùn)啊,不能拒絕的,所以就寫了份,反正也不是太重要,發(fā)到博客上也可以順便保存下 呵呵。
夢想從這里開始
5月27日,對于每一個南京人都有著特殊的意義,因為今天——奧運(yùn)圣火將在在南京傳遞,為了親自迎接奧運(yùn)圣火,計算機(jī)學(xué)院07級的全體同學(xué),穿著整齊的奧運(yùn)T恤衫,早早的等候在火炬手將要出現(xiàn)的地方。當(dāng)奧運(yùn)圣火出現(xiàn)的那一刻,我非常的激動,在我有生之年能和奧運(yùn)圣火零距離的接觸,那種感覺真是無法表達(dá)出來來的!!我們手中揮舞著奧運(yùn)五環(huán)旗和鮮艷的五星紅旗,高喊著:“北京加油!奧運(yùn)加油!汶川挺住,中國加油。”即使嗓子嘶啞了,也無法澆滅我們心中的那股激動之情。因為國殤之后生活傳遞已經(jīng)被賦予了更多的內(nèi)涵,是我們民族信心傳遞,也是我們民族愛心的傳遞,象征著我們的奧運(yùn)情,愛國心!
我想:奧運(yùn)圣火就像太陽一樣照亮每個人的心靈,點燃每個人心中深埋已久的夢想。其實我們每個人的心里都有一把火炬,不同的是,火炬手們傳遞的是和平團(tuán)結(jié)的奧運(yùn)精神,而我們志愿者,傳遞的則是中國人——南京人的熱情與文明!
--weitao
摘要: 有史以來寫的最爛的一個程序,居然寫到5000B,勉強(qiáng)16MS AC.題意就是有名的倒水游戲,給你2個一定容量的容器,然后要求你配出一定兩的溶液并輸出每一步的決策;此題的算法當(dāng)然是BFS啦,不過貌似有人告訴我說數(shù)論里有更好的方法,我感覺也是這樣,我寫的代碼實在是有點冗長。。。 algorithm=搜索+回溯。 有這幾個字就足夠了;值得一提的...
閱讀全文
題目大意就洗兩副牌,重復(fù)不停地洗,直到出現(xiàn)給定的順序為止 輸出洗牌步數(shù)即可,簡單模擬一下洗牌和分牌的動作 這道題就不難了
呵呵 AC這道題只用了20分鐘;
不過我有點弄不明白的是網(wǎng)上都說這個題是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;
}
摘要: 不知道數(shù)論里面是不是有相關(guān)的公式,總之這道題我做的有點暴力,呵呵,一個BFS搞定;要說具體的算法的話,就是【】【】【】【】這 四個數(shù)位按從左到右的順序每次改變一個位置上的數(shù)字,如果這個數(shù)字是質(zhì)數(shù),就把它放入隊列,并記錄下到達(dá)這個數(shù)字所要經(jīng)歷的步數(shù)即可,然后循環(huán)搜索,搜到跳出。。。有點遺憾的是,這道題我寫的有點長,如果你有更好的想法,不妨告訴我哦 謝謝啦O(∩_∩)O~
#...
閱讀全文
摘要: 早知道要寫這么長 就用類寫了 呵呵//copyright by abilitytao,Nanjing University of Science and Technology//thanks to Mr Xu Chungen//本程序在商人數(shù)<=1000,隨從數(shù)<=1000時測試通過,其余數(shù)據(jù)不能保證其正確性.#include<iostream>#include <w...
閱讀全文
摘要: 問題描述: 三個商人各帶一個隨從乘船過河,一只小船只能容納2人,由他們自己劃船。三個商人竊聽到隨從們密謀,在河的任意一岸上,只要隨從的人數(shù)比商人多,就殺掉商人。但是如何乘船渡河的決策權(quán)在商人手中,商人們?nèi)绾伟才哦珊佑媱澊_保自身安全?數(shù)學(xué)建模課上,老師給我們出了這樣一個問題,要我們編程解決,呵呵,于是,就寫了下面這個程序,這個程序適用于商人數(shù)和隨從數(shù)都《=1000的情況,并且約定小船的容量為2,此程...
閱讀全文