迷宮問題以一個m*n的長方陣表示迷宮,0和1分別表示迷宮中的通路和障礙.設計一個程序,對任意設定的迷宮,求出一條入口到出口的通路,或的出沒有通路的結論. {基本要求}: (1)實現一個以鏈表作存儲結構的棧類型,然后編寫一個求解迷宮的非遞歸程序。求得的通路以三元組(i,j,d)的形式輸出,其中:(i,j)指示迷宮中的一個坐標,d表示走到下一個坐標的方向. (2)編寫遞歸形式的算法,求迷宮中所有通路. (3)以方陣形式輸出迷宮及其通路
標簽: 迷宮
上傳時間: 2014-01-03
上傳用戶:zhengzg
設初始序列為a1,a2,……,an,以序列中的某個元素ai為基準(軸),經調整后,使得ai左邊的元素均小于ai,右邊的均大于等于ai,而后對這兩個子區再分別使用快速排序。 [具體要求] (1) 需要用一維數組a來存儲等待排序的序列; (2) 設置兩個工作指針i和j; (3) 每次快速排序都以排序區域的首元素為基準(軸); (4) 程序用遞歸函數來實現。
標簽: c++
上傳時間: 2015-12-28
上傳用戶:markhu53
/**************************************************************** 外部晶振8M PA0~3:四位數碼管的位選 PB0~7:數碼管的8位段選 外部中斷0用于計數 定時器0溢出中斷的定時為1ms 說明 :檢測到水流較小時,繼電器延時1秒關閉 ******************************************************************/ #include<iom16v.h> #include<macros.h> #define uchar unsigned char #define uint unsigned int char led_7[10]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F}; //數碼管段選 char position[4]={0xfe,0xfd,0xfb,0xf7};//數碼管位選 uint sumnum=0; //用于記錄1000ms內進入中斷的次數 uint time=0; //記錄進入比較定時器0的次數 uint num=0; //記錄1ms內進入中斷的次數 uint count=0; //進入外部中斷0的次數 uchar flag; uint sumnum1; //記錄100ms內的數目 /***************************函數聲明***************************/ void delay(); void display(uint m ); void init(); void init_0(); void init_2(); void _delay_us(uint l) { unsigned int i; for(i=0;i<l;i++) { asm("nop"); } } /**************************主函數***********************************/ void main() { init(); init_0(); init_2(); while(sumnum<5) { PORTD=0XBF; segdisplay(sumnum1); } while(1) { segdisplay(sumnum1); } } /*************************掃描數碼管時的延時函數*********************/ void delay() { uchar i,j; for(i=6;i>0;i--) for(j=225;j>0;j--); } /************************數碼管顯示函數*****************************/ void segdisplay( int temp) { int seg[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; int temp1,temp2,temp3,temp4; temp1=temp/1000; temp2=(temp/100)%10; temp3=(temp/10)%10; temp4=temp%10; DDRB=0xff; DDRA|=0x0f; PORTA=~BIT(3); PORTB=seg[temp1]; _delay_us(100); PORTA=~BIT(2); PORTB=seg[temp2]; _delay_us(100); PORTA=~BIT(1); PORTB=seg[temp3]; _delay_us(100); PORTA=~BIT(0); PORTB=seg[temp4]; _delay_us(100); } /***********************管腳初始化函數*********************/ void init() { DDRD|=0X40; //PD4 設置為輸出 PORTD=0XBF; DDRA=0XFF; DDRB=0XFF; PORTA=0XFF; PORTB=0XFF; } /***********************外部中斷0初始化*********************/ void init_0() { MCUCR=0X02; //INT0為下降沿觸發 GICR=0X40; //使能INT0中斷 SREG=0X80; //使能總中斷 } /**********************定時器2初始化***********************/ void init_2() { TCCR0=0x03; // 內部時鐘,64 分頻(8M/64=125KHz) TCNT0=0x83; //裝初值 TIMSK=0x01; // 允許 T/C0溢出中斷中斷 } /***********************外部中斷0子函數********************/ #pragma interrupt_handler int0_isr:2 void int0_isr(void) { count++; } /*********************定時計數器0溢出中斷子函數*****************/ #pragma interrupt_handler int0_over:10 void int0_over(void) { TCNT0=0x83; //重裝初值 if((time%100) == 0) sumnum1 = num; if(time == 1000) { sumnum=num; if(sumnum<10) { if((flag==1)&&(sumnum<10)) { PORTD=0XFF; flag=0; } flag++; } else PORTD=0XBF; num=0; time=0; } num+=count; count=0; ++time; }
標簽: C語言
上傳時間: 2016-03-09
上傳用戶:彥 yan
# include < reg52.h > # include < 24C02.h> # define uint unsigned int # define uchar unsigned char sbit rs = P3^5; //定義lcd1602的rs端 sbit lcden = P3^4;//定義lcd1602的lcden端口 sbit s1 = P3^0;//定義功能鍵s1 sbit s2 = P3^1;//定義功能鍵s2 sbit s3 = P3^2;//定義功能鍵s3 sbit beep = P2^3;//定義蜂鳴器 uchar count, s1num; char miao,fen,shi; uchar code table[] = "Designer:X_ZL ";//定義初始上電時液晶默認顯示狀態 void delay_ms( xms ) //定義延時函數 { uint i,j; for( i = xms ; i > 0 ; i --) for( j = 110 ; j > 0 ; j --); }
上傳時間: 2016-07-28
上傳用戶:游戲好嗎
void DFS(MGraph G, int i) { int j; visited[i] = TRUE; printf("%c ", G.vexs[i]); for (j=0; j<G.numVertexes; ++j) { if (G.arc[i][j]!=INFINITY && !visited[j]) DFS(G, j); } }
上傳時間: 2016-12-28
上傳用戶:chenyameng
#include <malloc.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #define NULL 0 #define MaxSize 30 typedef struct athletestruct /*運動員*/ { char name[20]; int score; /*分數*/ int range; /**/ int item; /*項目*/ }ATH; typedef struct schoolstruct /*學校*/ { int count; /*編號*/ int serial; /**/ int menscore; /*男選手分數*/ int womenscore; /*女選手分數*/ int totalscore; /*總分*/ ATH athlete[MaxSize]; /**/ struct schoolstruct *next; }SCH; int nsc,msp,wsp; int ntsp; int i,j; int overgame; int serial,range; int n; SCH *head,*pfirst,*psecond; int *phead=NULL,*pafirst=NULL,*pasecond=NULL; void create(); void input () { char answer; head = (SCH *)malloc(sizeof(SCH)); /**/ head->next = NULL; pfirst = head; answer = 'y'; while ( answer == 'y' ) { Is_Game_DoMain: printf("\nGET Top 5 when odd\nGET Top 3 when even"); printf("\n輸入運動項目序號 (x<=%d):",ntsp); scanf("%d",pafirst); overgame = *pafirst; if ( pafirst != phead ) { for ( pasecond = phead ; pasecond < pafirst ; pasecond ++ ) { if ( overgame == *pasecond ) { printf("\n這個項目已經存在請選擇其他的數字\n"); goto Is_Game_DoMain; } } } pafirst = pafirst + 1; if ( overgame > ntsp ) { printf("\n項目不存在"); printf("\n請重新輸入"); goto Is_Game_DoMain; } switch ( overgame%2 ) { case 0: n = 3;break; case 1: n = 5;break; } for ( i = 1 ; i <= n ; i++ ) { Is_Serial_DoMain: printf("\n輸入序號 of the NO.%d (0<x<=%d): ",i,nsc); scanf("%d",&serial); if ( serial > nsc ) { printf("\n超過學校數目,請重新輸入"); goto Is_Serial_DoMain; } if ( head->next == NULL ) { create(); } psecond = head->next ; while ( psecond != NULL ) { if ( psecond->serial == serial ) { pfirst = psecond; pfirst->count = pfirst->count + 1; goto Store_Data; } else { psecond = psecond->next; } } create(); Store_Data: pfirst->athlete[pfirst->count].item = overgame; pfirst->athlete[pfirst->count].range = i; pfirst->serial = serial; printf("Input name:) : "); scanf("%s",pfirst->athlete[pfirst->count].name); } printf("\n繼續輸入運動項目(y&n)?"); answer = getchar(); printf("\n"); } } void calculate() /**/ { pfirst = head->next; while ( pfirst->next != NULL ) { for (i=1;i<=pfirst->count;i++) { if ( pfirst->athlete[i].item % 2 == 0 ) { switch (pfirst->athlete[i].range) { case 1:pfirst->athlete[i].score = 5;break; case 2:pfirst->athlete[i].score = 3;break; case 3:pfirst->athlete[i].score = 2;break; } } else { switch (pfirst->athlete[i].range) { case 1:pfirst->athlete[i].score = 7;break; case 2:pfirst->athlete[i].score = 5;break; case 3:pfirst->athlete[i].score = 3;break; case 4:pfirst->athlete[i].score = 2;break; case 5:pfirst->athlete[i].score = 1;break; } } if ( pfirst->athlete[i].item <=msp ) { pfirst->menscore = pfirst->menscore + pfirst->athlete[i].score; } else { pfirst->womenscore = pfirst->womenscore + pfirst->athlete[i].score; } } pfirst->totalscore = pfirst->menscore + pfirst->womenscore; pfirst = pfirst->next; } } void output() { pfirst = head->next; psecond = head->next; while ( pfirst->next != NULL ) { // clrscr(); printf("\n第%d號學校的結果成績:",pfirst->serial); printf("\n\n項目的數目\t學校的名字\t分數"); for (i=1;i<=ntsp;i++) { for (j=1;j<=pfirst->count;j++) { if ( pfirst->athlete[j].item == i ) { printf("\n %d\t\t\t\t\t\t%s\n %d",i,pfirst->athlete[j].name,pfirst->athlete[j].score);break; } } } printf("\n\n\n\t\t\t\t\t\t按任意建 進入下一頁"); getchar(); pfirst = pfirst->next; } // clrscr(); printf("\n運動會結果:\n\n學校編號\t男運動員成績\t女運動員成績\t總分"); pfirst = head->next; while ( pfirst->next != NULL ) { printf("\n %d\t\t %d\t\t %d\t\t %d",pfirst->serial,pfirst->menscore,pfirst->womenscore,pfirst->totalscore); pfirst = pfirst->next; } printf("\n\n\n\t\t\t\t\t\t\t按任意建結束"); getchar(); } void create() { pfirst = (struct schoolstruct *)malloc(sizeof(struct schoolstruct)); pfirst->next = head->next ; head->next = pfirst ; pfirst->count = 1; pfirst->menscore = 0; pfirst->womenscore = 0; pfirst->totalscore = 0; } void Save() {FILE *fp; if((fp = fopen("school.dat","wb"))==NULL) {printf("can't open school.dat\n"); fclose(fp); return; } fwrite(pfirst,sizeof(SCH),10,fp); fclose(fp); printf("文件已經成功保存\n"); } void main() { system("cls"); printf("\n\t\t\t 運動會分數統計\n"); printf("輸入學校數目 (x>= 5):"); scanf("%d",&nsc); printf("輸入男選手的項目(x<=20):"); scanf("%d",&msp); printf("輸入女選手項目(<=20):"); scanf("%d",&wsp); ntsp = msp + wsp; phead = (int *)calloc(ntsp,sizeof(int)); pafirst = phead; pasecond = phead; input(); calculate(); output(); Save(); }
標簽: 源代碼
上傳時間: 2016-12-28
上傳用戶:150501
/*import java.util.Scanner; //主類 public class student122 { //主方法 public static void main(String[] args){ //定義7個元素的字符數組 String[] st = new String[7]; inputSt(st); //調用輸入方法 calculateSt(st); //調用計算方法 outputSt(st); //調用輸出方法 } //其他方法 //輸入方法 private static void inputSt(String st[]){ System.out.println("輸入學生的信息:"); System.out.println("學號 姓名 成績1,2,3"); //創建鍵盤輸入類 Scanner ss = new Scanner(System.in); for(int i=0; i<5; i++){ st[i] = ss.next(); //鍵盤輸入1個字符串 } } //計算方法 private static void calculateSt(String[] st){ int sum = 0; //總分賦初值 int ave = 0; //平均分賦初值 for(int i=2;i<5;i++) { /計總分,字符變換成整數后進行計算 sum += Integer.parseInt(st[i]); } ave = sum/3; //計算平均分 //整數變換成字符后保存到數組里 st[5] = String.valueOf(sum); st[6] = String.valueOf(ave); } //輸出方法 private static void outputSt(String[] st){ System.out.print("學號 姓名 "); //不換行 System.out.print("成績1 成績2 成績3 "); System.out.println("總分 平均分");//換行 //輸出學生信息 for(int i=0; i<7; i++){ //按格式輸出,小于6個字符,補充空格 System.out.printf("%6s", st[i]); } System.out.println(); //輸出換行 } }*/ import java.util.Scanner; public class student122 { public static void main(String[] args) { // TODO 自動生成的方法存根 String[][] st = new String[3][8]; inputSt(st); calculateSt(st); outputSt(st); } //輸入方法 private static void inputSt(String st[][]) { System.out.println("輸入學生信息:"); System.out.println("班級 學號 姓名 成績:數學 物理 化學"); //創建鍵盤輸入類 Scanner ss = new Scanner(System.in); for(int j = 0; j < 3; j++) { for(int i = 0; i < 6; i++) { st[j][i] = ss.next(); } } } //輸出方法 private static void outputSt(String st[][]) { System.out.println("序號 班級 學號 姓名 成績:數學 物理 化學 總分 平均分"); //輸出學生信息 for(int j = 0; j < 3; j++) { System.out.print(j+1 + ":"); for(int i = 0; i < 8; i++) { System.out.printf("%6s", st[j][i]); } System.out.println(); } } //計算方法 private static void calculateSt(String[][] st) { int sum1 = 0; int sum2 = 0; int sum3 = 0; int ave1 = 0; int ave2 = 0; int ave3 = 0; for(int i = 3; i < 6; i++) { sum1 += Integer.parseInt(st[0][i]); } ave1 = sum1/3; for(int i = 3; i < 6; i++) { sum2 += Integer.parseInt(st[1][i]); } ave2 = sum2/3; for(int i = 3; i < 6; i++) { sum3 += Integer.parseInt(st[2][i]); } ave3 = sum3/3; st[0][6] = String.valueOf(sum1); st[1][6] = String.valueOf(sum2); st[2][6] = String.valueOf(sum3); st[0][7] = String.valueOf(ave1); st[1][7] = String.valueOf(ave2); st[2][7] = String.valueOf(ave3); } }
上傳時間: 2017-03-17
上傳用戶:simple
問題描述:以一個m*n的長方陣表示迷宮,0和1分別表示迷宮中的通路和障礙。設計一個程序,對任意設定的迷宮,求出一條從入口到出口的通路,或得出沒有通路的結論。 1.基本要求 (1)首先實現一個以鏈表作存儲結構的棧類型,然后編寫一個求解迷宮的非遞歸程序。求得的通路以三元組(i,j,d)的形式輸出。其中:(i,j)指示迷宮中的一個坐標,d表示走到下一坐標的方向。如下圖所示迷宮。從入口(1,1)到出口(8,8)的求解結果如下: (1,1)(1,2),(2,2)(3,2)(3,1)(4,1)(5,1)(5,2)(5,3)(6,3)(6,4)(6,5)(5,5)(4,5)(4,6)(4,7)(3,7)(3,8)(4,8)(5,8)(6,8)(7,8)(8,8) (2)以方陣形式輸出迷宮及其通路。 2.重點、難點 重點:針對迷宮問題的特點,利用棧的后進先出特點,選擇適當的數據結構。 難點:遞歸算法的設計與求解。
標簽: 迷宮
上傳時間: 2018-07-03
上傳用戶:MOOMWHITE
function [R,k,b] = msc(A) % 多元散射校正 % 輸入待處理矩陣,通過多元散射校正,求得校正后的矩陣 %% 獲得矩陣行列數 [m,n] = size(A); %% 求平均光譜 M = mean(A,2); %% 利用最小二乘法求每一列的斜率k和截距b for i = 1:n a = polyfit(M,A(:,i),1); if i == 1 k = a(1); b = a(2); else k = [k,a(1)]; b = [b,a(2)]; end end %% 求得結果 for i = 1:n Ai = (A(:,i)-b(i))/k(i); if i == 1 R = Ai; else R = [R,Ai]; end end
上傳時間: 2020-03-12
上傳用戶:15275387185
P P I I CK I I T T3 3 使用 說明--- - 連機 、 脫 機操作試用 MPLAB IDE 軟件一 、 P P I I C CK K I I T3 接 口說 明, , 硬 件 二 、 P P I I C CK K I I T3 連 接 電腦 MPL L AB I I DE 聯機三 、 聯機四 、聯機讀芯片程序五 、 脫機 燒寫 調試
上傳時間: 2022-03-24
上傳用戶: