happmaoo 发表于 2013-2-7 12:47:01

AIX 程序设计大赛---AIX正方形问题

<iframe align="top" marginwidth="0" marginheight="0" src="http://www.zealware.com/csdnblog01.html" frameborder="0" width="728" scrolling="no" height="90"></iframe><div class="postText">AIX 程序设计大赛---AIX正方形问题

作者:成晓旭
作为“算法及实现”栏目的“抛砖引玉”之作,将自己2年多前实现的一个算法放出来。有一年IBM出了这个Java程序设计竞赛题,当时,自己花晚上时间用Java实现了。

[问题描述]:

任意给定一个正方形,将正方形的各边做n等分,并将相应各点连接成水平或垂直的直线,如果从正方形的左下角(0,0)出发,沿各边线或连接线,自左向右或自下而上的方向,到达正方形的右上角(n,n),请用JAVA程序计算并输出所有可能的路径总数和具体线路.请提供相关JAVA源程序和n=2,3,4时的输出结果。输出结果按以下方式:

以n=1为例:

n = 1

Path1: (0,0) - (0,1) - (1,1)

Path2: (0,0) - (1,0) - (1,1)

Total = 2



[设计简介]:

共设计3个类:

AixPoint:正方形问题的低层处理类,抽象正方形问题的每个访问点信息;

AixSquare:正方形问题的核心处理类,抽象正方形算法处理过程;

AixContest:正方形问题的客户调用处理类,抽象正方形问题的应用层。

[算法源码]:

AixPoint源码:



<div style="padding-right: 5.4pt; padding-left: 5.4pt; background: #e6e6e6; padding-bottom: 4px; width: 95%; padding-top: 4px;">http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif/***//*******************************************************************************
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif*>
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif*AIXContestver1.0
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif*开发作者:成晓旭
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif*项目简述:AIX程序设计的Java程序设计"AIX正方形问题"解决方案
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif*启动时间:2004年01月14日20:00:08
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif*完成时间:2003年01月14日20:09:00
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif*
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif*开发环境:Windows2000Professional+SUNJ2SE1.4.2
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif*开发工具:RationalRose2002Enterprise+JCreator2.5Pro
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif*
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif*文件名称:AixPoint.java
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif*简介:正方形问题的低层处理类,抽象正方形问题的每个访问点信息
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif*
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif*备注:
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif*
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif*修改时间1:
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif*
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif******************************************************************************/
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gifpackageCXXSoft.Aix;
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gifimportjava.awt.Point;
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gifpublicclassAixPointextendsPoint
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif...{
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gifprivateintmoveUnit;
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gifpublicbooleanaheadExcess;
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gifpublicbooleanaboveExcess;
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif//类构造器
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gifpublicAixPoint()
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif...{
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gifaheadExcess=false;
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gifaboveExcess=false;
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gifmoveUnit=1;
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif}
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif//类构造器
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gifpublicAixPoint(intx,inty)
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif...{
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gifthis();
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gifthis.x=x;
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gifthis.y=y;
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif}
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif//类构造器
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gifpublicAixPoint(Pointp)
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif...{
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gifthis();
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gifthis.x=p.x;
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gifthis.y=p.y;
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif}
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif//向左移动(前进)
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gifpublicvoidgoAhead()
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif...{
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gifthis.x+=moveUnit;
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif}
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif//向左的反方向移动(后退)
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gifpublicvoidgoAheadReturn()
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif...{
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gifthis.x-=moveUnit;
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif}
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif//向上移动
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gifpublicvoidgoAbove()
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif...{
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gifthis.y+=moveUnit;
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif}
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif//向上的反方向移动(后退)
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gifpublicvoidgoAboveReturn()
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif...{
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gifthis.y-=moveUnit;
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif}
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif//形成输出串
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gifpublicStringtoString()
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif...{
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gifreturn"("+x+","+y+")";
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif}
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif}
页: [1]
查看完整版本: AIX 程序设计大赛---AIX正方形问题