Lanffulce's profileLanffulce GPhotosBlogListsMore Tools Help

Lanffulce G

.nothing
January 19

一个关于主动对象的讨论

一个关于主动对象的讨论
今天突然想起来一个“主动对象”的问题。面向对象的程序设计正是现今主流趋势之一。但是,对象的主动问题如何解决或者说能不能解决呢?
我们根据战争的实际情况进行下列假设:
假设一:现有class Soldier,其数据成员有且只有“平面坐标”(float fPointX 和 float fPointY),成员函数有“移动”(void move(float fX, float fY));
假设二:所有的Soldier实例在平面坐标轴上沿直线移动,速度为定值,并且每个Soldier的视野均相等也为定值;
假设三:(也就是主动的问题)当Soldier周围有其他的Soldier进入他的视野的时候,就会发生战斗,然后随机将一个Soldier消除,也就是战死;

现在进行简化设定:
平面上有两个点,每个点是一个Soldier的实例(sa和sb),sa坐标为(0,0),sb坐标为(200,0),即两Soldier相距200单位(简化了y轴),每个Soldier的视野为150,当sb从相距151处移入sa视野时应如何处理?

如果添加成员函数scan,不断地扫描所有的其它对象,那当对象多了的时候资源的使用就成了问题,这还姑且不论是否为友军和障碍物的问题。

January 18

暂停Cpp的学习

构造和析构看完了~~~后边的好难,友元……疯了疯了!!

先来会儿java吧,我突然想起来了.net VS2003 J#开发会不会适合写JAVA呢?改天装一个吧

重新捡起上课的时候学的java继续学,继续“异常”那部分吧。

January 15

一个关于C++链表的最初型

#include <iostream.h>
#include <stdio.h>

int i_Input =0; //阵的行列
int i_CurrentRow =0; //所在行,后边有设定
int i_CurrentColumn =0; //所在列,后边有设定

struct Cell
{
 int i_Row; //排序用
 int i_Column; //排序用
 long l_Number; //实际填入的数值
 Cell *next;
};


void RC_move(long l_Currenti)
{
 if((l_Currenti - 1) % i_Input ==0)
 {
  (i_CurrentRow ==i_Input - 1)? i_CurrentRow =0 : i_CurrentRow++;
 }
 else
 {
  (i_CurrentRow ==0)? i_CurrentRow =i_Input - 1 : i_CurrentRow--;
  (i_CurrentColumn ==i_Input - 1)? i_CurrentColumn =0 : i_CurrentColumn++;
 }
};

void main()
{
 //cout <<"解决一个数学问题:在方阵内填数,是横行、数列的和相等" <<endl;
 //cout <<"请输入您准备建立的方阵行或列的元素个数(奇数):";
 cout <<"Please input the number of row or column:";
 cin >>i_Input;
 

 Cell *head; //链首指针
 Cell *p_CurrentCell;
 Cell *p_End;
 p_CurrentCell =new Cell;
 p_CurrentCell ->i_Column =-1;
 p_CurrentCell ->i_Row =-1;
 p_CurrentCell ->l_Number =0;
 head =NULL;
 p_End =p_CurrentCell;

 //此处可设定开始时的1的所在位置
 i_CurrentRow =0; //所在行
 i_CurrentColumn =0; //所在列

 for(long i=1; i<=i_Input * i_Input+1; i++)
 {
  if(head == NULL)
  {
   head =p_CurrentCell;
  }
  else
  {
   p_End  ->next =p_CurrentCell;
  }
  p_End =p_CurrentCell;
  p_CurrentCell =new Cell;
  RC_move(i);
  p_CurrentCell ->i_Row =i_CurrentRow;
  p_CurrentCell ->i_Column =i_CurrentColumn;
  p_CurrentCell ->l_Number =i;
 }
 p_End ->next =NULL;
 delete p_CurrentCell;

 Cell *head_result;
 for(int j =0; j < i_Input; j++)
 {
  for(int k =0; k <i_Input; k++)
  {
   head_result =new Cell;
   head_result =head;
   while(head_result ->l_Number < i_Input * i_Input)
   {
    head_result =head_result ->next;
    if(head_result ->i_Row == j && head_result ->i_Column == k)
    {
     cout <<head_result ->l_Number <<'\t';
    }
   }
  }
  cout <<endl;
 }
 getchar();
}

 

 

解决一个数学问题:在方阵内填数,是横行、数列的和相等,请输入您准备建立的方阵行或列的元素个数,请输入奇数(偶数无解)。

 

发觉在后边的输出段时再时间复杂度太高了,有待改善。

January 14

竟然int是……

int在win32下sizeof(int) = 4 一定要记住的。

数组竟然是……

数组的概念你知道吗?数组是一个有若干同类变量组成的集合。

相关的概念还有:下标是数组元素到数组开始的偏移量。

最关键的:数组名本身是一指针,它的类型是指向数组元素的指针。

int a[100];
int *iPtr =a;
关于第 i 个元素,我们有:
a[i]  *(a+i)  iPtr[i]  *(iPtr+i) 是指的同一个东西
&a[i]  a+i  iPtr+i &iPtr[i]  也是指同一个东西

综上所述,我发现我之前对数组的概念完全错了,完全。实在是太可怕了。
数组名就是一个指针,“把指针指向一个数组”,其实这完全是逻辑上的说法,物理上就是说把一个表示数组的指针赋值给另外一个指针。还有,类似于“取出数组的第 i 个元素”中使用的 a[i] 其实就是将一个指针按照不同的数据类型偏移n个字节罢了。

我正在努力看懂字符串的问题,没有String类型还真是别扭。

 
There are no photo albums.
感谢访问!
Please wait...
Sorry, the comment you entered is too long. Please shorten it.
You didn't enter anything. Please try again.
Sorry, we can't add your comment right now. Please try again later.
To add a comment, you need permission from your parent. Ask for permission
Your parent has turned off comments.
Sorry, we can't delete your comment right now. Please try again later.
You've exceeded the maximum number of comments that can be left in one day. Please try again in 24 hours.
Your account has had the ability to leave comments disabled because our systems indicate that you may be spamming other users. If you believe that your account has been disabled in error please contact Windows Live support.
Complete the security check below to finish leaving your comment.
The characters you type in the security check must match the characters in the picture or audio.

Lanffulce G

Occupation