公告

联系我:我的126邮箱: billhsu。 Locations of visitors to this page
<2024年4月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

统计

  • 随笔 - 41
  • 文章 - 0
  • 评论 - 82
  • 引用 - 0

常用链接

留言簿(16)

随笔分类

随笔档案

相册

Game Dev

搜索

  •  

最新评论

阅读排行榜

评论排行榜

stredit problem

s and t are two strings.
Change string s into string t in the least steps.
In each step you can insert or delete a char of the string.
INPUT n1 s
n2 t
n1 is the length of string s
n2 is the length of string t
OUT the least steps
exp:
INPUT 4 abcd
6 aefbhd
OUT 4

#include<iostream>
#include
<string>

using namespace std;

string s1,s2;
int map[100];
int i,j,result[100];
int n1,n2,nc;

int main(){
    cin
>>n1>>s1>>n2>>s2;
    nc
=0;
    
for (i=0;i<n1;i++){
        
if ((j=s2.find(s1[i]))>=0){
          map[nc]
=j;
          s2.replace(j,
1," ");
          nc
++;
          }
          }
    result[nc
-1]=1;
    
for (i=nc-2;i>=0;i--){
        
for (j=i+1;j<nc;j++if ((map[i]<map[j])&&(result[i]<result[j])) result[i]=result[j];
        result[i]
++;
        }
    j
=0;
    
for (i=0;i<nc;i++if(result[i]>j) j=result[i];
    cout
<<n1+n2-j-j;
    system(
"pause");
    
return 0;
}



posted @ 2008-08-01 13:41 Bill Hsu 阅读(286) | 评论 (0)编辑 收藏
开始写脚本引擎了

题记:
Python是荷兰人写的,Ruby是日本人写的,Lua是巴西人写的,我这个中国人只能在这里脸红。
——CSDN主编 孟岩
不打算自讨没趣地写个要超过Python,Ruby,Lua的脚本引擎,以锻炼能力为主。
估计完成以后和Lua有点像,宗旨是:以比Lua更短为荣,以比Python更长为耻 :-)
┏━┓   ┏━━┓   ┏┓     
┃┃┣━┳━┫━━╋━┳┳╋╋━┳━━┓
┃ ┫━┃┃┣━━┃┣┫┏┫┃┃┣┓┏┛
┗┻┻┻┫┏┻━━┻━┻┛┗┫┏┛┗┛ 
             ┗┛        ┗┛    
引擎就叫RapScript好了(Ruby,Lua,Python 加一起)

posted @ 2008-07-28 12:36 Bill Hsu 阅读(801) | 评论 (5)编辑 收藏
石子合并

附上题目:
在一个圆形操场的四周摆放着n堆石子。现要将石子有次序地合并成一堆。规定每次只能选相邻的2堆石子合并成新的一堆,并将新的一堆石子数记为该次合并的得分。试设计一个算法,计算出将n堆石子合并成一堆的最小得分和最大得分。

/*
   Name: Stone Problem
   Copyleft: www.graptor.com
   Author: Bill Hsu
   Date: 27-04-08 15:15
*/

#include 
<iostream>
#include 
<string>
#include 
<fstream>

#define MAX 100
#define MAXint 1000
using namespace std;

int i,j;//循环用的
ifstream in("in.txt");
ofstream 
out ("out.txt");
int f[MAX][MAX];//f[i][j]表示从i起取j堆的最大值
int sum[MAX][MAX];//sum[i][j]表示从i起取j堆的和
int num[MAX];

int main()
{
int n;
in >>n;
for(i=1;i<=n;i++)
{
in >>num[i];
sum[i][
1]=num[i];
f[i][
1]=0;
}
//end for

for (j=2;j<=n;++j)
{
cout 
<<endl<<j<<endl<<endl;
for(i=1;i<=n;++i)
{
cout 
<<(sum[i][j]=num[i]+sum[i%n+1][j-1])<<endl;

}
//end for i
}//end for j
int k,x,t;

for (j=2;j<=n;j++)
{
for(i=1;i<=n;i++)
{
f[i][j]
=MAXint;
t
=sum[i][j];
for(k=1;k<=j-1;k++)
{
x
=(i+k-1)%n+1;
if(f[i][k]+f[x][j-k]+t<f[i][j])
f[i][j]
=f[i][k]+f[x][j-k]+t;
}
//end for k
cout <<f[i][j]<<endl;
}
//end for i

}
//end for j

int tmp=f[1][n];
for(j=1;j<=n;++j)
{
if (f[j][n]<tmp)
tmp
=f[j][n];
}
//end for

cout 
<<tmp<<endl;

system(
"pause");
return 0;
}
//end main

posted @ 2008-07-24 21:37 Bill Hsu 阅读(643) | 评论 (0)编辑 收藏
我的VC++ RPG游戏紫日2037源代码


刚学游戏编程时写的程序,对初学者可能有用,希望大家喜欢 :-)

执行文件下载:
http://www.cppblog.com/Files/billhsu/2037.rar

源代码下载:
http://www.cppblog.com/Files/billhsu/Source_2037.rar

posted @ 2008-07-23 19:04 Bill Hsu 阅读(3328) | 评论 (7)编辑 收藏
很好的递推题:铺磁砖和走格子

这是Matrix67.com的递推专项训练的题目,感觉很好。

*题一:用1 x 1和2 x 2的磁砖不重叠地铺满N x 3的地板,共有多少种方案?
样例输入:2
样例输出:3


先设一个f[i]表示i*3的地板铺的方法,f[1]=1;f[2]=3;
i*3的地板数是这样得到的:(i-1)*3的地板比i*3的地板少的地方全铺上1*1的瓷砖,这有一种铺法;
或者在(i-2)*3的地板比i*3的地板少的地方铺上2*2的瓷砖和2个1*1的瓷砖,这有两种铺法;
所以得到递推式:f[i]=f[i-1]+2*f[i-2];

*题二:从原点出发,一步只能向右走、向上走或向左走。恰好走N步且不经过已走的点共有多少种走法?
样例输入:2
样例输出:7


这个我没想出来,看题解才弄明白。。
先设一个f[i]表示恰好走i步且不经过已走的点 共有的走法。
如果向上走,不会出现经过已走的点;如果向左或右,上一步不能是向右或左。

引用题解上的一句话:/*
这一步的选择数= (3*上一步的所有选择中向上走的选择数) + (2*上一步的所有选择中向左、右走的选择数)。上一步的所有选择中向上走的选择数”实际上就是“上上步的所有选择数”即d[i-2]
*/引用结束

还有一点,就是“上一步的所有选择中向左、右走的选择数” 等于 “上步所有的选择数(即f[i-1])-上步向上的选择数”
也就等于 “上步所有的选择数(即f[i-1])-上上步所有的选择数(即f[i-2])”
所以得到递推式:f[i] = (3*f[i-2]) + 2*(f[i-1]-f[i-2]);

题解上共有五题,都很好,大家可以去这里看看:
http://www.fengzee.com/blog/article.asp?id=60

posted @ 2008-07-23 15:37 Bill Hsu 阅读(922) | 评论 (0)编辑 收藏
仅列出标题
共9页: 1 2 3 4 5 6 7 8 9