【easyx 入门】基于 easyx 和 C++ 的寻路算法演示图(内含 BFS,双向 BFS,无随机 DFS,有随机 DFS,A* 算法(两种),Version. 2(解决闪烁问题)

介绍

基于 easyx 和 C++ 的寻路算法演示图。Version. 2(解决闪烁问题)

修复的地方

本作者发现了不少可以优化的地方,比如说在进行绘制的时候,只需要对一个地方进行改变,而不是全部,就解决了闪烁的问题

代码

/*
###################################################################################################################################
#                                                                                                                                 #
#            #########               #        #     ##                   ###          ######       ####                 #    #    #
#                #                  # #       #   ##                    #   #        #      #      #   ##               #    #    #
#                #                 #   #      # ##                     #     #       #             #     ##             #    #    #
#                #                #     #     ##                      #               ######       ##   ##              #    #    #
#                #               #########    # ##                    #       #             #      # ###    ########    #    #    #
#                #              #         #   #   ##                   #     #              #      #                    #    #    #
#                #             #           #  #     ##                  #   #        #     #       #               #    #         #
#            #########        #             # #       ##                 ###          #####        #                ####     #    #
#                                                                                                                                 #
###################################################################################################################################
*/
#include<stdio.h>
#include<easyx.h>
#include<conio.h>
#include<stdio.h>
#include<graphics.h>
#include<windows.h>
#include<math.h>
#include<stdlib.h>
#include<time.h>
#include<bits/stdc++.h>
using namespace std;
#define ll long long
namespace IO{
   
    #define ll long long
    long long fast_pow(long long a,long long b,long long mod){
   
        ll sum=1;
        while(b){
   
            if(b&1) sum=(sum*a)%mod;
            a=(a*a)%mod;
            b>>=1;
        }
        return sum%mod;
    }
    ll fast_times(ll a,ll b,ll p){
   
    	ll ret=0;
    	while(b){
   
    	    if(b&1) ret=(ret+a)%p;
    	    b>>=1;
    	    a=(a+a)%p;
    	}
    	return ret;
    }
    ll very_fast_times(ll a,ll b,ll m){
   
        unsigned long long c=(unsigned long long)a*b-(unsigned long long)((long double)a/m*b+0.5L)*m;
        if(c<m) return c;
        return c+m;
    }
    ll inv(ll a,ll p){
   
    	return fast_pow(a,p-2,p);
	}
    #undef ll
}
using namespace IO;
class BigNum{
   
   #define MAXN 9999
   #define SIZE 10000
   #define DLEN 4
private:
   int a[5000],len;
   bool neg;
public:
   BigNum(){
   len=1;neg=0;memset(a,0,sizeof(a));}
   BigNum(const int b){
   
   	int c,d=b;
   	if(d<0)	neg=1,d=-d;
   	else	neg=0;
   	len=0;
   	memset(a,0,sizeof(a));
   	while(d>MAXN){
   
   		c=d-(d/(MAXN+1))*(MAXN+1);
   		d=d/(MAXN+1);
   		a[len++]=c;
   	}
   	a[len++]=d;
   }
   BigNum(const long long b){
   
   	long long c,d=b;
   	if(d<0)	neg=1,d=-d;
   	else	neg=0;
   	len=0;
   	memset(a,0,sizeof(a));
   	while(d>MAXN){
   
   		c=d-(d/(MAXN+1))*(MAXN+1);
   		d=d/(MAXN+1);
   		a[len++]=c;
   	}
   	a[len++]=d;
   }
   BigNum(char* s){
   
   	memset(a,0,sizeof(a));
   	int l=strlen(s);
   	if(s[0]=='-'){
   
   		neg=1;
   		for(int i=0;i<l;i++)	s[i]=s[i+1];
   		l--;
   	}
   	else	neg=0;
   	len=l/DLEN;
   	if(l%DLEN)	len++;
   	int idx=0;
   	for(int i=l-1;i>=0;i-=DLEN){
   
   		int t=0,k=i-DLEN+1;
   		if(k<0)	k=0;
   		for(int j=k;j<=i;j++)	t=t*10+s[j]-'0';
   		a[idx++]=t;
   	}
   }
   BigNum(string s){
   
   	memset(a,0,sizeof(a));
   	if(s[0]=='-'){
   
   		neg=1;
   		s=s.substr(1);
   	}
   	else neg=0;
   	int l=s.size();
   	len=l/DLEN;
   	if(l%DLEN)	len++;
   	int idx=0;
   	for(int i=l-1;i>=0;i-=DLEN){
   
   		int t=0,k=i-DLEN+1;
   		if(k<0)	k=0;
   		for(int j=k;j<=i;j++)	t=t*10+s[j]-'0';
   		a[idx++]=t;
   	}
   }
   BigNum(const char c){
   
   	memset(a,0,sizeof(a));
   	neg=0;
   	len=1;
   	a[0]=c-'0';
   }
   BigNum(const BigNum &T):len(T.len){
   
   	neg=T.neg;
   	memset(a,0,sizeof(a));
   	for(int i=0;i<len;i++)	a[i]=T.a[i];
   }
   
   friend istream& operator>>(istream& in,BigNum &b){
   
   	string ch;
   	in>>ch;
   	b=BigNum(ch);
   	return in;
   }
   friend ostream& operator<<(ostream& out,BigNum b){
   
   	if(b.neg)	out<<"-";
   	out<<b.a[b.len-1];
   	for(int i=b.len-2;i>=0;i--){
   
   		out.width(DLEN);
   		out.fill('0');
   		out<<b.a[i];
   	}
   	return out;
   }
   
   BigNum& operator=(const BigNum& T){
   
   	len=T.len;
   	neg=T.neg;
   	memset(a,0,sizeof(a));
   	for(int i=0;i<len;i++)	a[i]=T.a[i];
   	return *this; 
   }
   template<typename T1>
   BigNum& operator=(const T1& T){
   
   	BigNum tmp=BigNum(T);
   	len=tmp.len;
   	neg=tmp.neg;
   	memset(a,0,sizeof(a));
   	for(int i=0;i<len;i++)	a[i]=tmp.a[i];
   	return *this;
   }
   
   bool operator>(const BigNum& T)const{
   
   	if(len>T.len)	return true;
   	if(len==T.len){
   
   		int l=len-1;
   		while(a[l]==T.a[l]&&l>=0)	l--;
   		if(l>=0&&a[l]>T.a[l])	return true;
   		return false;
   	}
   	return false;
   }
   template<typename T1>
   bool operator>(const T1& T)const{
   
   	BigNum t2(T);
   	return *this>t2;
   }
   
   bool operator<(const BigNum& T)const{
   
   	if(len<T.len)	return true;
   	if(len==T.len){
   
   		int l=len-1;
   		while(a[l]==T.a[l]&&l>=0)	l--;
   		if(l>=0&&a[l]<T.a[l])	return true;
   		return false;
   	}
   	return false;
   }
   template<typename T1>
   bool operator<(const T1& T)const{
   
   	BigNum t2(T);
   	return *this<t2;
   }
   
   bool operator>=(const BigNum T)const{
   
   	if(len>T.len)	return true;
   	if(len==T.len){
   
   		int l=len-1;
   		while(a[l]==T.a[l]&&l>=0)	l--;
   		if(l<0)	return true;
   		if(a[l]>=T.a[l])	return true;
   		return false;
   	}
   	return false;
   }
   template<typename T1>
   bool operator>=(const T1 T)const{
   
   	BigNum t2(T);
   	return *this>=t2;
   }
   
   bool operator<=(const BigNum T)const{
   
   	if(len<T.len)	return true;
   	if(len==T.len){
   
   		int l=len-1;
   		while(a[l]==T.a[l]&&l>=0)	l--;
   		if(l<0)	return true;
   		if(a[l]<=T.a[l])	return true;
   		return false;
   	}
   	return false;
   }
   template<typename T1>
   bool operator<=(const T1 T)const{
   
   	BigNum t2(T);
   	return *this<=t2;
   }
   
   bool operator==(const BigNum T)const{
   
   	if(len!=T.len)	return false;
   	for(int i=0;i<len;i++){
   
   		if(a[i]!=T.a[i])	return false;
   	}
   	return true;
   }
   template<typename T1>
   bool operator==(const T1 T)const{
   
   	BigNum t(T);
   	return t==(*this);
   }
   
   BigNum operator+(const BigNum T){
   
   	BigNum t(*this);
   	int big=T.len>len?T.len:len;
   	for(int i=0;i<big;i++){
   
   		t.a[i]+=T.a[i];
   		if(t.a[i]>MAXN){
   
   			t.a[i+1]++;
   			t.a[i]-=MAXN+1;
   		}
   	}
   	if(t.a[big]!=0)	t.len=big+1;
   	else	t.len=big;
   	return t;
   }
   template<typename T1>
   BigNum operator+(const T1 T){
   
   	BigNum t1(*this),t2(T);
   	return t1+t2;
   }
   
   BigNum operator-(const BigNum T){
   
   	BigNum t1,t2;
   	bool flag;
   	if(*this>T){
   
   		t1=*this,t2=T;
   		flag=0;
   	}
   	else{
   
   		t1=T,t2=*this;
   		flag=1;
   	}
   	int big=t1.len;
   	for(int i=0;i<big;i++){
   
   		if(t1.a[i]<t2.a[i]){
   
   			int j=i+1;
   			while(t1.a[j]==0)	j++;
   			t1.a[j]--;
   			j--;
   			while(j>i)	t1.a[j--]+=MAXN;
   			t1.a[i]+=MAXN+1-t2.a[i]; 
   		}
   		else	t1.a[i]-=t2.a[i];
   	}
   	t1.len=big;
   	while(t1.a[t1.len-1]==0&&t1.len>1){
   
   		t1.len--;
   		big--;
   	}
   	if(flag)	t1.neg^=1;
   	return t1;
   }
   template<typename T1>
   BigNum operator-(const T1 T){
   
   	BigNum t1(*this),t2(T);
   	return t1-t2;
   }
   
   BigNum operator*(const BigNum &T)const{
   
   	BigNum ret;
   	int i,j;
   	for(i=0;i<len;i++){
   
   		int up=0;
   		for(j=0;j<T.len;j++){
   
   			int tmp=a[i]*T.a[j]+ret.a[i+j]+up;
   			if(tmp>MAXN){
   
   				int tmp1=tmp-tmp/(MAXN+1)*(MAXN+1);
   				up=tmp/(MAXN+1);
   				ret.a[i+j]=tmp1;
   			}
   			else{
   
   				up=0;
   				ret.a[i+j]=tmp;
   			}
   		}
   		if(up!=0)	ret.a[i+j]+=up;
   	}
   	ret.len=i+j;
   	while(ret.a[ret.len-1]==0&&ret.len>1)	ret.len--;
   	return ret;
   }
   template<typename T1>
   BigNum operator*(const T1 T)const{
   
   	BigNum t1(*this),t2(T);
   	BigNum ans=t1*t2;
   	return ans;
   }
   
   BigNum operator/(
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Programming_Konjac

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值