目录
7:20-7:30学习打卡
9:00-12:00看疯狂Java讲义
2:30-5:00看视频
面向对象和面向过程(结构化程序设计)的区别:
- 面向对象的最小程序单位是类,面向过程的最小程序单位是函数;
- 面向对象以对象为中心,面向过程以函数为中心。
面向过程的局限性:
- 设计不够直观,与人类思维习惯不一致;
- 适应性差,可扩展性不强。
面向对象的语言不仅使用类来封装一类事物的内部状态数据,而且类会提供操作这些状态数据的方法 ,还会为这类事物的行为特征提供相应的实现,这种实现也是方法。
基本等式:
成员变量(状态数据)+方法(行为)=类定义
面向对象的三个基本特征:
- 封装(Encapsulation)
- 继承(Inheritance):分为单继承和多继承,Java不支持多继承
- 多态(Polymorphism)
注:基于对象没有继承和多态的特征
对象与类的关系:
类是对象的抽象,对像是类的实例
- 对象:对象是类的一个实例,有状态和行为。例如,一条狗是一个对象,它的状态有:颜色、名字、品种;行为有:摇尾巴、叫、吃等。
- 类:类是一个模板,它描述一类对象的行为和状态。
Java语言使用class关键字定义类,可以使用new关键字来创建指定类的对象了,每个类可以创建任意多个对象,多个对象的成员变量值可以不同——这表现为不同对象的数据存在差异。
类之间的结构关系:
- 一般->特殊关系:典型的继承关系,用关键字extends来表示这种继承关系
- 整体->部分结构关系:被称为组装结构,典型的组合关系
晚上7:00-9:00刷二招题目
You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of unit cubes which may or may not be filled with rock. It takes one minute to move one unit north, south, east, west, up or down. You cannot move diagonally and the maze is surrounded by solid rock on all sides.
Is an escape possible? If yes, how long will it take?Input
The input consists of a number of dungeons. Each dungeon description starts with a line containing three integers L, R and C (all limited to 30 in size).
L is the number of levels making up the dungeon.
R and C are the number of rows and columns making up the plan of each level.
Then there will follow L blocks of R lines each containing C characters. Each character describes one cell of the dungeon. A cell full of rock is indicated by a '#' and empty cells are represented by a '.'. Your starting position is indicated by 'S' and the exit by the letter 'E'. There's a single blank line after each level. Input is terminated by three zeroes for L, R and C.Output
Each maze generates one line of output. If it is possible to reach the exit, print a line of the form
Escaped in x minute(s).
where x is replaced by the shortest time it takes to escape.
If it is not possible to escape, print the lineTrapped!Sample Input
3 4 5 S.... .###. .##.. ###.# ##### ##### ##.## ##... ##### ##### #.### ####E 1 3 3 S## #E# ### 0 0 0
Sample Output
Escaped in 11 minute(s). Trapped!
题解:你被困在一个三维的迷宫里,可移动的方向有六个,需要用到三位数组,bfs,你处在S位置,E位置为出口,#为墙,走不通,”.“可以走,定义一个队列,将起始位置放入队列,并标记,循环,将队列中第一个元素,往第一个位置的六个方向走,如果这个方向可以走并且没有被标记,入队,循环上面的操作直到找到出口。注意传递参数时别传错了,三维数组可以看成多个二维数组。
#include <stdio.h>
#include <string.h>
int book[50][50][50];
char a[50][50][50];
int l,r,c;
typedef struct
{
int x,y,z;
int s;
} locat;
void bfs(int tz,int tx,int ty)
{
locat q[50100];
int rear=0,head=0,flag=0,i;
int next[6][3]= {{0,0,1},{0,1,0},{0,0,-1},{0,-1,0},{1,0,0},{-1,0,0}};
q[rear].x=tx;
q[rear].y=ty;
q[rear].z=tz;
q[rear].s=0;
rear++;
while(head<rear)
{
for(i=0; i<=5; i++)//六个方向循环
{
tx=q[head].x+next[i][1];
ty=q[head].y+next[i][2];
tz=q[head].z+next[i][0];
if(tx<0||tx>=r||ty<0||ty>=c||tz<0||tz>=l)
continue;
if(a[tz][tx][ty]=='.'&&book[tz][tx][ty]==0)
{
q[rear].x=tx;
q[rear].y=ty;
q[rear].z=tz;
q[rear].s=q[head].s+1;
rear++;
book[tz][tx][ty]=1;
}
if(a[tz][tx][ty]=='E')
{
printf("Escaped in %d minute(s).\n",q[head].s+1);
return ;
}
}
head++;
}
printf("Trapped!\n");
}
int main()
{
while(~scanf("%d%d%d",&l,&r,&c))
{
int flag=0;
int i,j,k;
if(l==0&&r==0&&c==0)
{
break;
}
memset(book,0,sizeof(book));
getchar();
for(i=0; i<l; i++)
for(j=0; j<r; j++)
scanf("%s",a[i][j]);
for(i=0; i<l; i++)
{
for(j=0; j<r; j++)
{
for(k=0; k<c; k++)
{
if(a[i][j][k]=='S')
{
flag=1;
book[i][j][k]=1;
break;
}
}
if(flag)
break;
}
if(flag)
break;
}
bfs(i,j,k);
}
return 0;
}