作业保存1

#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<time.h>
#include<windows.h>
using namespace std;
const int initial_lize=10000;
const int adding_size=2*initial_lize;
template<class T>
struct Queue{
T * base;
T * Qhead,*Qbegin,*Qend,*Qfront,*Qtail;
int front_pos,tail_pos;
int now_size,whole_size;
Queue(){
base=(T *)malloc(sizeof(T)*initial_lize);
Qhead=base;
Qbegin=base;Qend=base+(initial_lize-1);
Qfront=Qtail=base+1;
front_pos=tail_pos=1;
now_size=1;
whole_size=initial_lize;
}
bool Empty(){
if(Qfront==Qtail) return true;
else return false;
}
void push(const T x){
now_size++;
if(now_size<whole_size){
*Qtail=x;
Qtail++;
tail_pos++;
}
else{
base=(T *)realloc(base,(sizeof(T))*whole_size*2);//别忘了类型转换
whole_size*=2;
Qhead=base;Qend=base+(whole_size-1);
Qfront=base+front_pos;Qtail=base+tail_pos;
*Qtail=x;Qtail++;tail_pos++;
}
}
T Top(){
if(!Empty()) return (*Qfront);
else{
cerr<<"Queue is empty! can not return any elements"<<endl;
}
}
void pop(){
if(!Empty()){
Qfront++;
front_pos++;
}
else{
cerr<<"Queue is empty! can not pop any elements"<<endl;
}
}
void delete_Queue(){
free(base);
}
};
template<class T>
struct Stack{
T * base;
T * head,* tail;int tail_pos;
int now_size,whole_size;
Stack(){
base=(T*)malloc(sizeof(T)*initial_lize);
head=tail=base+1;tail_pos=1;
now_size=0;whole_size=initial_lize;
}
bool Empty(){
if(tail==head) return true;
else return false;
}
void push(const T x){
now_size++;
if(now_size<whole_size){
tail++;tail_pos++;
*tail=x;
}
else{
base=(T*)realloc(base,sizeof(T)*(whole_size*2));
whole_size*=2;
head=base+1;tail=base+tail_pos;
tail++;tail_pos++;*tail=x;
}
}
void pop(){
if(!Empty()) {tail--;}
else {cerr<<"the Stack is empty!can not pop any elements"<<endl;}
}
T Top(){
if(!Empty()) {return *tail;}
else {cerr<<"the Stack is empty!can not pop any elements"<<endl;}
}
void delete_Stack(){
free(base);
}
};
const int m_size=100;
int matrix[m_size][m_size],sx,sy,dx,dy,N;
bool vis[m_size][m_size];
struct node{
int x,y,step;
};
const int dir[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
bool check(int x,int y){
if(x<0||x>=N||y<0||y>=N) return false;
else return true;
}
void print(){
Sleep(1000);
system("CLS");
for(int i=0;i<N;i++){
for(int j=0;j<N;j++){
if(i==sx&&j==sy) printf(" S");
else if(vis[i][j]) printf(" N");
else printf(" %d",matrix[i][j]);
}
printf("\n");
}
}
int ans;
int bfs(int sx,int sy,int dx,int dy,int draw){
Queue<node> que;ans=0;
memset(vis,false,sizeof(vis));
que.push((node){sx,sy,0});
vis[sx][sy]=true;bool _find=false;
while(!que.Empty()){
node k=que.Top();
que.pop();
for(int i=0;i<4;i++){
int x=k.x+dir[i][0];
int y=k.y+dir[i][1];
int step=k.step+1;
if(check(x,y)&&!vis[x][y]&&matrix[x][y]!=0) {vis[x][y]=true;
if(x==dx&&y==dy){if(draw) print();_find=true;printf("find");ans=max(ans,step);break;}
que.push((node){x,y,step});
if(draw) print();ans=max(ans,step);
}
}
}
que.delete_Queue();
return _find;
}
bool havefind(int x,int y){
if(x==dx&&y==dy) return true;
else return false;
}
bool dvis[m_size][m_size][4];
int dfs(int sx,int sy,int dx,int dy,int draw){
memset(dvis,false,sizeof(dvis));
Stack<node> s;memset(vis,false,sizeof(vis));
s.push((node){sx,sy,0});vis[sx][sy]=true;
bool _find=false;
while(!s.Empty()){
node p=s.Top();
node k=p;
Sleep(1000);
if(k.x==dx&&k.y==dy) s.pop();
p=s.Top();
k=p;
printf("k:%d %d\n",k.x,k.y);
while(!havefind(k.x,k.y)&&check(k.x,k.y)){
Sleep(1000);
printf("k:%d %d\n",k.x,k.y);
bool havedir=false;
for(int i=0;i<4;i++){
int tx,ty;
if(!dvis[k.x][k.y][i]){
havedir=true;
tx=k.x+dir[i][0];
ty=k.y+dir[i][1];
dvis[k.x][k.y][i]=true;
if(check(tx,ty)&&!vis[tx][ty]&&matrix[tx][ty]!=0) {
vis[tx][ty]=true;
s.push((node){tx,ty,k.step+1});
print();
k=(node){tx,ty,k.step+1};break;
}
}
}
if(!havedir) break;
}
node f=s.Top();bool havedir=false;
for(int i=0;i<4;i++){
if(!dvis[f.x][f.y][i]) {havedir=true;break;}
}
if(!havedir) {
s.pop();
vis[f.x][f.y]=false;
}
}
}
bool general_matrix(int sx,int sy,int dx,int dy,int N){
for(int i=0;i<N;i++){
for(int j=0;j<N;++j){
matrix[i][j]=rand()%2;
}
}
while(!bfs(sx,sy,dx,dy,0)){
for(int i=0;i<N;i++){
for(int j=0;j<N;++j){
matrix[i][j]=rand()%2;
}
}
}
printf("成功生成迷宫\n");
}
int main(){
//队列的测试
// Queue<int> que;
// int temp=0;
// que.Top();
// que.pop();
// for(int i=0;i<10;i++){
// que.push(i);
// }
// for(int i=0;i<10;i++){
// temp=que.Top();
// que.pop();
// cout<<temp<<endl;
// }
// que.delet_Queue();
printf("输入迷宫的阶数和起点终点:");
cin>>N>>sx>>sy>>dx>>dy;
printf("输入完毕\n");
srand(time(NULL));
general_matrix(sx,sy,dx,dy,N);
dfs(sx,sy,dx,dy,1);
// bfs(sx,sy,dx,dy,1);printf(" minimum step is %d ",ans);

return 0;
}

时间: 2024-08-05 19:34:28

作业保存1的相关文章

作业保存

#include<iostream> #include<cstdlib> #include<cstdio> #include<time.h> #include<windows.h> using namespace std; const int initial_lize=10000; const int adding_size=2*initial_lize; template<class T> struct Queue{ T * bas

增加Activity Monitor中的作业保存数量

在Master Server的注册表中加入如下两个键值即可: (1500的单位是小时) ?

[转]hadoop运行mapreduce作业无法连接0.0.0.0/0.0.0.0:10020

14/04/04 17:15:12 INFO mapreduce.Job:  map 0% reduce 0% 14/04/04 17:19:42 INFO mapreduce.Job:  map 41% reduce 0% 14/04/04 17:19:53 INFO mapreduce.Job:  map 64% reduce 0% 14/04/04 17:19:55 INFO mapreduce.Job:  map 52% reduce 0% 14/04/04 17:19:57 INFO 

第五到七次作业总结

三次作业多线程设计 第五次作业多线程电梯的设计为:输入.总调度器.三部电梯,共5个线程.输入和总调度器从共享对象--请求队列--中获取请求,由总调度器向三部电梯系统派发请求,一个电梯系统本身就是继承的第三次作业的具有捎带功能的(拥有一部电梯的)调度器,可以自行处理派发到电梯系统的一系列请求. 第六次作业IFTTT的线程设计为:每个监控作业一个线程,相互之间没有交互. 第七次作业设计为:主线程.100辆出租车.每个请求一个线程.主线程调用输入处理方法每增加一个请求就开启一个请求处理线程,所有请求处

SQL Server 2014 日志传送部署(6):监视日志传送

13.3 监视日志传送 部署日志传送后,就需要监视有关日志传送服务器状态的信息.日志传送操作的历史记录和状态始终由日志传送作业保存在本地.备份操作的历史记录和状态存储在主服务器上,复制和还原操作的历史记录和状态存储在辅助服务器上.如果使用了远程监视服务器,此信息还将存储在监视服务器上. 如果配置了监视服务器,该监视服务器上将运行两个警报作业,一个用来监视主数据库实例,一个用来监视辅助服务器: 如果未指定监视服务器,警报作业将在主服务器实例上运行,以便监视备份操作.警报作业还将在每个辅助服务器实例

Python下APScheduler的简单使用

今天准备实现一个功能需要用到定时执行任务,所以就看到了Python的一个定时任务框架APScheduler,试了一下感觉还不错. 1.APScheduler简介: APScheduler是Python的一个定时任务框架,可以很方便的满足用户定时执行或者周期执行任务的需求,它提供了基于日期date.固定时间间隔interval .以及类似于Linux上的定时任务crontab类型的定时任务.并且该框架不仅可以添加.删除定时任务,还可以将任务存储到数据库中,实现任务的持久化,所以使用起来非常方便.

流式计算-Jstorm提交Topology过程(下)

紧接上篇流式计算-Jstorm提交Topology过程(上), 5.上篇任务已经ServiceHandler.submitTopologyWithOpts()方法,在该方法中,会实例化一个TopologyAssignEvent,相当于创建了一个topology级别的作业,然后将其保存到TopologyAssign的任务队列中,具体代码如下: TopologyAssignEvent assignEvent = new TopologyAssignEvent(); assignEvent.setTo

Python之路【第十二篇续】jQuery案例详解

jQuery 1.jQuery和JS和HTML的关系 首先了HTML是实际展示在用户面前的用户可以直接体验到的,JS是操作HTML的他能改变HTML实际展示给用户的效果! 首先了解JS是一门语言,他是运行在浏览器上的. jQuery是什么呢?他是对JS进行了封装,成了一个类库,就类似于python中的类,我们用的时候直接掉类库了就行了非常方便.比如paramiko模块,我们要使用paramiko就得学习里面的方法. 2.jQuery分为的几部分 ------找 ----选择器 ----筛选器 -

Python任务调度模块 – APScheduler

APScheduler是一个Python定时任务框架,使用起来十分方便.提供了基于日期.固定时间间隔以及crontab类型的任务,并且可以持久化任务.并以daemon方式运行应用.目前最新版本为3.0.x. 在APScheduler中有四个组件: 触发器(trigger)包含调度逻辑,每一个作业有它自己的触发器,用于决定接下来哪一个作业会运行.除了他们自己初始配置意外,触发器完全是无状态的. 作业存储(job store)存储被调度的作业,默认的作业存储是简单地把作业保存在内存中,其他的作业存储