intTypePromotion=1
zunia.vn Tuyển sinh 2024 dành cho Gen-Z zunia.vn zunia.vn
ADSENSE

Bài tập lớn NLHĐH

Chia sẻ: Tran Thanh Xuyen | Ngày: | Loại File: DOC | Số trang:13

321
lượt xem
100
download
 
  Download Vui lòng tải xuống để xem tài liệu đầy đủ

Đây là tài liệu môn HĐH nâng cao mà mình tìm được, hy vọng với những giải thuật sẽ giúp ích cho các bạn. Tài liệu không tránh khỏi sai sót, mời các bạn cùng tham khảo.

Chủ đề:
Lưu

Nội dung Text: Bài tập lớn NLHĐH

  1. Bài tập lớn NLHĐH #include #include #include #include #include #include #include #include int *tentt,*ten; //tentt: ten cac tt nhap vao, ten: danh sach ten tt xuat ra unsigned int *txh,*tth,*moctg,*daxh; //txh,tth:thoi gian xh va th cau tien trinh. daxh:danh dau tien trinh da xh trong hang doi int n,m; //n:so tien trinh,m:so o duoc ve //HAM NHAP DU LIEU void nhapdl() { coutn; tentt=(int*)malloc(n*sizeof (int)); txh=(unsigned int*)malloc(n*sizeof (int)); tth=(unsigned int*)malloc(n*sizeof (int)); daxh=(unsigned int*)malloc(n*sizeof (int)); gotoxy(35,4); cout
  2. t=txh[(l+r)/2]; int i=l,j=r; while(i
  3. d2++; } d1++; } } //HAM THUC HIEN CUA THUAT TOAN SJF void thSJF(int *hangdoi, int &xh,int &so,unsigned int *tthhd,unsigned int *tconlai,int &m) { if(so>0 || xh
  4. { moctg[m]=txh[i]; tconlai[so-1]-=moctg[m]-moctg[m-1]; i=n+1; //Neu co tien trinh ngat -> dung tien trinh dang thuc hien } if(i==n) so--; //Neu khong co tien trinh ngat -> thuc hien xong tt dang th -> loai bo khoi hang doi } } if(so>0 || xh
  5. so++; xh++; daxh[i]=1; hangdoi[so-1]=tentt[i]; tthhd[so-1]=tth[i]; tconlai[so-1]=tth[i]; } //Sap xep lai hang doi int tg; if(so>1) { for(int i=0;i0) { ten[m]=hangdoi[so-1]; moctg[m+1]=moctg[m]+tconlai[so-1]; m++; int tam; for(int i=0;i
  6. //HAM THUC HIEN THUAT TOAN SRT void SRT(int &m) { settextstyle(1,0,1); settextjustify(1,1); outtextxy(320,80,"Thuat toan SRT"); unsigned int *tthhd,*tconlai; int *hangdoi,so=0,xh=0; ten=(int*)calloc(m+1,sizeof(int)); moctg=(unsigned int*)calloc(m+2,sizeof(int)); hangdoi=(int*)calloc(n,sizeof(int)); tthhd=(unsigned int*)calloc(n,sizeof(int)); tconlai=(unsigned int*)calloc(n,sizeof(int)); m=0; moctg[0]=0; for(int i=0;i0 || xh
  7. if(so>0) // Neu so phan tu hang doi >0, dua phan tu dau hang doi vao thuc hien { if(tthtr[so-1] dua no ve cuoi hang doi { moctg[m+1]=moctg[m]+q; ten[m]=hangdoi[so-1]; for(int i=so-1;i>0;i--) { hangdoi[i]=hangdoi[i-1]; tthtr[i]=tthtr[i-1]; daxh[i]=daxh[i-1]; } hangdoi[0]=ten[m]; int vt; for(i=0;i
  8. } if(so>0 || xh
  9. settextjustify(1,2); settextstyle(0,0,1); int ax,ay,bx,by,rong=40; //Toa do cac o vuong can ve int d=0,i=0,j=0; //d:So o can ve; i:Ve o theo hang; j:Xuong dong moi khi het hang char *s; while(d620) //Neu so o vuong khong the chua het tren mot hang->xuong hang { i=0;j++;} ax=210+i*rong; ay=120+5+j*40; bx=210+rong+i*rong; by=120+5+20+j*40; //Tinh toa do cac o vuong setcolor(WHITE); rectangle(ax,ay,bx,by); //Ve o vuong itoa(ten[d],s,10); setcolor(YELLOW); settextjustify(1,1); outtextxy((ax+bx+textwidth("P"))/2,(ay+by)/2,s); //Xuat cac ten tien trinh settextjustify(2,1); outtextxy((ax+bx+textwidth("P"))/2-textwidth(s)/2,(ay+by)/2,"P"); settextjustify(1,2); setcolor(LIGHTGRAY); itoa(moctg[d],s,10); outtextxy(ax,by+3,s); //Xuat cac moc thoi gian if(i==360/rong) { itoa(moctg[d+1],s,10); outtextxy(bx,by+3,s); } if(ten[d]==-99) //Tao o trong {setfillstyle(0,0); bar(ax+3,ay+3,bx-3,by-3);} d++; i++; //Dem tong so o da ve } itoa(moctg[d],s,10); outtextxy(bx,by+3,s); } //Ham kt de tinh thoi gian cho doi cho cac tien trinh int ktcomat(int a,int ds[],int &d) { int i=0; while(i
  10. { int *ds,*tkt,*tcd; //ds:cac tien trinh da duoc tinh, tkt:mang luu tg ket thuc cua cac tien trinh //tcd:mang luu thoi gian cho cua cac tien trinh float ttb; //ttb:thoi gian cho doi trung binh ds=(int*)calloc(1,sizeof(int)); tkt=(int*)calloc(n,sizeof(int)); tcd=(int*)calloc(n,sizeof(int)); int i=m-1,d=0; ds[0]=-99; while(d=0) //Duyet nguoc tu cuoi mang ten,moctg.Neu tt nao chua co mat trong ds cac tien trinh da duoc tinh tg kt -> lay moctg[i+1] la tg ket thuc { if(!ktcomat(ten[i],ds,d)) { tkt[d]=moctg[i+1]; d++; ds=(int*)realloc(ds,(d+1)*sizeof(int)); ds[d]=ten[i]; } i--; } //Sap lai mang thoi gian ket thuc theo dung tentt for(i=0;i
  11. } void gt() { setcolor(WHITE); settextstyle(1,0,2); settextjustify(0,2); outtextxy(80,80,"DANH SACH THANH VIEN NHOM 1"); settextstyle(1,0,1); outtextxy(80,100,"1.Nguyen Tuan Anh"); outtextxy(80,115,"2.Pham Tuan Luong"); outtextxy(80,130,"3.Do thi Hong Van"); outtextxy(80,145,"4.Nguyen Van Bat"); outtextxy(80,160,"5.Nguyen Trung Hieu"); outtextxy(80,175,"6.Doan xuan Nghia"); getch(); } void xuatdebai(int &n,int *tentt,unsigned int *txh,unsigned int *tth) { char as[30]; setcolor(YELLOW); settextstyle(0,0,1); settextjustify(0,2); outtextxy(10,40,"TenTT"); outtextxy(60,40,"TXH"); outtextxy(90,40,"TTH"); rectangle(5,35,120,55+15*n); rectangle(5,15,120,35); settextjustify(1,2); outtextxy(60,25,"DE BAI"); settextjustify(0,2); for(int i=0;i
  12. { clrscr(); restorecrtmode(); //tro ve man hinh soan thao nhapdl(); //Nhap du lieu s: restorecrtmode(); //Dua ra menu cho nguoi dung chon lua thuat toan gotoxy(5,4); cout
  13. else if(k=='4') RR(m); else if(k=='6') { gt(); goto s;} else goto s; if(k!='6') { vesodogrant(ten,m,moctg); //Ve so do Grant xuatdebai(n,tentt,txh,tth); //Xuat de bai float ttb=floor(TGCDTB()*100+0.5)/100; //Tinh thoi gian cho doi trung binh cua thuat toan setcolor(RED); settextstyle(1,0,1); char as[30]; settextjustify(1,2); sprintf(as,"Thoi gian cho doi tb: %f",ttb); outtextxy(440,440,as); getch(); goto s; closegraph(); //Dong man hinh do hoa } } } //Ket thuc chuong trinh
ADSENSE

CÓ THỂ BẠN MUỐN DOWNLOAD

 

Đồng bộ tài khoản
2=>2