Đăng ký Đăng nhập
Trang chủ Nguồn tin kinh tế tại trung tâm thông tin tư liệu khoa học và công nghệ quốc gia...

Tài liệu Nguồn tin kinh tế tại trung tâm thông tin tư liệu khoa học và công nghệ quốc gia

.DOC
13
81
54

Mô tả:

Website: http://www.docs.vn Email : [email protected] Tel (: 0918.775.368 bµi 2. 1.§Ò bµi: M« pháng cuéc ch¹y thi giöa 2 tµu chiÕn gäi lµ Tµu 1 vµ Tµu 2. Néi dung nh sau: Cã 2 tµu chiÕn gäi lµ Tµu1 vµ Tµu 2 xuÊt ph¸t t¹i cïng mét c¨n cø ®iÓm vµ ®i ®Õn ®Ých trong mét lé tr×nh dµi Y (km). Trong qu¸ tr×nh ®i th× c¸c tµu ph¶i dõng l¹i tiÕp nhiªn liÖu däc ®êng. Do cã dùa vµo trang thiÕt bÞ hiÖn ®¹i vµ ®îc chÕ t¹o víi c«ng nghÖ cao h¬n nªn Tµu 1 cã vËn tèc lín h¬n Tµu 2 tuy nhiªn còng v× lý do ®ã mµ Tµu1 cã hÖ sè s½n sµng xuÊt ph¸t bÐ thua hÖ sè s½n sµng xuÊt ph¸t cña Tµu 2. Trªn ®êng ®i cø mçi lÇn dõng l¹i ®Ó tiÕp nhiªn liÖu c¸c tµu l¹i tiÕp tôc xuÊt ph¸t víi hÖ sè s½n sµng lÇn lîc lµ hssst1 vµ hssst2. Qu·ng ®êng ®i ®îc cña c¶ hai tµu ®îc céng dån. H·y thiÕt lËp mét bµi to¸n m« pháng víi c¸c hÖ sè s½n sµng lµ mét sè ngÉu nhiªn sao cho Tµu 2 cã x¸c suÊt vÒ ®Ých lín h¬n Tµu 1. 2. Ph©n tÝch ®Ò bµi. Bµi to¸n nµy thuéc lo¹i bµi to¸n m« h×nh ho¸ hÖ ngÉu nhiªn víi biÕn ngÉu nhiªn ë ®©y lµ hÖ sè s½n sµng xuÊt ph¸t cña c¸c tµu. Trong thuËt gi¶i nµy th× vËn tèc cña c¸c tµu cã thÓ ®îc thÓ hiÖn qua qu·ng ®êng mµ nã di chuyÓn ®îc trong mét kho¶ng thêi gian nhÊt ®Þnh cho tríc. Nh vËy khi thùc hiÖn gieo mét sè ngÉu nhiªn th× ta ph¶i so s¸nh víi c¸c hÖ sè s½n sµng cña c¶ hai tµu ®Ó ra quyÕt ®Þnh tµu nµo xuÊt ph¸t. Thùc hiÖn gieo c¸c sè ngÉu nhiªn ®Ó thö lµ néi dung cña ph¬ng ph¸p m« h×nh ho¸ hÖ ngÉu nhiªn. Néi dung cña ph¬ng ph¸p ®îc tr×nh bµy ë trong bµi 1. 3. C¸c biÕn ngÉu nhiªn Nh trªn ®· tr×nh bµy sù xuÊt ph¸t cña c¸c tµu ®îc ®¸nh gi¸ qua mét sè ngÉu nhiªn ®ã lµ hÖ sè xuÊt ph¸t. Nh vËy biÕn ngÉu nhiªn ë ®©y chÝnh lµ hÖ sè xuÊt ph¸t. NÕu nh hÖ sè s½n sang cña c¸c tµu ®îc lÊy c¸c gi¸ trÞ trong kho¶ng [0,1] th× sè ngÉu nhiªn lµ mét sè cã ph©n bè U(0,1). 4. Ph©n tÝch gi¶i thuËt. Gi¶i thuËt cho bµi to¸n trªn ®îc x©y dùng nh sau: + Cho tríc c¸c th«ng sè kh«ng ®æi trong qu¸ tr×nh chuyÓn ®éng nh vËn tèc cña c¸c tÇu vµ qu·ng ®êng di chuyÓn sau mçi lÇn tiÕp nhiªn liÖu. + Gieo mét sè ngÉu nhiªn x=U(0,1): NÕu xhssst1 th× Tµu 2 xuÊt ph¸t + Thùc hiÖn so s¸nh qu·ng ®êng di chuyÓn ®îc cña c¶ hai tµu so víi ®é dµi qu·ng ®êng Ên ®Þnh tríc nÕu tÇu nµo vÒ ®Ých tríc th× kÕt thóc cuéc ch¬i. 5. Lu ®å thuËt gi¶i nh sau: NhËp sè liÖu hssst1,hssst2 NhËp Y LÊy x=U(0,1) x<=hssst1 § Tau1cd, Tµu 2cd S S § hssst1<=x<=hssst2 xt1=xt1+x01 or xt2=xt2+x02 S Tµu 2cd S xt1=Y or xt2=Y xt2=xt2+x02 S § xt2=Y § END 6.§iÒu kiÖn ®Çu, ®iÒu kiÖn dõng m« pháng. §iÒu kiÖn ®Çu ë ®©y lµ kho¶ng c¸c cña hµnh tr×nh vµ c¸c kho¶ng c¸c chuyÓn ®éng cña Tµu 1 vµ Tµu 2. §iÒu kiÖn dõng chuyÓn ®éng lµ khi mét trong 2 tµu vÒ ®Ých. 7.Ch¬ng tr×nh m« pháng. Ch¬ng tr×nh sau ®îc x©y dùng trªn ng«n ng÷ C víi m· nguån ®îc cho díi ®©y. #include"mou.h" #include"iostream.h" #include"math.h" #include"conio.h" #include"stdio.h" #include"graphics.h" #define Enter 13 void Write_text(int x1, int y1,double x,char*s,int color); void write_value(int*x,int*y,char*s); void read_value(int*x,int*y,char*s); int Nhap_kc_tau1(void); int Nhap_kc_tau2(void); double Nhap_hsss_tau1(void); double Nhap_hsss_tau2(void); void Data_in(void); void void void void tau1_cd(void); tau2_cd(void); ve_tau1(void); ve_tau2(void); void Win(void); void Run(void); void button(int x1,int y1,int x2,int y2,int color,char s[],int color_s,int size); void button1(int x1,int y1,int x2,int y2,int color); void _line(int x1, int y1, int x2, int y2, int color); void _line1(int x1,int y1,int x2,int y2); void main_h(void); void help(void); int xt,yt,xr,yr,nt,nr,i,j=0,k=0,t=0,kct1,kct2,a=0; double hst1,hst2; char*pr,*pt; void write_value(int*x,int*y,char*s) { outtextxy(*x,*y,s); *x+=textwidth(s); } void read_value(int*x,int*y,char*s) { int i=0;char ch[2]; ch[1]=0; while(1) { ch[0]=getch(); if(ch[0]==Enter) break; write_value(x,y,ch); s[i]=ch[0]; ++i; } s[i]=0; } int Nhap_kc_tau1() { int xt1=220,yt1=380; char*st1; read_value(&xt1,&yt1,st1); return atoi(st1); } int Nhap_kc_tau2() { int xt2=220,yt2=435; char*st2; read_value(&xt2,&yt2,st2); return atoi(st2); } double Nhap_hsss_tau1() { int xst1=470,yst1=380; char*sst1; read_value(&xst1,&yst1,sst1); return atof(sst1); } double Nhap_hsss_tau2() { int xst2=470,yst2=435; char*sst2; read_value(&xst2,&yst2,sst2); return atof(sst2); } void Data_in(void) { char ch; setcolor(1); kct1=Nhap_kc_tau1(); kct2=Nhap_kc_tau2(); hst1=Nhap_hsss_tau1(); hst2=Nhap_hsss_tau2(); //ch=getch(); // if(ch==Enter) Run(); // Run(); } void ve_tau1(void) { setcolor(RED); ellipse(100,50,0,360,20,8); ellipse(100,46,190,357,20,6); line(107,44,110,38); circle(110,38,2); line(93,44,90,38); circle(90,38,2); setfillstyle(SOLID_FILL,BLUE); floodfill(101,54,RED); setfillstyle(SOLID_FILL,MAGENTA); floodfill(94,45,RED); } void ve_tau2(void) { setcolor(7); ellipse(100,50,0,360,20,8); ellipse(100,46,190,357,20,6); line(107,44,110,38); circle(110,38,2); line(93,44,90,38); circle(90,38,2); } setfillstyle(SOLID_FILL,GREEN); floodfill(101,54,7); setfillstyle(SOLID_FILL,13); floodfill(94,45,7); void tau2_cd(void) { if(j<1) putimage(50,170,pr,XOR_PUT); j=j+1; if(j>1) putimage(xr,yr,pr,XOR_PUT); xr=50+kct2*(j-1);yr=170; while(xr=540) { setcolor(15); outtextxy(250,250,"Tau 2 chien thang"); putimage(xr,yr,pr,XOR_PUT); Win(); putimage(xr,yr,pr,XOR_PUT); } if(xr>=kct2*j+50) putimage(xr,yr,pr,XOR_PUT); } } void tau1_cd() { if(k<1) putimage(50,250,pt,XOR_PUT); k=k+1; if(k>1) putimage(xt,yt,pt,XOR_PUT); xt=50+kct1*(k-1);yt=250; while(xt=540) { setcolor(15); outtextxy(250,250,"Tau 1 chien thang"); putimage(xt,yt,pt,XOR_PUT); Win(); putimage(xt,yt,pt,XOR_PUT); } if(xt>=kct1*k+50) putimage(xt,yt,pt,XOR_PUT); } /*void rua_tho_cd(); { if(j<1) putimage(50,200,pr,XOR_PUT); j=j+1; if(j>1) putimage(xr,yr,pr,XOR_PUT); if(k<1) putimage(50,300,pt,XOR_PUT); k=k+1; if(k>1) putimage(xt,yt,pt,XOR_PUT); xr=50+70*(j-1);yr=200; xt=50+98*(k-1);yt=300; while((xr<70*j+50)&(xt<98*k+50)) { putimage(xr,yr,pr,XOR_PUT); delay(500); putimage(xr,yr,pr,XOR_PUT); xr=xr+7; putimage(xt,yt,pt,XOR_PUT); delay(200); putimage(xt,yt,pt,XOR_PUT); xt=xt+10; if(xr==540) { setcolor(15); outtextxy(250,250,"Rua chien thang"); putimage(xr,yr,pr,XOR_PUT); Win(); putimage(xr,yr,pr,XOR_PUT); } if(xt==540) { setcolor(15); outtextxy(250,250,"Tho chien thang"); putimage(xt,yt,pt,XOR_PUT); Win(); putimage(xt,yt,pt,XOR_PUT); } if(xr>=70*j+50) putimage(xr,yr,pr,XOR_PUT); if(xt>=98*k+50) putimage(xt,yt,pt,XOR_PUT); } */ } void Write_text(int x1, int y1,double x,char*s,int color) { gcvt(x,5,s); setcolor(color); outtextxy(x1,y1,s); } void button(int x1,int y1,int x2,int y2,int color,char s[],int color_s,int size) { setfillstyle(1,color); bar(x1,y1,x2,y2); setcolor(15); setlinestyle(0,0,1); line(x1,y1,x2,y1); line(x1,y1,x1,y2); setcolor(0); line(x2,y2,x2,y1); line(x2,y2,x1,y2); } settextjustify(1,1); settextstyle(0,0,size); setcolor(color_s); outtextxy((x1+x2)/2,(y1+y2)/2,s); void button1(int x1,int y1,int x2,int y2,int color) { setfillstyle(1,color); bar(x1,y1,x2,y2); setcolor(0); setlinestyle(0,0,1); line(x1,y1,x2,y1); line(x1,y1,x1,y2); setcolor(15); line(x2,y2,x2,y1); line(x2,y2,x1,y2); } void _line(int x1, int y1, int x2, int y2, int color) { setcolor(color); line(x1,y1,x2,y1); line(x2,y1,x2,y2); line(x2,y2,x1,y2); line(x1,y2,x1,y1); } void _line1(int x1, int y1, int x2, int y2) { setfillstyle(1,9); bar(x1+1,y1+1,x2-1,y2-1); setcolor(0); line(x1,y1,x2,y1); line(x1,y1,x1,y2); line(x1+1,y2-1,x2-1,y2-1); line(x2-1,y2-1,x2-1,y1+1); setcolor(15); line(x1+1,y1+1,x2-1,y1+1); line(x1+1,y1+1,x1+1,y2-1); line(x1,y2,x2,y2); line(x2,y2,x2,y1); } void help() { int mh,mode; mh=DETECT;mode=1; initgraph(&mh,&mode,"..\\bgi"); setbkcolor(1); cleardevice(); Reset_mouse(); Show_mouse(); _line(2,2,637,478,15); _line(5,5,634,475,2); _line(7,8,630,472,15); _line(137,127,523,333,15); _line(135,125,525,335,2); settextstyle(7,0,1); setcolor(5); Hide_mouse(); button1(140,130,520,330,11); setcolor(8); settextjustify(0,0); settextstyle(0,0,1); outtextxy(146,150,"Phan mem mo phong va mo hinh hoa bai 2"); outtextxy(240,170,"Nhom sinh vien thiet ke:"); outtextxy(280,190,"Nguyen Le Hoa"); outtextxy(280,210,"Doan Phi Hung"); outtextxy(280,230,"Hoang Vu Hung"); outtextxy(280,250,"Lai Thien Hung"); outtextxy(165,270,"Phan mem duoc hoan thanh voi su giup do cua"); outtextxy(240,290,"PGS.TS Nguyen Cong Hien"); setcolor(12); outtextxy(265,310,"-------***-------"); Show_mouse(); button(180,380,240,410,2,"Return",1,1); button(420,380,480,410,2,"Exit",1,1); while(1) { } Click_mouse(); if(Win_mouse(180,380,240,410)==1&&Click_mouse()==1) { main_h(); } if(Win_mouse(420,380,480,410)==1&&Click_mouse()==1) { exit(1); } } void Run() { double n1; int n,i=0,k=1; // a=a+50; char*s; //randomize(); while(xt<540 & xr<540&k) { k=0; i=i+1; n=rand() % 10; n1=n*0.1; Write_text(100+40*i,130,n1,s,1); if((n1>hst1)&(n1<=hst2)) { tau2_cd(); delay(1000); } // else if(n1<=hst1) { tau1_cd(); tau2_cd(); delay(1000); } k=1; } } void Win() { int x[1001],y[1001],k; int i,n; char*p[1001]; for(i=1;i<=1000;++i) { x[i]=random(getmaxx())-10; y[i]=random(getmaxy())-10; if(x[i]<0) x[i]=0; if(y[i]<0) y[i]=0; n=imagesize(x[i],y[i],x[i]+10,y[i]+10); p[i]=(char*)malloc(n); getimage(x[i],y[i],x[i]+10,y[i]+10,p[i]); // } while(t<5) do { for(i=1;i<=100;++i) { setfillstyle(SOLID_FILL,i%15+1); pieslice(x[i]+5,y[i]+5,0,360,5); } delay(500); for(i=100;i>=1;--i) putimage(x[i],y[i],p[i],COPY_PUT); delay(500); t=t+1; } } void main_h(void) { long *p; int mh=0,mode=0; int xmax ,ymax; initgraph(&mh,&mode,"..\\bgi "); Hide_mouse(); ve_tau2(); Show_mouse(); nt=imagesize(79,36,121,59); pt=(char*)malloc(nt); getimage(79,36,121,59,pt); Hide_mouse(); ve_tau1(); Show_mouse(); randomize(); nr=imagesize(79,36,121,59); pr=(char*)malloc(nr); getimage(79,36,121,59,pr); cleardevice(); Reset_mouse(); setfillstyle(1,3); xmax=getmaxx(); ymax=getmaxy(); bar(0,0,xmax,ymax); Show_mouse(); _line(2,2,637,478,15); _line(5,5,634,475,13); _line(7,8,630,472,15); setcolor(RED); _line(50,150,53,300,15); //outtextxy(50,40,"Gia tri ngau nhien nhan duoc:"); //outtextxy(50,20,"Click Run button to create a number"); _line(580,150,583,300,RED); setcolor(RED); outtextxy(30,130,"START"); outtextxy(560,130,"FINISH"); outtextxy(180,110,"Gia tri ngau nhien nhan duoc"); setcolor(15); outtextxy(60,150,"Tau2"); outtextxy(60,230,"Tau1"); /*--Vung chuc nang---*/ Show_mouse(); _line1(15,350,619,465); _line1(15,17,619,100); button(50,45,100,75,2,"Help",1,1); button(170,45,220,75,2,"Run",1,1); button(290,45,340,75,2,"Reset",1,1); button(410,45,460,75,2,"Data",1,1); button(530,45,580,75,2,"Exit",1,1); /*--Vung vao du lieu--*/ setcolor(15); outtextxy(150,380,"KC_tau 1:"); outtextxy(150,435,"KC_tau 2:"); outtextxy(400,380,"Hsss_tau 1:"); outtextxy(400,435,"Hsss_tau 2:"); button1(200,370,250,390,15); button1(200,425,250,445,15); button1(450,370,500,390,15); button1(450,425,500,445,15); button1(100,120,540,140,15); putimage(50,250,pt,XOR_PUT); putimage(50,170,pr,XOR_PUT); while(1) { Click_mouse(); if( Win_mouse(50,45,100,75)==1&&Click_mouse()==1) { help(); } if( Win_mouse(170,45,220,75)==1&&Click_mouse()==1) { Run(); } if( Win_mouse(290,45,340,75)==1&&Click_mouse()==1) { main_h(); } if( Win_mouse(410,45,460,75)==1&&Click_mouse()==1) { Data_in(); random } if( Win_mouse(530,45,580,75)==1&&Click_mouse()==1) { exit(1); } } } void main() { main_h(); } 8. KÕt qu¶ m« pháng 9. NhËn xÐt vµ b×nh luËt kÕt qu¶. Ta nhËn thÊy víi mét kho¶ng c¸ch chuyÓn ®éng cho tríc th× qu¸ tr×nh gieo sè ngÉu nhiªn th× tuú thuéc vµo ®é s½n sµng cña tõng tÇu mµ x¸c ®Þnh ® îc sè lÇn chuyÓn ®éng cña mçi tµu. Ta cã thª thay ®æi c¸c th«ng sè ®Çu vµo ®Ó x¸c suÊt Tµu 2 th¾ng nhiÒu h¬n tµu 1. 10. Tµi liÖu tham kh¶o. 1. Gi¸o tr×nh M« h×nh ho¸ hÖ thèng vµ m« pháng-PGS.TS NguyÔn C«ng HiÒn 2. Ng«n ng÷ lËp tr×nh C- Ph¹m V¨n Êt.
- Xem thêm -

Tài liệu liên quan