關(guān)于制造回文 描述 回文,亦稱(chēng)回環(huán),是正讀反讀都能讀通的句子,亦有將文字排列成圓圈者,是一種修辭方式和文字游戲。回文運(yùn)用得當(dāng),可以表現(xiàn)兩種事物或現(xiàn)象相互依靠或排斥的關(guān)系。總有人以為回文是英文的專(zhuān)利,其實(shí)不然,中文中也有很多回文的例子,譬如: 鶯啼岸柳弄春晴, 柳弄春晴夜月明。 明月夜晴春弄柳, 晴春弄柳岸啼鶯。 看著很有意思,可要想寫(xiě)出回文,并不是一件很容易的事情。如果有一個(gè)字符串,怎樣才能插入最少的內(nèi)容,把它變成回文呢? 例如,要想把字符串 "Zb3bd" 變成回文,就需要插入兩個(gè)字符,變成 "dZb3bZd" 或者 "Zdb3bdZ",插入一個(gè)字符,是肯定不行的。 輸入 輸入的第一行是字符串的長(zhǎng)度 N,3 <= N <= 5000,第二行是一個(gè)長(zhǎng)度為 N 的字符串。該字符串由英文大小寫(xiě)字母和數(shù)字組成,英文大寫(xiě)字母和小寫(xiě)字母是不同的。 輸出 程序輸出要把該字符串變成回文,需要插入的最少字符數(shù)。
標(biāo)簽: 制造
上傳時(shí)間: 2014-01-24
上傳用戶:gundamwzc
RSA ( Rivest Shamir Adleman )is crypthograph system that used to give a secret information and digital signature . Its security based on Integer Factorization Problem (IFP). RSA uses an asymetric key. RSA was created by Rivest, Shamir, and Adleman in 1977. Every user have a pair of key, public key and private key. Public key (e) . You may choose any number for e with these requirements, 1< e <Æ (n), where Æ (n)= (p-1) (q-1) ( p and q are first-rate), gcd (e,Æ (n))=1 (gcd= greatest common divisor). Private key (d). d=(1/e) mod(Æ (n)) Encyption (C) . C=Mª mod(n), a = e (public key), n=pq Descryption (D) . D=C° mod(n), o = d (private key
標(biāo)簽: crypthograph information Adleman Rivest
上傳時(shí)間: 2017-09-01
上傳用戶:chfanjiang
本程序引入了連通性狀態(tài)壓縮動(dòng)態(tài)規(guī)劃方法,可以在非常快的時(shí)間內(nèi)解決棋盤(pán)上的哈密頓回路個(gè)數(shù)的計(jì)數(shù)。 時(shí)間復(fù)雜度O(n*m*3^n)遠(yuǎn)低于搜索。
標(biāo)簽: 程序 狀態(tài) 動(dòng)態(tài)規(guī)劃 連通性
上傳時(shí)間: 2014-01-19
上傳用戶:refent
Use the fast Fourier transform function fft to analyse following signal. Plot the original signal, and the magnitude of its spectrum linearly and logarithmically. Apply Hamming window to reduce the leakage. . The hamming window can be coded in Matlab as for n=1:N hamming(n)=0.54+0.46*cos((2*n-N+1)*pi/N); end; where N is the data length in the FFT.
標(biāo)簽: matlab fft
上傳時(shí)間: 2015-11-23
上傳用戶:石灰?guī)r123
實(shí)驗(yàn)源代碼 //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("請(qǐng)輸入矩陣第%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("可傳遞閉包關(guān)系矩陣是:\n"); for(i=0;i<k;i++) { for( j=0;j<n;j++) { printf("%d", temp[i][ j]); } printf("\n"); } } void main() { printf("利用 Warshall 算法求二元關(guān)系的可傳遞閉包\n"); void warshall(int,int); int k , n; printf("請(qǐng)輸入矩陣的行數(shù) i: "); scanf("%d",&k); 四川大學(xué)實(shí)驗(yàn)報(bào)告 printf("請(qǐng)輸入矩陣的列數(shù) j: "); scanf("%d",&n); warshall(k,n); }
標(biāo)簽: warshall 離散 實(shí)驗(yàn)
上傳時(shí)間: 2016-06-27
上傳用戶:梁雪文以
“Huffman-樹(shù)”不僅能對(duì)文本數(shù)據(jù)進(jìn)行編碼、譯碼,提高文本數(shù)據(jù)的傳輸效率,同時(shí)它也能對(duì)多媒體數(shù)據(jù)(如:數(shù)字圖像、視頻等)進(jìn)行編碼、譯碼,從而實(shí)現(xiàn)多媒體數(shù)據(jù)的壓縮存儲(chǔ)。目前,在Web互聯(lián)網(wǎng)上廣泛使用的JPEG圖像格式就采用了Huffman編碼,與其他圖像格式(如:BMP、TIF等)相比,同一副圖像采用JPEG格式時(shí)所需的存儲(chǔ)空間是最少的。在這個(gè)實(shí)驗(yàn)中,請(qǐng)?jiān)O(shè)計(jì)一個(gè)Huffman編/譯碼器,并模擬數(shù)字圖像的壓縮存儲(chǔ)(編碼)和解碼顯示(譯碼)的過(guò)程。 (1)構(gòu)造“Huffman-樹(shù)”: ①讀入一個(gè)大小為N*M(N為圖像的高度,M為圖像的寬度)的灰度圖像塊,該圖像中的每個(gè)像素(元素)的取值范圍是0~255,取值為0表示該像素是“黑色”,取值為255表示該像素是“白色”,其他取值表示介于“黑色”和“白色”之間的灰度值。 ②統(tǒng)計(jì)讀入圖像塊中每種灰度值出現(xiàn)的次數(shù),并去除出現(xiàn)次數(shù)為零的灰度值,以此作為構(gòu)造“Huffman-樹(shù)”所需的權(quán)值。 ③說(shuō)明:在構(gòu)造“Huffman-樹(shù)”的過(guò)程中,當(dāng)有多個(gè)待合并元素的權(quán)值相同時(shí),每次選擇灰度值較小的兩個(gè)元素進(jìn)行合并。 (2)Huffman編碼(壓縮存儲(chǔ)):讀入新的灰度圖像塊,利用已建立好的“Huffman-樹(shù)”對(duì)其進(jìn)行編碼,將圖像的寬度、高度信息和編碼結(jié)果保存到文件(如:compress_image.txt)中,同時(shí)計(jì)算Huffman編碼的壓縮比并輸出。壓縮比的計(jì)算公式如下:壓縮比=原始圖像所需比特?cái)?shù)/壓縮后圖像所需比特?cái)?shù)。 (3)Huffman譯碼(解碼顯示):讀入壓縮存儲(chǔ)的灰度圖像,利用已建立好的“Huffman-樹(shù)”對(duì)其進(jìn)行譯碼,將譯碼結(jié)果按照原有寬度、高度還原圖像,并將還原之后的圖像保存到文件(如:decoding_image.txt)中。
標(biāo)簽: 樹(shù)
上傳時(shí)間: 2016-12-02
上傳用戶:592595
#include <malloc.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #define NULL 0 #define MaxSize 30 typedef struct athletestruct /*運(yùn)動(dòng)員*/ { char name[20]; int score; /*分?jǐn)?shù)*/ int range; /**/ int item; /*項(xiàng)目*/ }ATH; typedef struct schoolstruct /*學(xué)校*/ { int count; /*編號(hào)*/ int serial; /**/ int menscore; /*男選手分?jǐn)?shù)*/ int womenscore; /*女選手分?jǐn)?shù)*/ 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輸入運(yùn)動(dòng)項(xiàng)目序號(hào) (x<=%d):",ntsp); scanf("%d",pafirst); overgame = *pafirst; if ( pafirst != phead ) { for ( pasecond = phead ; pasecond < pafirst ; pasecond ++ ) { if ( overgame == *pasecond ) { printf("\n這個(gè)項(xiàng)目已經(jīng)存在請(qǐng)選擇其他的數(shù)字\n"); goto Is_Game_DoMain; } } } pafirst = pafirst + 1; if ( overgame > ntsp ) { printf("\n項(xiàng)目不存在"); printf("\n請(qǐng)重新輸入"); 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輸入序號(hào) of the NO.%d (0<x<=%d): ",i,nsc); scanf("%d",&serial); if ( serial > nsc ) { printf("\n超過(guò)學(xué)校數(shù)目,請(qǐng)重新輸入"); 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繼續(xù)輸入運(yùn)動(dòng)項(xiàng)目(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號(hào)學(xué)校的結(jié)果成績(jī):",pfirst->serial); printf("\n\n項(xiàng)目的數(shù)目\t學(xué)校的名字\t分?jǐn)?shù)"); 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按任意建 進(jìn)入下一頁(yè)"); getchar(); pfirst = pfirst->next; } // clrscr(); printf("\n運(yùn)動(dòng)會(huì)結(jié)果:\n\n學(xué)校編號(hào)\t男運(yùn)動(dòng)員成績(jī)\t女運(yùn)動(dòng)員成績(jī)\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按任意建結(jié)束"); 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("文件已經(jīng)成功保存\n"); } void main() { system("cls"); printf("\n\t\t\t 運(yùn)動(dòng)會(huì)分?jǐn)?shù)統(tǒng)計(jì)\n"); printf("輸入學(xué)校數(shù)目 (x>= 5):"); scanf("%d",&nsc); printf("輸入男選手的項(xiàng)目(x<=20):"); scanf("%d",&msp); printf("輸入女選手項(xiàng)目(<=20):"); scanf("%d",&wsp); ntsp = msp + wsp; phead = (int *)calloc(ntsp,sizeof(int)); pafirst = phead; pasecond = phead; input(); calculate(); output(); Save(); }
標(biāo)簽: 源代碼
上傳時(shí)間: 2016-12-28
上傳用戶:150501
#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<<"正在析構(gòu)中~~~~"<<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<<"請(qǐng)輸入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<<"請(qǐng)輸入b:"<<endl; for(int j=0;j<size;j++){ cout<<"第"<<j+1<<"個(gè):"<<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<<"計(jì)算U得:"<<endl; U.Disp(); cout<<"計(jì)算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; }
標(biāo)簽: 道理特分解法
上傳時(shí)間: 2018-05-20
上傳用戶:Aa123456789
module M_GAUSS !高斯列主元消去法模塊 contains subroutine LINEQ(A,B,X,N) !高斯列主元消去法 implicit real*8(A-Z) integer::I,K,N integer::ID_MAX !主元素標(biāo)號(hào) real*8::A(N,N),B(N),X(N) real*8::AUP(N,N),BUP(N) !A,B為增廣矩陣 real*8::AB(N,N+1) real*8::VTEMP1(N+1),VTEMP2(N+1) AB(1:N,1:N)=A AB(:,N+1)=B
標(biāo)簽: fortan Newton 程序 數(shù)值分析 方程 非線性
上傳時(shí)間: 2018-06-15
上傳用戶:answer123
設(shè)有n=2k個(gè)運(yùn)動(dòng)員要進(jìn)行網(wǎng)球循環(huán)賽。現(xiàn)要設(shè)計(jì)一個(gè)滿足以下要求的比賽日程表:⑴每個(gè)選手必須與其他n-1個(gè)選手各賽一次;⑵每個(gè)選手一天只能賽一次;⑶循環(huán)賽一共進(jìn)行n-1天。按此要求可將比賽日程表設(shè)計(jì)-成有n行和n-l列的一個(gè)表。在表中第i行和第j列處填入第i個(gè)選手在第j天所遇到的選手。用分治法編寫(xiě)為該循環(huán)賽設(shè)計(jì)一張比賽日程表的算法并運(yùn)行實(shí)現(xiàn)、對(duì)復(fù)雜度進(jìn)行分析。
標(biāo)簽: 算法 實(shí)驗(yàn)指導(dǎo)書(shū) 設(shè)計(jì)與分析
上傳時(shí)間: 2019-06-04
上傳用戶:594551562
蟲(chóng)蟲(chóng)下載站版權(quán)所有 京ICP備2021023401號(hào)-1