Trang 1 trên tổng số 3 123 Cuối cùngCuối cùng
Từ 1 tới 10 trên tổng số 21 kết quả

Đề tài: Code C: Mô phỏng thuật toán Dijktra

  1. #1
    Ngày gia nhập
    05 2007
    Bài viết
    64

    Mặc định Code C: Mô phỏng thuật toán Dijktra

    Ui da, cuối cùng cũng qua môn Lý thuyết đồ thị. Mừng quá !!!

    Share cho các bạn cái đề tài giữa kì của mình nè.

    "Viết chương trình mô phỏng thuật toán Dijktra"
    (cái này do mình với 1 bạn khác tự viết 100% đó nha, hổng chôm source của ai đâu (^.*))


    --> Nhớ mở thư viện đồ họa nha, chạy bằng BorlandC 3.1 <--
    --> để 2 file cùng 1 thư mục, copy thư mục BGI vào nữa <--

    File "DIJKSTRA.CPP" chứa hàm main()

    Code:
    #include<stdio.h>
    #include<conio.h>
    #include<stdlib.h>
    #include<graphics.h>
    #include<dos.h>
    #include"dijkstra.h"
    
    void main()
    {
    	int mh=0,mode=0; int i1,j1,k1,s1;
    	int co=0;
    	initgraph(&mh,&mode,"BGI");
    	initMouse();
    	background(); co=0;
    	showMouse();
    	c1=0;
    	q=0;q2=0; c2=0; initArrayTS(); n=0;
    	while(1)// //DUNG VONG LAP VO TAN KHI DUNG CHUOT
    	{
    		Locate();
    		On_mose_over1(x1,y1);
    		clickMouse(s,x,y); 
    		if(s)
    		{
    			chonMenu1(x,y); c2=q2;
    			if (c2==1)
    			{
    				Batdau:
    				if (c1==0)
    				{
    					MenuDT();q=0; q2=0;useWin(0);
    					while (q2==0)//c1==0)
    					{
    						Locate();
    						On_mose_over0(x1,y1);
    						clickMouse(s,x,y);
    						if(s)   chonMenu0(x,y);
    					}
    					c1=q2; q2=0; q=0; Status(c1);useWin(1);
    				}
    
    				if (co==1) rewrite();
    				nutVexong();
    				vedothi:
    				xoaStatus(); inStatus(10,5,"Ve do thi");
    				c2=1; c3=0;
    				q=0;
    				while(c2==1)
    				{
    					
    					Locate();
    					mouseOver(x1,y1,5,50,65,70,"Ve Xong",1);
    					clickMouse(s,x,y);
    					VeDT(s,x,y,c2);
    					if(rightClick(x,y)) goto huongdan;
    				}
    				q=0; c2=0;
    				xoaStatus();
    			}
    
    			if (c2==2&&n!=0&&useMouse==1)
    			{
    				xoaStatus(); useWin(0);
    				inStatus(10,5,"Luu vao File");
    				File(1);
    				for(i=0;i<30;i++) F[i]=NULL; i=0;
    				while(c2==2){
    					useMouse=0;	s=0;
    					XuatTenFile(F[i],1);
    				}
    				useWin(1);
    				xoaStatus();
    			}
    
    			if (c2==3&&useMouse==1)
    			{
    				xoaStatus();useWin(0);
    				inStatus(10,5,"Mo File do thi");
    				File(2); 
    				for(i=0;i<30;i++) F[i]=NULL; i=0;
    				while(c2==3){
    					useMouse=0; s=0;
    					XuatTenFile(F[i],2);
    				}
    				xoaStatus();useWin(1);
    			}
    
    			if (c2==4&&n>0&&useMouse==1)
    			{
    				xoaStatus();useWin(0);if (co==1) rewrite();
    				inStatus(10,5,"Xem ma tran trong so");
    				s=0;   MTTS(); 
    				while(c2==4)
    				{
    					Locate();
    					clickMouse(s,x,y);
    					if (s) c2=0;
    				}
    				hideMouse(); xuatHinh(x3,y3); showMouse();Menu();
    				xoaStatus(); useWin(1);
    			}
    
    			if (c2==5&&n>1&&useMouse==1)
    			{
    				xoaStatus();useWin(0);
    				inStatus(10,5,"Xet duong di trong do thi");
    				xetDuongdi();  S=0; s=0; useMouse=0;
    				chonDinhS(-1);T=0; q3=0;
    				chonDinhT(S);
    				if (q3==1){
    					if (co==1) rewrite();
    					dijkstra(); xoaStatus();
    					useWin(1);
    					inKQ();
    					co=1;
    				}
    				useWin(1);
    			}
    			if (c2==6)
    			{
    				huongdan:
    				xoaStatus();useWin(0);
    				inStatus(10,5,"Huong dan");
    				q=0;q2=0;q3=0; HuongDan(5);
    				while(q2==0)
    				{
    					Locate();
    					On_mouse_overHD(x1,y1);
    					clickMouse(s,x,y);
    					if(s) thoatHD(x,y);
    				}
    				q=0,q2=0;
    				xoaStatus();useWin(1);
    				if(c2==1) goto vedothi;
    				c2=0;				
    			}
    
    			if (c2==7)
    			{
    				hideMouse();
    				setfillstyle(0,7); bar(5,50,635,435);
    				co=0;c1=0;
    				q=0;q2=0; c2=0; initArrayTS(); n=0;
    				showMouse();
    				goto Batdau;
    			}
    
    		}
    
    		if(!s) {q2=0;}
    
    	}
    	hideMouse();
    	closegraph();
    }
    Đã được chỉnh sửa lần cuối bởi nguyen190887 : 08-06-2007 lúc 11:01 PM. Lý do: sai quy định
    I know... nothing

  2. #2
    Ngày gia nhập
    05 2007
    Bài viết
    64

    <tiếp theo>

    File "DIJKSTRA.H" chứa các hàm khác.

    Code:
    #include<stdio.h>
    #include<conio.h>
    #include<graphics.h>
    #include<math.h>
    #include<dos.h>
    #include<string.h>
    
    #define MAX 50
    #define R 10
    #define pi 3.1415926
    #define DUOI_NEN 7
    #define DUOI_LEFT 0
    #define DUOI_RIGHT 400
    #define DUOI_TOP 380
    #define DUOI_BOTTOM 479
    #define MAU_NEN BLACK
    #define MAU_SO YELLOW
    #define MAU_VT BLUE
    #define MAU_DT CYAN
    #define MAU_TS YELLOW
    
    
    typedef struct point {
    	int x,y;
    };
    
    int c1,c2,c3,x,s,y,x1,y1,x2,y2,x3,y3,q,q2,q3,hang,ketqua,i;
    char ch[50]; char F[30];
    unsigned img; char *pimg;
    int M[MAX][MAX];
    int n=0; int t1,t2;
    int j;
    int j1,j2,j3;
    point a[MAX];	//	MANG a CHUA TOA DO CUA CAC DIEM DA VE
    FILE *file;
    int truoc[MAX],d[MAX],final[MAX];
    int S,T,n1,minp=2000;
    int L[MAX],so;
    int useMouse=1; 
    
    void in();
    int leftClick(int&,int&);
    void dragMouse(int&,int&,int&);
    void drawCircle(int,int,int,int,int);
    void drawLine(int,int,int,int,int);
    void initArrayTS();
    void getArray(int,int);
    long distance(int,int,int,int);
    int checkPoint(int,int,int);
    void checkMin(int,int,int&);
    void changeColor(int);
    void changeLine(int,int);
    void w2m(int);
    void w2f(char*);
    void xuly();
    void dijkstra();
    void inKQ();
    void ghiTS(int,int,int,int);
    double goc(int,int,int,int);
    void chi_huong(int,int,int,int,int,int);
    void xoaDiem(int,int);
    char* toS(int);
    void rewrite();
    void luuDT(char*);
    void nhapDT(char*);
    
    void chupHinh(int x1,int y1, int x2, int y2)
    {
    	img=imagesize(x1,y1,x2,y2);
    	pimg=(char*)malloc(img);
    	getimage(x1,y1,x2,y2,pimg);
    }
    
    void xuatHinh(int x1, int y1)
    {
    	putimage(x1,y1,pimg,0);
    	free(pimg);
    }
    
    void initMouse()
    {
    	union REGS v;
    	v.x.ax=0x00;// KHOI TAO CHUOT
    	int86(0x33,&v,&v);
    }
    
    void showMouse()
    {
    	union REGS v;
    	v.x.ax=0x01; //HIEN CHUOT
    	int86(0x33,&v,&v);
    }
    
    void hideMouse()
    {
    	union REGS v;
    	v.x.ax=0x02; //AN CHUOT
    	int86(0x33,&v,&v);
    }
    
    void clickMouse(int &s,int &x,int &y)
    {
    	union REGS v;
    	v.x.ax=0x05;   //CLICK CHUOT , CHI LAY GIA TRI O LAN CLICK DAU TIEN
    	int86(0x33,&v,&v);
    	s=v.x.bx; //KHI NHAP CHUOT THI S=...BX=1, KHI THA RA THI S = 0
    	x=v.x.cx; // KHI DANG NHAP CHUOT, X LA TOA DO NGANG
    	y=v.x.dx; // KHI DANG NHAP CHUOT, Y LA TOA DO DOC
    }
    
    void clickMouse2(int &s,int &x,int &y)
    {
    	union REGS v;
    	v.x.ax=0x03;   // CLICK CHUOT VA GIU THI SE LIEN TUC NHAN GIA TRI
    	int86(0x33,&v,&v);
    	s=v.x.bx;
    	x=v.x.cx;
    	y=v.x.dx;
    }
    
    void clickMouse3(int &s,int &x,int &y)
    {
    	union REGS v;
    	v.x.ax=0x06;   // CLICK CHUOT VA GIU THI SE NHAN GIA TRI LUC THA CHUOT RA
    	int86(0x33,&v,&v);
    	s=v.x.bx;
    	x=v.x.cx;
    	y=v.x.dx;
    }
    
    int rightClick(int &x,int &y)
    {
    	union REGS v;
    	v.x.ax=0x05;
    	v.x.bx=1;
    	int86(0x33,&v,&v);
    	x=v.x.cx;
    	y=v.x.dx;
    	return v.x.bx;
    }
    
    void dragMouse(int &s,int &x,int &y)
    {
    	union REGS v;
    	v.x.ax=0x03;
    	int86(0x33,&v,&v);
    	s=v.x.bx;
    	x=v.x.cx;
    	y=v.x.dx;
    }
    
    
    void Locate()
    {
    	union REGS v;
    	v.x.ax=3;
    	int86(0x33,&v,&v);
    	x1=v.x.cx;
    	y1=v.x.dx;
    }
    
    void Button(int x1, int y1, int x2, int y2, char t[50], int loai)
    {
    	hideMouse();
    	int c1, c2;
    	if (loai==0) {c1=15; c2=8;}
    	else {c1=8; c2=15;}
    	setcolor(c1);
    	line(x1,y1,x2,y1); 		//ngang 1
    	line(x1,y1,x1,y2);	        //doc 1
    	setcolor(c2);
    	line(x1+1,y2,x2,y2);		//ngang 2
    	line(x2,y1+1,x2,y2);		//doc 2
    	setcolor(7);setfillstyle(1,0);
    	rectangle(x1+1,y1+1,x2-1,y2-1);
    	setfillstyle(1,7);					//Mau nut
    	bar(x1+2,y1+2,x2-2,y2-2);
    	setcolor(1); //settextstyle(2,0,1);
    	settextjustify(1,1);
    	outtextxy((x1+x2)/2,(y1+y2)/2+1,t);
    	settextjustify(0,2);
    	showMouse();
    }
    
    void Window(int x1, int y1, int x2, int y2, char t[50], int loai)
    {
    	setcolor(15);
    	line(x1,y1,x2,y1); 		//ngang 1
    	line(x1+2,y2-2,x2-2,y2-2);      //ngang 2
    	line(x1,y1,x1,y2);	        //doc 1
    	line(x2-2,y1+22,x2-2,y2-2);      //doc 2
    
    	setcolor(8);
    	line(x1+2,y1+22,x2-2,y1+22);	//ngang 1
    	line(x1+1,y2,x2,y2);		//ngang 2
    	line(x1+2,y1+22,x1+2,y2-2);	//doc 1
    	line(x2,y1+1,x2,y2);		//doc 2
    
    	setcolor(7);setfillstyle(1,0);
    	rectangle(x1+1,y1+1,x2-1,y2-1);
    	line(x1+2,y1+21,x2-1,y1+21);
    	setfillstyle(1,5);					//mau window
    	bar(x1+2,y1+2,x2-2,y1+20);
    	setcolor(15);
    	outtextxy(x1+6,y1+8,t);
    	x3=x2-18;y3=y1+4;
    	Button(x2-18,y1+4,x2-4,y1+18,"X",0);
    
    	if (loai==1) {
    		setfillstyle(1,7);
    		bar(x1+2,y1+23,x2-2,y2-2);
    	}
    
    }
    
    void Menu()
    {
    	Button(3,23,636,43,"",0);
    	hideMouse();
    	setcolor(15); line(3,44,637,44); line(637,23,637,44);
    	setcolor(7);line(2,45,637,45);
    	setcolor(8);line(2,46,637,46);
    	setcolor(1); //outtextxy(5,30,"|");
    	settextjustify(1,1);
    	outtextxy(31,34,"VeDT"); //outtextxy(57,30,"");
    	outtextxy(86,34,"LuuDT");//outtextxy(116,30,"");
    	outtextxy(166,34,"MoFileDT"); //outtextxy(216,30,"");
    	outtextxy(273,34,"XemMTtrongso"); //outtextxy(330,30,"");
    	outtextxy(380,34,"Xetduongdi");   //outtextxy(430,30,"");
    	outtextxy(470,34,"Trogiup");	  //outtextxy(510,30,"");
    	outtextxy(540,34,"DTmoi");	  //outtextxy(570,30,"");
    	outtextxy(600,34,"Thoat");	  //outtextxy(570,30,"");
    	settextjustify(0,2);
    	showMouse();
    }
    
    void reMenu(int x1, int y1, int x2, int y2, char *t){
    	hideMouse();
    	setfillstyle(1,7);
    	bar(x1,y1+1,x2,y2-1);
    	setcolor(1);
    	outtextxy(x1+13,y1+7,t);
    	showMouse();
    }
    
    void Status(int c)
    {
    	Button(3,440,637,477,"",1);
    	hideMouse();
    	setcolor(15); 	line(3,438,636,438);	line(399,440,399,477);	line(401,458,636,458);
    	setcolor(8);	line(2,46,636,46);	line(401,440,401,477);	line(401,460,636,460);
    	setcolor(7);	line(3,439,637,439);	line(400,439,400,477);	line(400,459,637,459);
    	settextjustify(1,1); setcolor(1);
    	if (c==1) outtextxy(520,450,"DO THI CO HUONG");
    	if (c==2) outtextxy(520,450,"DO THI VO HUONG");
    	outtextxy(520,469,"Last Update: 14/05/2007");			//Update
    	settextjustify(0,2);
    	showMouse();
    }
    
    void background()
    {
    	Window(0,0,639,479,"Chuong trinh mo phong thuat toan DIJKSTRA",0);
    	Menu();
    	Status(0);
    }
    
    void useWin(int loai)
    {
    	hideMouse();
    	if(loai==1) {setfillstyle(1,5);					//mau window
    	bar(2,2,637,22);}
    	if(loai==0) {setfillstyle(1,7);					//mau window
    	bar(2,2,637,22);setcolor(8);	rectangle(2,2,637,22);}
    	setcolor(15);
    	outtextxy(6,8,"Chuong trinh mo phong thuat toan DIJKSTRA");
    	showMouse();
    	Button(619,4,633,18,"X",0);
    }
    
    void TextGiua(int xa,int ya,int xb, int yb,char *t)
    {
    	setcolor(1);settextjustify(1,1);
    	outtextxy((xa+xb)/2,(ya+yb)/2+1,t);
    	settextjustify(0,2);
    }
    
    void mouseOver(int x1, int y1, int xa,int ya, int xb, int yb, char*t, int qsau)
    {
    	if (x1>xa&&x1<xb&&y1>ya&&y1<yb&&q==0)
    	{
    		Button(xa,ya,xb,yb,t,0);
    		q=qsau; return;
    	}
    	if ((x1<=xa||x1>=xb||y1<=ya||y1>=yb)&&q==qsau)
    	{
    		hideMouse();setfillstyle(1,7);
    		bar(xa,ya,xb,yb);
    		TextGiua(xa,ya,xb,yb,t);
    		showMouse();
    		q=0;return;
    	}
    }
    
    void onClick(int x1, int y1, int xa, int ya, int xb, int yb, char*t, int qsau)
    {
    	if (x1>xa&&x1<xb&&y1>ya&&y1<yb&&q2==0)
    	{
    		Button(xa,ya,xb,yb,t,1);
    		q2=qsau; return;
    	}
    }
    
    void On_mose_over1(int x, int y)
    {
    	mouseOver(x,y,5,25,57,41,"VeDT",1);
    	mouseOver(x,y,57,25,116,41,"LuuDT",2);
    	mouseOver(x,y,116,25,216,41,"MoFileDT",3);
    	mouseOver(x,y,216,25,330,41,"XemMTtrongso",4);
    	mouseOver(x,y,330,25,430,41,"Xetduongdi",5);
    	mouseOver(x,y,430,25,510,41,"Trogiup",6);
    	mouseOver(x,y,510,25,570,41,"DTmoi",7);
    	mouseOver(x,y,570,25,630,41,"Thoat",8);
    }
    
    void chonMenu1(int x, int y)
    {
    	onClick(x,y,5,25,57,41,"VeDT",1);
    	onClick(x,y,57,25,116,41,"LuuDT",2);
    	onClick(x,y,116,25,216,41,"MoFileDT",3);
    	onClick(x,y,216,25,330,41,"XemMTtrongso",4);
    	onClick(x,y,330,25,430,41,"Xetduongdi",5);
    	onClick(x,y,430,25,510,41,"Trogiup",6);
    	onClick(x,y,510,25,570,41,"DTmoi",7);
    	onClick(x,y,570,25,630,41,"Thoat",-1); 	if (q2==-1) exit(1);
    	onClick(x,y,621,4,635,18,"X",-1); 	if (q2==-1) exit(1);
    }
    
    void xoaStatus()
    {
    	hideMouse();
    	setfillstyle(1,7);
    	bar(4,441,398,476);
    	showMouse();
    }
    
    void inStatus(int x, int y, char *t)
    {
    	hideMouse();
    	x+=5; y+=441;
    	setcolor(1);
    	outtextxy(x,y,t);
    	showMouse();
    }
    
    void smallWindow(int rong, int cao, char *t)
    {
    	int xa,xb,ya,yb; cao+=2;
    	xa=320-(rong*5);xb=320+(rong*5);
    	ya=240-(cao*6); yb=240+(cao*6);
    	hideMouse();
    	chupHinh(xa,ya,xb,yb);
    	Window(xa,ya,xb,yb,t,1);
    	showMouse();
    }
    
    void MenuDT()
    {
    	smallWindow(18,5,"Chon Loai Do Thi");
    	hideMouse();
    	setcolor(1);settextjustify(1,1);
    	outtextxy(320,236,"1. Do Thi Co Huong");
    	outtextxy(320,266,"2. Do Thi Vo Huong");
    	settextjustify(0,2);
    	showMouse();
    }
    void On_mose_over0(int x, int y)
    {
    	mouseOver(x,y,240,225,400,245,"1. Do Thi Co Huong",1);
    	mouseOver(x,y,240,255,400,275,"2. Do Thi Vo Huong",2);
    }
    
    void chonMenu0(int x, int y)
    {
    	onClick(x,y,240,225,400,245,"1. Do Thi Co Huong",1);
    	onClick(x,y,240,255,400,275,"2. Do Thi Vo Huong",2);
    	onClick(x,y,392,202,406,216,"X",1);
    	if (q2!=0) {hideMouse();xuatHinh(230,198);showMouse();}
    }
    
    
    
    void Cal()
    {
    	smallWindow(13,10,"");
    	hideMouse();
    	Button(257,192,383,212,"Nhap Trong So",1);
    
    	TextGiua(260,217,290,247,"1");
    	TextGiua(260,247,290,277,"4");
    	TextGiua(260,277,290,307,"7");
    	TextGiua(290,217,320,247,"2");
    	TextGiua(290,247,320,277,"5");
    	TextGiua(290,277,320,307,"8");
    	TextGiua(320,217,350,247,"3");
    	TextGiua(320,247,350,277,"6");
    	TextGiua(320,277,350,307,"9");
    	TextGiua(350,217,380,247,"<-");
    	TextGiua(350,247,380,277,"OK");
    	TextGiua(350,277,380,307,"0");
    	showMouse();
    }
    
    void On_mose_overCal(int x, int y)
    {
    	mouseOver(x,y,260,217,290,247,"1",1);
    	mouseOver(x,y,290,217,320,247,"2",2);
    	mouseOver(x,y,320,217,350,247,"3",3);
    	mouseOver(x,y,260,247,290,277,"4",4);
    	mouseOver(x,y,290,247,320,277,"5",5);
    	mouseOver(x,y,320,247,350,277,"6",6);
    	mouseOver(x,y,260,277,290,307,"7",7);
    	mouseOver(x,y,290,277,320,307,"8",8);
    	mouseOver(x,y,320,277,350,307,"9",9);
    	mouseOver(x,y,350,277,380,307,"0",10);
    	mouseOver(x,y,350,217,380,247,"<-",11);
    	mouseOver(x,y,350,247,380,277,"OK",12);
    }
    
    void xuatKQ(int t)			  //sua 5h/5-5
    {
    	char cht[3]; sprintf(cht,"%d",t);
    	Button(257,192,383,212,cht,1);
    }
    void chonNutCal(int x, int y, int &c)
    {
    	onClick(x,y,260,217,290,247,"1",1);
    	if (q2==1&&hang<3) {
    		ketqua=ketqua*10+1;
    		xuatKQ(ketqua);hang++; q2=0;
    	}
    	onClick(x,y,290,217,320,247,"2",2);
    	if (q2==2&&hang<3) {
    		ketqua=ketqua*10+2;
    		xuatKQ(ketqua);hang++; q2=0;
    	}
    	onClick(x,y,320,217,350,247,"3",3);
    	if (q2==3&&hang<3) {
    		ketqua=ketqua*10+3;
    		xuatKQ(ketqua);hang++; q2=0;
    	}
    	onClick(x,y,260,247,290,277,"4",4);
    	if (q2==4&&hang<3) {
    		ketqua=ketqua*10+4;
    		xuatKQ(ketqua);hang++; q2=0;
    	}
    	onClick(x,y,290,247,320,277,"5",5);
    	if (q2==5&&hang<3) {
    		ketqua=ketqua*10+5;
    		xuatKQ(ketqua);hang++; q2=0;
    	}
    	onClick(x,y,320,247,350,277,"6",6);
    	if (q2==6&&hang<3) {
    		ketqua=ketqua*10+6;
    		xuatKQ(ketqua);hang++; q2=0;
    	}
    	onClick(x,y,260,277,290,307,"7",7);
    	if (q2==7&&hang<3) {
    		ketqua=ketqua*10+7;
    		xuatKQ(ketqua);hang++; q2=0;
    	}
    	onClick(x,y,290,277,320,307,"8",8);
    	if (q2==8&&hang<3) {
    		ketqua=ketqua*10+8;
    		xuatKQ(ketqua);hang++; q2=0;
    	}
    	onClick(x,y,320,277,350,307,"9",9);
    	if (q2==9&&hang<3) {
    		ketqua=ketqua*10+9;
    		xuatKQ(ketqua);hang++; q2=0;
    	}
    	onClick(x,y,350,277,380,307,"0",10);
    	if (q2==10&&hang<3) {
    		ketqua=ketqua*10+0;
    		xuatKQ(ketqua);if (ketqua!=0) hang++; q2=0;
    	}
    	onClick(x,y,350,217,380,247,"<-",11);
    	if (q2==11&&hang>0) {
    		ketqua=ketqua/10;
    		xuatKQ(ketqua); hang--; q2=0;
    	}
    	onClick(x,y,350,247,380,277,"OK",12);
    	if (q2==12&&ketqua!=0) {
    		c=1; q2=0;
    		hideMouse(); xuatHinh(255,168); showMouse();
    	}
    	onClick(x,y,x3,y3,x3+14,y3+14,"X",13);
    	if (q2==13) {
    		ketqua=0; c=1; q2=0;
    		hideMouse(); xuatHinh(255,168); showMouse();
    	}
    	if(q2!=0) q2=0;
    }
    
    void nutVexong()
    {
    	hideMouse(); chupHinh(4,49,66,71);
    	setcolor(1); rectangle(4,49,66,71);
    	setfillstyle(1,7);bar(5,50,65,70);
    	TextGiua(5,50,65,70,"Ve Xong");
    	showMouse();
    }
    
    void File(int a)
    {
    	if (a==2) smallWindow(25,7,"Open File");
    	if (a==1) smallWindow(25,7,"Save File");
    	hideMouse(); setcolor(1);
    	outtextxy(205,215,"Ten File:");
    	TextGiua(265,255,375,270,">> Enter de dong y");
    	TextGiua(265,275,375,290,">> ESC de huy bo  ");
    	showMouse();
    	Button(203,225,437,245,"Nhap ten File",1);
    }
    
    void XuatTenFile(char &ch, int d) //sua 5h/5-5
    {	char t;
    	t=getch(); int len=strlen(F);
    	if (t==13&&F[0]!=NULL){			//Enter
    		c2=0; Menu(); useMouse=1;
    		hideMouse(); xuatHinh(195,186);showMouse();
    		if(d==1) luuDT(F);
    		if(d==2) nhapDT(F);
    		return;
    	}
    	if (t==27) {
    		c2=0; q3=1; useMouse=1;  Menu();			///ESC
    		hideMouse(); xuatHinh(195,186);showMouse();
    		return;}
    	if ((t>=65&&t<=122||t==46)&&len<27){			//ky tu chu hoac dau \ hoac dau . : duong dan vi du: ..\quang hay BGI\quang
    		ch=t; i++;
    		Button(203,225,437,245,F,1);
    		}
    	if (t==8&&i>=0){				//Backspace
    		i--;F[i]=NULL;
    		Button(203,225,437,245,F,1);
    	}
    }
    
    void xetDuongdi()
    {
    	smallWindow(21,6,"Xet duong di");
    	hideMouse(); setcolor(1);
    	outtextxy(225,225,"Xet duong di:");
    	outtextxy(225,246,"Tu dinh");
    	outtextxy(320,246,"Den dinh");
    	showMouse();
    	Button(288,241,315,258,"",1);
    	Button(390,241,417,258,"",1);
    	Button(225,265,417,283,"Nhap dinh bat dau",1);
    }
    
    void chonDinhS(int ss)//int &d, int ss)
    {
    	while (c2==5)
    	{
    		int chon; 
    		chon=getch();
    		if (chon>=48&&chon<=57&&S<10)
    		{
    //			chon-=48;
    			S=S*10+chon-48;
    			Button(288,241,315,258,toS(S),1);
    			if (S!=ss&&S<n) Button(225,265,417,283,"Dinh hop le",1);
    			if (S==ss) Button(225,265,417,283,"Hai dinh trung nhau",1);
    			if (S>=n) Button(225,265,417,283,"Dinh khong ton tai",1);
    		}
    		if (chon==27)
    		{					//ESC
    			c2=0;    xoaStatus(); Menu(); useMouse=1;
    			hideMouse(); xuatHinh(215,192);showMouse();
    			return;
    		}
    		if (chon==13&&S!=ss&&S<n){		//Enter
    			Button(225,265,417,283,"Nhap dinh ket thuc",1);
    			return;
    		}
    		if (chon==8&&i>=0){		// <-
    			S/=10;
    			Button(288,241,315,258,toS(S),1);
    			if (S!=ss&&S<n) Button(225,265,417,283,"Dinh hop le",1);
    			if (S==ss) Button(225,265,417,283,"Hai dinh trung nhau",1);
    			if (S>=n) Button(225,265,417,283,"Dinh khong ton tai",1);
    		}
    
    	}
    }
    
    void chonDinhT(int ss)//int &d, int ss)
    {
    	while (c2==5)
    	{
    		int chon; 
    		chon=getch();
    		if (chon>=48&&chon<=57&&T<10)
    		{
    //			chon-=48;
    			T=T*10+chon-48;
    			Button(390,241,417,258,toS(T),1);
    			if (T!=ss&&T<n) Button(225,265,417,283,"Dinh hop le",1);
    			if (T==ss) Button(225,265,417,283,"Hai dinh trung nhau",1);
    			if (T>=n) Button(225,265,417,283,"Dinh khong ton tai",1);
    		}
    		if (chon==27)
    		{					//ESC
    			c2=0;    Menu();  xoaStatus(); useMouse=1;
    			hideMouse(); xuatHinh(215,192);showMouse();
    			return;
    		}
    		if (chon==13&&T!=ss&&T<n){		//Enter
    			c2=0; q3=1;useMouse=1;
    			Menu();	hideMouse(); xuatHinh(215,192);showMouse();
    			return;
    		}
    		if (chon==8&&i>=0){		// <-
    			T/=10;
    			Button(390,241,417,258,toS(T),1);
    			if (T!=ss&&T<n) Button(225,265,417,283,"Dinh hop le",1);
    			if (T==ss) Button(225,265,417,283,"Hai dinh trung nhau",1);
    			if (T>=n) Button(225,265,417,283,"Dinh khong ton tai",1);
    		}
    
    	}
    }
    
    void loaiHD(int loai)
    {
    	int ax,bx; //150,480,170
    	if (loai==1) {ax=155; bx=200;}
    	if (loai==2) {ax=203; bx=303;}
    	if (loai==3) {ax=306; bx=407;}
    	if (loai==4) {ax=410; bx=477;}
    	setcolor(7);	line(ax,170,bx,170);
    	setcolor(15); 	line(150,170,ax,170);	line(bx,170,480,170);
    }
    
    void HuongDan(int loai)
    {
    	int td=180,tc=160;
    	if(loai==5){
    		hideMouse();
    		chupHinh(150,125,480,350);
    		Window(150,125,480,350,"Huong dan su dung chuong trinh",1);showMouse();
    		Button(155,150, 200,170,"VeDT",0); 		
    		Button(203,150, 303,170,"Luu/MoFile",0);
    		Button(306,150, 407,170,"XetDuongDi",0);
    		Button(410,150, 477,170,"TacGia",0);	
    	}
    	hideMouse();
    	setfillstyle(1,7); bar(153,173,477,325);
    	setcolor(1); 
    	TextGiua(160,327,470,347,"<< Da xem xong >>");
    	if (loai==1||loai==5){
    		outtextxy(tc,td,"- Nhan  VeDT  de bat dau ve");td+=18;
    		outtextxy(tc,td,"- Nhan chuot trai de ve dinh");td+=18;
    		outtextxy(tc,td,"- Nhan giu va keo chuot tu dinh nay den ");td+=14;
    		outtextxy(tc,td,"  dinh khac de ve dinh");td+=18;
    		outtextxy(tc,td,"- Doi trong so bang cach ve lai canh");td+=18;
    		outtextxy(tc,td,"- Nhan nut  Ve Xong  de hoan tat ");td+=18;
    		outtextxy(tc,td,"- Nhan  VeDT  de tiep tuc ve ");td+=18;
    		outtextxy(tc,td,"- Nhan  DTmoi de ve do thi moi ");
    		loaiHD(1);
    	}
    	if (loai==2){
    		outtextxy(tc,td,"- Chi luu duoc khi da co do thi");td+=18;
    		outtextxy(tc,td,"- Khi ghi ten File khong dung ky");td+=14;
    		outtextxy(tc,td,"  tu so va ky tu dac biet");td+=18;
    		outtextxy(tc,td,"- Enter de dong y luu/mo File");td+=18;
    		outtextxy(tc,td,"- ESC de huy bo viec luu/mo File");td+=18;
    		loaiHD(2);
    	}
    	if (loai==3){
    		outtextxy(tc,td,"- Chi xet duong di khi da co do thi");td+=18;
    		outtextxy(tc,td,"- Ghi dinh bat dau");td+=14;
    		outtextxy(tc,td,"   + Enter");td+=14;
    		outtextxy(tc,td,"   + Dinh bat dau phai co trong do thi");td+=18;
    		outtextxy(tc,td,"- Ghi dinh ket thuc");td+=14;
    		outtextxy(tc,td,"   + Enter");td+=14;
    		outtextxy(tc,td,"   + Dinh ket thuc phai co trong do thi");td+=18;
    		outtextxy(tc,td,"      va khac dinh bat dau");td+=18;
    		outtextxy(tc,td,"- ESC de huy bo xet duong di");
    		loaiHD(3);
    	}
    	if (loai==4){
    		tc+=10;
    		TextGiua(160,td,470,td+12,"TRUONG DH SU PHAM KY THUAT");td+=12;
    		TextGiua(160,td,470,td+12,"KHOA CONG NGHE THONG TIN");td+=12;
    		TextGiua(160,td,470,td+12,"MON LY THUYET DO THI");td+=12;
    		TextGiua(160,td,470,td+12,"DE TAI 13 - DIJKSTRA");td+=20;
    		outtextxy(tc+10,td,"- Nhom thuc hien:");td+=12;
    		outtextxy(tc,td,"05110148  -  Nguyen Ngoc Tri");td+=12;
    		outtextxy(tc,td,"05118041  -  Dang Vu Minh Quang");td+=12;
    		outtextxy(tc,td,"05110102  -  Nguyen Thanh Phuoc");td+=12;
    		outtextxy(tc,td,"05110006  -  Nguyen Thi Ngoc Anh");td+=12;
    		outtextxy(tc,td,"05110026  -  Ngoc Le Dung");td+=12;
    		loaiHD(4);
    	}
    	showMouse();
    }
    
    void mouseOverHD(int x1, int y1, int xa,int ya, int xb, int yb, int l)
    {
    	if (x1>xa&&x1<xb&&y1>ya&&y1<yb&&q3!=l)
    	{
    		HuongDan(l);
    		q3=l; return;
    	}
    }
    Đã được chỉnh sửa lần cuối bởi nguyen190887 : 08-06-2007 lúc 11:02 PM. Lý do: sai quy định
    I know... nothing

  3. #3
    Ngày gia nhập
    05 2007
    Bài viết
    64

    Mặc định Mô phỏng thuật toán Dijktra (good ^.^ good) !!!

    < còn nữa nè >

    Code:
    void On_mouse_overHD(int x, int y)
    {
    	mouseOverHD(x,y,155,150, 200,170,1);
    	mouseOverHD(x,y,203,150, 303,170,2);
    	mouseOverHD(x,y,306,150, 407,170,3);
    	mouseOverHD(x,y,410,150, 477,170,4);
    	mouseOver(x,y,160,327,470,347,"<< Da xem xong >>",5);
    }
    
    void thoatHD(int x,int y){
    	onClick(x,y,160,327,470,347,"<< Da xem xong >>",5);
    	onClick(x,y,x3,y3,x3+14,y3+14,"X",5);
    	if (q2==5) {hideMouse();xuatHinh(150,125);showMouse();Menu();}
    }
    
    void MTTS()
    {
    	if(n<11)
    {	int socot=n, cot,dong;
    	int td1,tc1,tc2; char tso[3];
    	td1=80; tc2=15; 
    	if (socot<4){ td1=80+((4-socot)*8);tc2=15+((4-socot)*15); socot=4;}
    	tc1=tc2; 
    	chupHinh(5,50,335-((10-socot)*30),250-((10-socot)*16));
    	Window(5,50,335-((10-socot)*30),250-((10-socot)*16),"Ma Tran Trong So",1);
    	x3=5;y3=50;
    	socot=n;
    	setcolor(4); outtextxy(tc1,td1,toS(n));  tc1+=18; cot=0;
    	setcolor(8); while(cot<socot) {outtextxy(tc1,td1,toS(cot)); tc1+=30;cot++;}
    	tc1=tc2; td1+=15; cot=0;dong=0;
    	while (dong<socot){
    		settextjustify(0,2);
    		if (cot==0) {setcolor(8); outtextxy(tc1,td1,toS(dong)); cot++; tc1+=18;}
    		if (cot!=0) {setcolor(1); sprintf(tso,"%d",M[dong][cot-1]);
    		outtextxy(tc1,td1,tso); tc1+=30; cot ++; 
    		if (cot>socot) {dong++; cot=0; tc1=tc2;td1+=15;}}
    	}
    }
    	if(n>=11)
    {	int socot=5;
    	int td1,tc1; 
    	td1=170+(9*7); tc1=160+((10-socot)*15); 
    	chupHinh(150+((10-socot)*15),140+(9*7),480-((10-socot)*15),340-(9*8));
    	Window(150+((10-socot)*15),140+(9*7),480-((10-socot)*15),340-(9*8),"Ma Tran Trong So",1);
    	x3=150+((10-socot)*15);y3=140+(9*7);
    	setcolor(1); outtextxy(tc1,td1,"So dinh >10"); td1+=15;
    	outtextxy(tc1,td1,"Khong the xuat MT");
    }
    }
    
    int benTrong(int x,int y)
    {
    if (x>5+R && x<66-R && y>71+R && y<435-R)
    	return 1;
    if (x>=66+R && x<=635-R && y>=50+R && y<=435-R)
    	return 1;
    return 0;
    }
    
    void VeDT(int &s, int x,int y,int&c2) //Q sua 8h30/5-5
    {
      int c;
    		if (s)
    		{
    			if (x>5&&y>50&&x<65&&y<70)
    				{hideMouse();  setfillstyle(0,7); bar(4,49,66,71);Menu(); showMouse();c2=0;return;}
    			if (checkPoint(x,y,2*R) && benTrong(x,y))
    			{
    				getArray(x,y);
    				drawCircle(x,y,n-1,YELLOW,BLUE);
    			}
    			checkMin(x,y,j1);
    			while(s)
    			{
    				dragMouse(s,x,y);
    				checkMin(x,y,j3);
    				if (!s && !checkPoint(x,y,R) && (distance(x,y,a[j1].x,a[j1].y)>R*R))
    				{
    					checkMin(x,y,j2);useWin(0);
    					Cal();q=0; ketqua=0; hang=0; q2=0; c=3;
    					while(c==3)
    					{
    						Locate();
    						On_mose_overCal(x1,y1);
    						clickMouse(s,x,y);
    						if(s){
    							chonNutCal(x,y,c);
    						}
    					}
    					if(ketqua!=0){
    						drawLine(a[j1].x,a[j1].y,a[j2].x,a[j2].y,MAU_DT);
    						if (M[j1][j2]!=0) ghiTS(j1,j2,M[j1][j2],MAU_NEN);
    						w2m(ketqua);
    						ghiTS(j1,j2,ketqua,MAU_TS);
    					}
    					xoaStatus();useWin(1);
    					inStatus(10,5,"Ve do thi");q=0;q2=0;
    				}
    
    			}
    		}
    }
    
    void drawCircle(int x,int y,int i,int mau1,int mau2)
    {
    	char *ch;
    	hideMouse();
    	setcolor(mau1);
    	setfillstyle(1,mau2);
    	pieslice(x,y,0,360,R);
    	setcolor(mau2);
    	line(x,y,x+R-1,y);
    	setcolor(mau1);
    	itoa(i++,ch,10);
    	settextjustify(1,1);
    	outtextxy(x,y,ch);
    	showMouse();
    }
    
    void drawLine(int x1,int y1,int x2,int y2,int mau)
    {
    	setcolor(mau);
    	hideMouse();
    	line(x1,y1,x2,y2);
    	if (c1==1) chi_huong(x1,y1,x2,y2,(x1+2*x2)/3,(y1+2*y2)/3);
    	showMouse();
    	setcolor(BLUE);
    }
    
    void initArrayTS()
    {
    	int i,j;
    	for (i=0;i<MAX;i++)
    		for (j=0;j<MAX;j++)
    			M[i][j]=0;
    }
    
    void getArray(int x,int y)
    {
    	a[n].x=x;
    	a[n].y=y;
    	n++;
    }
    
    long distance(int x1,int y1,int x2,int y2)
    {
    	long s=pow(x1-x2,2)+pow(y1-y2,2);
    	return s;
    }
    
    int checkPoint(int x,int y,int r)
    {
    	int i;
    	long s;
    	if (n==0) return 1;
    	for (i=0;i<=n;i++)
    	{
    		s=distance(a[i].x,a[i].y,x,y);
    		//pow((x-a[i].x),2)+pow((y-a[i].y),2);
    		if (s<r*r) return 0;
    	}
    	return 1;
    }
    
    void checkMin(int x,int y,int &j)
    {
    	int i;
    	long s,min=pow(getmaxx(),2)+pow(getmaxy(),2);
    	for (i=0;i<n;i++)
    	{
    		s=distance(x,y,a[i].x,a[i].y);
    		if (s<min)
    		{
    			min=s;
    			j=i;
    		}
    	}
    }
    
    void w2m(int ts)
    {
    	M[j1][j2]=ts;
    	if(c1==2)	M[j2][j1]=ts;
    }
    
    void w2f(char *name)
    {
    	int I,J;
    	file=fopen(name,"w");
    	fprintf(file,"%d\n",n);
    	for (I=0;I<n;I++)
    	{
    		for (J=0;J<n;J++)
    			fprintf(file,"%5d",M[I][J]);
    		fprintf(file,"\n");
    	}
    	fclose(file);
    }
    
    void xuly(int loai)
    {
    	int i,j;
    	for (i=0;i<n;i++)
    		for (j=0;j<n;j++)
    		{
    			if (M[i][j]==0&&loai==0) M[i][j]=15000;
    			if (M[i][j]==15000&&loai==1) M[i][j]=0;
    		}
    }
    
    void dijkstra()
    {
    	xuly(0);
    	int u,v;
    	for (v=0;v<n;v++)
    	{
    		d[v]=M[S][v];
    		truoc[v]=S;
    		final[v]=0;
    
    	}
    	truoc[S]=0;
    	d[S]=0;
    	final[S]=1;
    
    	while (!final[T])
    	{
    		minp=20000;
    		for (v=0;v<n;v++)
    			if (!final[v] && d[v]<minp)
    			{
    				u=v;
    				minp=d[v];
    			}
    		final[u]=1;
    		//if (!final[t])
    			for (v=0;v<n;v++)
    				if (!final[v] && d[v]>d[u]+M[u][v])
    				{
    					d[v]=d[u]+M[u][v];
    					truoc[v]=u;
    				}
    	}
    }
    
    void rewrite()
    {
    	int i,j;
    	for (i=so;i>0;i--)
    		{
    			setlinestyle(0,1,3);
    			drawLine(a[L[i]].x,a[L[i]].y,a[L[i-1]].x,a[L[i-1]].y,MAU_NEN);
    			//ghiTS(L[i],L[i-1],M[L[i]][L[i-1]],MAU_NEN);
    			setlinestyle(0,1,1);
    			drawLine(a[L[i]].x,a[L[i]].y,a[L[i-1]].x,a[L[i-1]].y,MAU_DT);
    			//ghiTS(L[i],L[i-1],M[L[i]][L[i-1]],MAU_TS);
    		}
    	setlinestyle(0,1,1);
    }
    
    void inKQ()
    {
    	int i; int tc=10, td=445;
    	char *c,*temp;
    	setcolor(BLUE);
    	for (i=0;i<n;i++)
    	{
    		drawCircle(a[i].x,a[i].y,i,YELLOW,BLUE);
    	}
    	if (d[T]==15000)
    	{
    		xoaStatus(); setcolor(4); settextjustify(0,2);
    		outtextxy(tc,td,"Khong co duong di");
    	}
    	else
    	{
    		i=truoc[T];
    		L[0]=T;
    		so=1;
    		while (i!=S)
    		{
    			L[so]=i;
    			so++;
    			i=truoc[i];
    
    		}
    		L[so]=S;
    		xoaStatus();
    		setcolor(1); settextjustify(0,2);
    		outtextxy(tc,td,"Tong trong so: "); tc+=150; setcolor(4);
    		outtextxy(tc,td,toS(d[T])); tc=10; td+=11; setcolor(1);  //td=455
    		outtextxy(tc,td,"Duong di: "); tc+=100;
    		setcolor(4); outtextxy(tc,td,toS(S)); tc+=20;
    		setlinestyle(0,1,3);
    		for (i=so;i>0;i--)
    		{
    			setcolor(1);
    			outtextxy(tc,td,"=>"); tc+=25; if (tc>370) {tc=10; td+=11; if (td>468) {xoaStatus(); td=445;}}
    			setcolor(4); outtextxy(tc,td,toS(L[i-1])); 
    			drawLine(a[L[i]].x,a[L[i]].y,a[L[i-1]].x,a[L[i-1]].y,RED);
    			delay(1000);
    			if (i!=1) {setcolor(1); outtextxy(tc,td,toS(L[i-1]));} tc+=20; if (tc>370) {tc=10;td+=11;if (td>468) {xoaStatus(); td=445;}}
    			
    		}
    		setlinestyle(0,1,1);
    	}
    	xuly(1);
    }
    
    void ghiTS(int j1,int j2,int value,int mau) //Q sua 8h30/5-5
    {
    	char *c;                                                       //
    	int x3,y3,vt=2;                                                //
    	if (c1==2) vt=1;                                               //
    	x3=(a[j1].x+vt*a[j2].x)/(vt+1); y3=(a[j1].y+vt*a[j2].y)/(vt+1);//
    	c=(char*)malloc(4*sizeof(char)); c[0]=NULL;
    	sprintf(c,"%d",value);
    	setcolor(mau);
    	if ((a[j1].x-a[j2].x)*(a[j1].y-a[j2].y)>0)
    		outtextxy(x3+2,y3-8,c);
    	else
    		outtextxy(x3+2,y3+2,c);
    	free(c);
    }
    
    double goc(int x1, int y1, int x2, int y2)
    {
    	double a,b;
    	a=x1-x2;
    	b=y1-y2;
    	if (y1-y2<0) return 2*pi-acosl((a)/sqrt((a*a)+(b*b)));
    	else         return      acosl((a)/sqrt((a*a)+(b*b)));
    }
    
    void chi_huong(int x1, int y1, int x2, int y2, int x3, int y3)
    {
    	double anpha;
    	anpha=goc(x2,y2,x1,y1);
    	//setcolor(BLUE) ;
    	line(x3,y3,x3-15*cos(anpha+pi/10),y3-15*sin(anpha+pi/10));
    	line(x3,y3,x3-15*cos(anpha-pi/10),y3-15*sin(anpha-pi/10));
    }
    
    void xoaDiem(int x,int y)
    {
    	int i=0,j,temp;
    	while(distance(x,y,a[i].x,a[i].y)>R*R && i<n)
    	{
    		i++;
    	}
    	temp=i;
    
    	/***	VE VONG TRON CO MAU NEN DE XOA DIEM		***/
    //	setcolor(MAU_NEN);
    //	setfillstyle(1,MAU_NEN);
    	hideMouse();
    	drawCircle(a[i].x,a[i].y,0,MAU_NEN,MAU_NEN);
    	showMouse();
    
    	/***	XOA DUONG THANG XUAT PHAT TU DINH VUA XOA	***/
    	for (i=0;i<n;i++)
    	{
    		if (M[temp][i]>0)
    		{
    			drawLine(a[temp].x,a[temp].y,a[i].x,a[i].y,MAU_NEN);
    			ghiTS(temp,i,M[temp][i],MAU_NEN);
    			//	VE LAI DIEM
    			drawCircle(a[i].x,a[i].y,i,MAU_SO,MAU_VT);
    			M[temp][i]=0;
    		}
    		if (M[i][temp]>0)
    		{
    			drawLine(a[i].x,a[i].y,a[temp].x,a[temp].y,MAU_NEN);
    			ghiTS(i,temp,M[i][temp],MAU_NEN);
    			//	VE LAI DIEM
    			drawCircle(a[i].x,a[i].y,i,MAU_SO,MAU_VT);
    			M[i][temp]=0;
    		}
    	}
    
    	/***	THAY CAC GIA TRI TRONG MANG CHUA TOA DO BANG 0
    				DE CO THE VE DUOC TIEP TREN VUNG VUA XOA	***/
    	i=temp;
    	a[i].x=a[i].y=0;
    
    	/*** DON MANG LAI	***/
    	while (i<n)
    	{
    		a[i].x=a[i+1].x;
    		a[i].y=a[i+1].y;
    		i++;
    	}
    	for (i=0;i<n;i++)
    		for (j=temp;j<n;j++)
    		{
    			M[i][j]=M[i][j+1];
    			//M[j][i]=M[j+1][i];
    		}
    	for (j=0;j<n;j++)
    		for (i=temp;i<n;i++)
    			M[i][j]=M[i+1][j];
    
    
    	n--;
    //	index--;		//	GIAM INDEX
    
    	/*** VE LAI CAC DIEM SAU KHI XOA	***/
    	for (i=temp;i<n;i++)
    	{
    		drawCircle(a[i].x,a[i].y,i,MAU_SO,MAU_VT);
    	}
    }
    
    void luuDT(char *name)
    {
    	FILE *f;
    	int i,j;
    	f=fopen(name,"w");
    	fprintf(f,"%3d%3d\n",n,c1);
    	for (i=0;i<n;i++)
    		fprintf(f,"%5d%5d\n",a[i].x,a[i].y);
    	fclose(f);
    	strcat(name,"ts");
    
    	f=fopen(name,"w");
    	fprintf(f,"%d\n",n);
    	for (i=0;i<n;i++){
    		for (j=0;j<n;j++)
    			fprintf(f,"%5d",M[i][j]);
    		fprintf(f,"\n");
    	}
    	fclose(f);
    }
    
    void velaiDT()		//Q sua 8h30/5-5
    {
    	int i,j2;
    	hideMouse();
    	setfillstyle(0,7); bar(5,50,635,435);
    	for (i=0;i<n;i++)
    		drawCircle(a[i].x,a[i].y,i,MAU_SO,MAU_VT);
    	setfillstyle(1,7); bar(405,442,634,457);
    	setcolor(1); settextjustify(1,1);
    	if (c1==1) outtextxy(520,450,"DO THI CO HUONG");
    	if (c1==2) outtextxy(520,450,"DO THI VO HUONG");
    	settextjustify(0,2);
    	for (i=0;i<n;i++)
    		for (j=0;j<n;j++)
    			if (M[i][j]>0)
    			{
    				drawLine(a[i].x,a[i].y,a[j].x,a[j].y,MAU_DT);
    				if (c1==2) { if (i>j) ghiTS(i,j,M[i][j],MAU_TS);}
    				else ghiTS(i,j,M[i][j],MAU_TS);
    			}
    	showMouse();
    }
    
    void nhapDT(char *name)
    {
    	FILE *f;
    	int i,j,dem,co=0;
    	f=fopen(name,"r");
    	fscanf(f,"%d%d",&n,&c1);
    	for (i=0;i<n;i++)
    		fscanf(f,"%d%d",&a[i].x,&a[i].y);
    	fclose(f);
    	strcat(name,"ts");
    	f=fopen(name,"r");
    	fscanf(f,"%d",&n);
    	for (i=0;i<n;i++)
    		for (j=0;j<n;j++)
    			fscanf(f,"%d",&M[i][j]);
    	fclose(f);
    	velaiDT();
    }
    
    char* toS(int n)
    {
    	char *c;
    	itoa(n,c,10);
    	return c;
    }
    Đã được chỉnh sửa lần cuối bởi nguyen190887 : 08-06-2007 lúc 10:59 PM. Lý do: sai quy định
    I know... nothing

  4. #4
    Ngày gia nhập
    11 2007
    Nơi ở
    Da Nang, Vietnam, Vietnam
    Bài viết
    1

    sao mình thử chạy bài của bạn thì báo lỗi, nhưng ko fix đc.

  5. #5
    Ngày gia nhập
    12 2008
    Bài viết
    53

    Build làm sao chạy bạn.Hay bạn sắp xếp thứ tự file rồi nén thành zip post lên cho anh em xem nào...!

  6. #6
    Ngày gia nhập
    04 2009
    Bài viết
    1

    Mặc định Code C: Mô phỏng thuật toán Dijktra

    Bạn sắp xếp thứ tự file rồi nén thành zip post lên đi,chứ nó báo lỗi hoài àh.

  7. #7
    Ngày gia nhập
    07 2009
    Bài viết
    73

    bạn nào post hoàn chỉnh em xxem fát

  8. #8
    Ngày gia nhập
    07 2009
    Bài viết
    73

    thank nguyen9887 nhe
    da~ sap xep dc bài hehe
    1 file dijkstra.cpp ở phần đầu tiên
    còn 2 phần dưới cho vào 1 file DIJKSTRA.H
    Rồi copy 2 file đó vào BIN
    Còn hễ bị lỗi là do chưa chạy đồ họa rùi
    vào option->linker->libraries-> chọn Graphicss library
    option->linker->libraries-> chọn Turbo Vission la ok ngay

  9. #9
    Ngày gia nhập
    03 2009
    Bài viết
    523

    Em down Turbo C++ 3.0 về nhưng ko setup dc, mấy bác chỉ giúp em với.

  10. #10
    Ngày gia nhập
    07 2009
    Bài viết
    73

    dajka viết code bài Dijkstra này cho em hỏi cái
    anh co thể cho biết ý nghĩa những biến này thế nào ko , và dc dùng như thế nào
    HELP ME sắp OUTTIME rồi dajka ơi !
    Code:
    typedef struct point {
    	int x,y;
    };
    
    int c1,c2,c3,x,s,y,x1,y1,x2,y2,x3,y3,q,q2,q3,hang,ketqua,i;
    char ch[50]; char F[30];
    unsigned img; char *pimg;
    int M[MAX][MAX];
    int n=0; int t1,t2;
    int j;
    int j1,j2,j3;
    point a[MAX];	//	MANG a CHUA TOA DO CUA CAC DIEM DA VE
    FILE *file;
    int truoc[MAX],d[MAX],final[MAX];
    int S,T,n1,minp=2000;
    int L[MAX],so;
    int useMouse=1;
    anh có thể giải thích phần thuật toán Dijkstra ko
    void xuly(int loai)
    void dijkstra();
    giải thích hộ em 2 cái void này với
    THANKS !!!
    Live as If tommorrow never comes

Các đề tài tương tự

  1. Bài tập C++ code thuật toán clipping và mô tả thuật toán
    Gửi bởi binhc trong diễn đàn Thắc mắc lập trình C/C++/C++0x
    Trả lời: 0
    Bài viết cuối: 05-06-2013, 07:56 PM
  2. Cần tìm người code C# lương thỏa thuận
    Gửi bởi zaroyahoo trong diễn đàn Việc làm IT(tự do)
    Trả lời: 0
    Bài viết cuối: 24-05-2013, 04:00 PM
  3. code tìm cây có trọng lượng nhỏ nhất bằng giải thuật prim-cách chạy tay code này
    Gửi bởi ruacon_206 trong diễn đàn Thắc mắc lập trình C/C++/C++0x
    Trả lời: 3
    Bài viết cuối: 25-04-2011, 02:27 PM
  4. Cần source code thuật toán Apriori và thuật toán Eclat !
    Gửi bởi ronaldo1984 trong diễn đàn Thắc mắc lập trình Visual C++
    Trả lời: 0
    Bài viết cuối: 27-07-2010, 09:25 AM
  5. Giải Thuật Dijktra trên C++
    Gửi bởi honbuom123 trong diễn đàn Nhập môn lập trình C/C++
    Trả lời: 2
    Bài viết cuối: 25-12-2009, 11:17 AM

Quyền hạn của bạn

  • Bạn không thể gửi đề tài mới
  • Bạn không thể gửi bài trả lời
  • Bạn không thể gửi các đính kèm
  • Bạn không thể chỉnh sửa bài viết của bạn