-
prolog 找路例子程序:
=== === === === === ===
Part 1-Adding connections
Part 2-Simple Path
example
| ?- path1(a,b,P,T).
will produce the response:
T = 15
P = [a,b] ?
Part 3 - Non-repeating path
As an example, the query:
?- path2(a,h,P,T).
will succeed and may produce the bindings:
P = [a,depot,b,d,e,f,h]
T = 155
Part 4 - Generating a path below a cost threshold
As an example, the query:
?- path_below_cost(a,[a,b,c,d,e,f,g,h],RS,300).
returns:
RS = [a,b,depot,c,d,e,g,f,h] ?
RS = [a,c,depot,b,d,e,g,f,h] ?
no
==================================
標簽:
Part
connections
example
prolog
上傳時間:
2015-04-24
上傳用戶:ljt101007
-
編寫具有如下函數原型的遞歸與非遞歸兩種函數equ,負責判斷數組a與b的前n個元素值是否按下標對應完全相同,是則返回true,否則返回false。并編制主函數對它們進行調用,以驗證其正確性。
bool equ(int a[], int b[], int n)
提示:遞歸函數中可按如下方式來分解并處理問題,先判斷最后一個元素是否相同,不同則返false;相同則看n是否等于1,是則返回true,否則進行遞歸調用(傳去實參a、b與 n-1,去判斷前n-1個元素的相等性),并返回遞歸調用的結果(與前n-1個元素的是否相等性相同)。
標簽:
equ
函數
遞歸
編寫
上傳時間:
2013-12-03
上傳用戶:梧桐
-
數據結構
1、算法思路:
哈夫曼樹算法:a)根據給定的n個權值{W1,W2… ,Wn }構成 n棵二叉樹的集合F={T1,T2…,T n },其中每棵二叉樹T中只有一個帶權為W i的根結點,其左右子樹均空;b)在F中選取兩棵根結點的權值最小的樹作為左右子樹構造一棵新的二叉樹,且置新的二叉樹的根結點的權值為其左、右子樹上結點的權值之和;c)F中刪除這兩棵樹,同時將新得到的二叉樹加入F中; d)重復b)和c),直到F只含一棵樹為止。
標簽:
算法
W1
數據結構
樹
上傳時間:
2016-03-05
上傳用戶:lacsx
-
void III_hufman_decode(struct Granule *gr,int part2_start,
int freqline[SBLIMIT][SSLIMIT])
{
unsigned int reg1, reg2,i
unsigned int part3_length = part2_start + gr->part2_3_length
unsigned used
int h,*f=&freqline[0][0]
if(gr->window_switching_flag &&
gr->block_type == 2)
{
/* short block regions */
reg1 = 36
reg2 = 576
}
else
{
/* long block regions */
reg1 = sfBandIndex[fr_ps.header->sampling_frequency].l[gr->region0_count + 1]
reg2 = sfBandIndex[fr_ps.header->sampling_frequency].l[gr->region0_count + gr->region1_count + 2]
}
標簽:
III_hufman_decode
int
freqline
Granule
上傳時間:
2013-12-19
上傳用戶:jjj0202
-
Newton-Raphson算法 介紹
在科學計算和財經工程領域,許多數值算法都是通用的(至少在理論上是),可廣泛地用于解決一類問題。一個大家熟悉的例子就是Newton-Raphson例程,它可用來尋找方程 f(x)=0的數值解。標準的數學表達式f(x)表示f是變量x的函數,其通常的表達形式為f(x,a,b,...)=0,f被定義為多于一個變量的函數。在這種情況下,Newton-Raphson算法試圖把x以外的變量固定并作為參數,而尋找關于變量x的數值解。
由于Newton-Raphson算法需要知道被求解函數的確切表達,其傳統實現方法是直接將代碼嵌入到客戶應用程序中。這就使得算法的實現代碼經過針對不同被求解函數的少量修改后在客戶程序中反復出現。
同許多其它數學例程一樣,Newton-Raphson算法的具體實現是應該與特定用戶無關的。并且,重復編碼在任何情況下都應該盡量避免。我們很自然地會想到把該類例程作為庫函數來實現,以使客戶程序可以直接調用它們。但是,這種實現方式必然會涉及到如何將用戶自定義函數(Newton-Raphson 例程需要調用該函數)封裝成可以作為參數傳遞的形式。
標簽:
Newton-Raphson
算法
工程領域
計算
上傳時間:
2016-07-31
上傳用戶:gdgzhym
-
編寫具有如下函數原型的遞歸與非遞歸兩種函數equ,負責判斷數組a與b的前n個元素值是否按下標對應完全相同,是則返回true,否則返回false。并編制主函數對它們進行調用,以驗證其正確性。
bool equ(int a[], int b[], int n)
提示:遞歸函數中可按如下方式來分解并處理問題,先判斷最后一個元素是否相同,不同則返false;相同則看n是否等于1,是則返回true,否則進行遞歸調用(傳去實參a、b與 n-1,去判斷前n-1個元素的相等性),并返回遞歸調用的結果(與前n-1個元素的是否相等性相同)。
標簽:
equ
函數
遞歸
編寫
上傳時間:
2014-01-18
上傳用戶:love1314
-
實驗源代碼
//Warshall.cpp #include<stdio.h> void warshall(int k,int n) { int i , j, t; int temp[20][20]; for(int a=0;a<k;a++) { printf("請輸入矩陣第%d 行元素:",a); for(int b=0;b<n;b++) { scanf ("%d",&temp[a][b]); } } for(i=0;i<k;i++){ for( j=0;j<k;j++){ if(temp[ j][i]==1) { for(t=0;t<n;t++) { temp[ j][t]=temp[i][t]||temp[ j][t]; } } } } printf("可傳遞閉包關系矩陣是:\n"); for(i=0;i<k;i++) { for( j=0;j<n;j++) { printf("%d", temp[i][ j]); } printf("\n"); } } void main() { printf("利用 Warshall 算法求二元關系的可傳遞閉包\n"); void warshall(int,int); int k , n; printf("請輸入矩陣的行數 i: "); scanf("%d",&k);
四川大學實驗報告 printf("請輸入矩陣的列數 j: "); scanf("%d",&n); warshall(k,n); }
標簽:
warshall
離散
實驗
上傳時間:
2016-06-27
上傳用戶:梁雪文以
-
#include "iostream" using namespace std;
class Matrix
{
private:
double** A; //矩陣A
double *b; //向量b
public:
int size;
Matrix(int );
~Matrix();
friend double* Dooli(Matrix& );
void Input();
void Disp();
};
Matrix::Matrix(int x) {
size=x;
//為向量b分配空間并初始化為0
b=new double [x];
for(int j=0;j<x;j++)
b[j]=0;
//為向量A分配空間并初始化為0
A=new double* [x];
for(int i=0;i<x;i++)
A[i]=new double [x];
for(int m=0;m<x;m++)
for(int n=0;n<x;n++)
A[m][n]=0;
}
Matrix::~Matrix() {
cout<<"正在析構中~~~~"<<endl;
delete b;
for(int i=0;i<size;i++)
delete A[i];
delete A;
}
void Matrix::Disp()
{
for(int i=0;i<size;i++)
{
for(int j=0;j<size;j++)
cout<<A[i][j]<<" ";
cout<<endl;
}
}
void Matrix::Input()
{
cout<<"請輸入A:"<<endl;
for(int i=0;i<size;i++)
for(int j=0;j<size;j++){
cout<<"第"<<i+1<<"行"<<"第"<<j+1<<"列:"<<endl;
cin>>A[i][j];
}
cout<<"請輸入b:"<<endl;
for(int j=0;j<size;j++){
cout<<"第"<<j+1<<"個:"<<endl;
cin>>b[j];
}
}
double* Dooli(Matrix& A) {
double *Xn=new double [A.size];
Matrix L(A.size),U(A.size);
//分別求得U,L的第一行與第一列
for(int i=0;i<A.size;i++)
U.A[0][i]=A.A[0][i];
for(int j=1;j<A.size;j++)
L.A[j][0]=A.A[j][0]/U.A[0][0];
//分別求得U,L的第r行,第r列
double temp1=0,temp2=0;
for(int r=1;r<A.size;r++){
//U
for(int i=r;i<A.size;i++){
for(int k=0;k<r-1;k++)
temp1=temp1+L.A[r][k]*U.A[k][i];
U.A[r][i]=A.A[r][i]-temp1;
}
//L
for(int i=r+1;i<A.size;i++){
for(int k=0;k<r-1;k++)
temp2=temp2+L.A[i][k]*U.A[k][r];
L.A[i][r]=(A.A[i][r]-temp2)/U.A[r][r];
}
}
cout<<"計算U得:"<<endl;
U.Disp();
cout<<"計算L的:"<<endl;
L.Disp();
double *Y=new double [A.size];
Y[0]=A.b[0];
for(int i=1;i<A.size;i++ ){
double temp3=0;
for(int k=0;k<i-1;k++)
temp3=temp3+L.A[i][k]*Y[k];
Y[i]=A.b[i]-temp3;
}
Xn[A.size-1]=Y[A.size-1]/U.A[A.size-1][A.size-1];
for(int i=A.size-1;i>=0;i--){
double temp4=0;
for(int k=i+1;k<A.size;k++)
temp4=temp4+U.A[i][k]*Xn[k];
Xn[i]=(Y[i]-temp4)/U.A[i][i];
}
return Xn;
}
int main()
{
Matrix B(4);
B.Input();
double *X;
X=Dooli(B);
cout<<"~~~~解得:"<<endl;
for(int i=0;i<B.size;i++)
cout<<"X["<<i<<"]:"<<X[i]<<" ";
cout<<endl<<"呵呵呵呵呵";
return 0;
}
標簽:
道理特分解法
上傳時間:
2018-05-20
上傳用戶:Aa123456789
-
#include<stdio.h>
#include<windows.h>
int xuanxiang;
int studentcount;
int banjihao[100];
int xueqihao[100][10];
char xm[100][100];
int xuehao[100][10];
int score[100][3];
int yuwen;
int shuxue[000];
int yingyu[100];
int c[100];
int p;
char x[1000][100]="",y[100][100]="";/*x學院 y專業 z班級*/
int z[100];
main()
{
void input();
void inputsc();
void alter();
void scbybannji();
printf("--------學生成績管理-----\n");
printf("請按相應數字鍵來實現相應功能\n");
printf("1.錄入學生信息 2.錄入學生成績 3.修改學生成績\n");
printf("4.查詢學生成績 5.不及格科目及名單 6.按班級輸出學生成績單\n");
printf("請輸入你要實現的功能所對應的數字:");
scanf("%d",&xuanxiang);
system("cls");
getchar();
switch (xuanxiang)
{
case 1:input();
case 2:inputsc();
case 3:alter();
/*case 4:select score();
case 5:bujigekemujimingdan();*/
case 6:scbybanji;
}
}
void input()
{
int i;
printf("請輸入你的學院名稱:");
gets(x);
printf("請輸入你的專業名稱:");
gets(y);
printf("請輸入你的班級號:");
scanf("%d",&z);
printf("請輸入你們一個班有幾個人:");
scanf("%d",&p);
system("cls");
for(i=0;i<p;i++)
{
printf("請輸入第%d個學生的學號:",i+1);
scanf("%d",xuehao[i]);
getchar();
printf("請輸入第%d個學生的姓名:",i+1);
gets(xm[i]);
system("cls");
}
printf("您已經錄入完畢您的班級所有學生的信息!\n");
printf("您的班級為%s%s%s\n",x,y,z);
/*alter(p);*/
}
void inputsc()
{
int i;
for(i=0;i<p;i++)
{
printf("\n");
printf("--------------------------------------------------------------------------------\n\n");
printf("\t\t\t\t錄入學生的成績\n\n\n");
printf("--------------------------------------------------------------------------------\n\n");
printf("\t\t\t\t%s\n",xm[i]);
printf("\n");
printf("\t\t\t\t數學:");
scanf("%d",&shuxue[i]);
printf("\n");
getchar();
printf("\t\t\t\t英語:");
scanf("%d",&yingyu[i]);
printf("\n");
getchar();
printf("\t\t\t\tc語言:");
scanf("%d",&c[i]);
system("cls");
}
}
void alter()
{
int i;/*循環變量*/
int m[10000];/*要查詢的學號*/
int b;/*修改后的成績*/
char kemu[20]="";
printf("請輸入你要修改的學生的學號");
scanf("%d",&m);
for (i=0;i<p;i++)
{
if (m==xuehao[i])
{
printf("%s的數學成績為%d,英語成績為%d,c語言成績為%d,xm[i],shuxue[i],yingyu[i],c[i]");
printf("請輸入你想修改的科目");}
}
gets(kemu);
getchar();
if (kemu=="數學");
{
scanf("%d",&b);
shuxue[i]=b;}
if (kemu=="英語");
{
scanf("%d",&b);
yingyu[i]=b;}
if (kemu=="c語言");
{
scanf("%d",&b);
c[i]=b;
}
printf("%s的數學成績為%d,英語成績為%d,c語言成績為%d,xm[i],shuxue[i],yingyu[i],c[i]");
}
void scbybannji()
{
int i;
char zyname[20];
int bjnumber;
printf("請輸入你的專業名稱");
scanf("%s",&zyname);
printf("請輸入你的班級號");
scanf("%d",&bjnumber);
for (i=0;i<p;i++)
{
if (zyname==y[i]);
if (bjnumber==z[i]);
printf("專業名稱%s班級號%d數學成績%d英語成績%dc語言成績%d,y[i],z[i],shuxue[i],yingyu[i],c[i]");
}
}
標簽:
c語言
上傳時間:
2018-06-08
上傳用戶:2369043090
-
特點: 精確度0.1%滿刻度 可作各式數學演算式功能如:A+B/A-B/AxB/A/B/A&B(Hi or Lo)/|A|/ 16 BIT類比輸出功能 輸入與輸出絕緣耐壓2仟伏特/1分鐘(input/output/power) 寬范圍交直流兩用電源設計 尺寸小,穩定性高
標簽:
微電腦
數學演算
隔離傳送器
上傳時間:
2014-12-23
上傳用戶:ydd3625