介绍
基于 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/(