Welcome![Sign In][Sign Up]
Location:
Search - T.31

Search list

[Other用c编写的N*N的螺旋矩阵源代码

Description:

/*
实现效果:
1 2 6 7 15
3 5 8 14 16
4 9 13 17 22
10 12 18 21 23
11 19 20 24 25
*/
#include <stdio.h>
#define N 5 //阶数,即N*N的螺旋矩阵

void main()
{
    int i, j, num=1, a[N][N];
    for(i=0; i<=N/2; i++)
    {
        for(j=i; j<N-i; j++) a[i][j]=n++;
        for(j=i+1; j<N-i; j++) a[j][N-i-1]=n++;
        for(j=N-i-2; j>i; j--) a[N-i-1][j]=n++;
        for(j=N-i-1; j>i; j--) a[j][i]=n++;
    }
    for(i=0; i<N; i++)
    {
        for(j=0; j<N; j++)
            printf("%2d ",a[i][j]);
        printf("\n");
    }
}
    

 

不知道叫什么,先叫它“回宫图”吧
年初的时候在贴吧瞎逛,看到了一个程序挺有意思,会输出如下的形状:
01 24 23 22 21 20 19
02 25 40 39 38 37 18
03 26 41 48 47 36 17
04 27 42 49 46 35 16
05 28 43 44 45 34 15
06 29 30 31 32 33 14
07 08 09 10 11 12 13
仔细看这个形状,数字是按顺序往里回旋的,觉得很有创意,可是一看源代码头就大了,
每个编程人都知道看别人的代码是很困难的,尤其像这种不知道思路的,所以也就放下
没管了。
昨天上物理课实在是没心思听,就想起这个程序,想了一节课,果然不负有心人,给弄出来了,这个是增强版的,可以输入1-10中的任意个数,然后生成图形。
先看代码,没有注释,所以不好看的懂。
#include<stdio.h>
main()
{
       int n,m,i,j,t,k=1;
       int a[11][11];
       clrscr();
       do{
       printf("please input a number(1-10):");
       scanf("%d",&n);
       }while(n<1||n>10);
       t=n+1;
       for(m=1;m<=t/2;m++)
         {
           for(i=m;i<=t-m;i++)
             {a[i][m]=k;k++;}
           for(j=m+1;j<=t-m;j++)
             {a[i-1][j]=k;k++;}
           for(i=n-m;i>=m;i--)
             {a[i][j-1]=k;k++;}
           for(j=n-m;j>=m+1;j--)
             {a[i+1][j]=k;k++;}
         }
       for(i=1;i<=n;i++)
         {
           for(j=1;j<=n;j++)
             {
               if(a[i][j]<=9) printf("0%d ",a[i][j]);
               else printf("%d ",a[i][j]);       }
           printf("\n");
         }
       getch();
}
就是这样的。


可以更简洁些:

#include<stdio.h>
main()
{
       int n,m,i,j,t,k=1;
       int a[11][11];
       clrscr();
       do{
       printf("please input a number(1-10):");
       scanf("%d",&n);
       }while(n<1||n>10);
       t=n+1;
       for(m=1;m<=t/2;m++)
         {
           for(i=m;i<=t-m;i++)
             a[i][m]=k++;
           for(j=m+1;j<=t-m;j++)
             a[i-1][j]=k++;
           for(i=n-m;i>=m;i--)
             a[i][j-1]=k++;
           for(j=n-m;j>=m+1;j--)
             a[i+1][j]=k++;
         }
       for(i=1;i<=n;i++)
         {
           for(j=1;j<=n;j++)
             {
               if(a[i][j]<=9) printf("0%d ",a[i][j]);
               else printf("%d ",a[i][j]);       }
           printf("\n");
         }
       getch();
}

 


 #include <stdio.h>
#define N 8
main(){
 int i,j,n=1,a[N][N];
 for(i=0;i<=N/2;i++){
  for(j=i;j<N-i;j++)
   a[i][j]=n++;
  for(j=i+1;j<N-i;j++)
   a[j][N-i-1]=n++;
  for(j=N-i-2;j>i;j--)
   a[N-i-1][j]=n++;
  for(j=N-i-1;j>i;j--)
   a[j][i]=n++;
 }
 for(i=0;i<N;i++){
  printf("\n\n");
  for(j=0;j<N;j++)
   printf("%5d",a[i][j]);
 }
}
 

 


                                马踏棋盘问题


#include <stdio.h>
#define N 5
void main(){
 int x,y;
 void horse(int i,int j);
 printf("Please input start position:");
 scanf("%d%d",&x,&y);
 horse(x-1,y-1);
}
void horse(int i,int j){
 int a[N][N]={0},start=0,
  h[]={1,2,2,1,-1,-2,-2,-1},
  v[]={2,1,-1,-2,2,1,-1,-2},
  save[N*N]={0},posnum=0,ti,tj,count=0;
 int jump(int i,int j,int a[N][N]);
 void outplan(int a[N][N]);
 a[i][j]=posnum+1;
 while(posnum>=0){
  ti=i;tj=j;
  for(start=save[posnum];start<8;++start){
   ti+=h[start];tj+=v[start];
   if(jump(ti,tj,a))
    break;
   ti-=h[start];tj-=v[start];
  }
  if(start<8){
   save[posnum]=start;
   a[ti][tj]=++posnum+1;
   i=ti;j=tj;save[posnum]=0;
   if(posnum==N*N-1){
    //outplan(a);
    count++;
   }
  }
  else{
   a[i][j]=0;
   posnum--;
   i-=h[save[posnum>;j-=v[save[posnum>;
   save[posnum]++;
  }
 }
 printf("%5d",count);
}
int jump(int i,int j,int a[N][N]){
 if(i<N&&i>=0&&j<N&&j>=0&&a[i][j]==0)
  return 1;
 return 0;
}
void outplan(int a[N][N]){
 int i,j;
 for(i=0;i<N;i++){
  for(j=0;j<N;j++)
   printf("%3d",a[i][j]);
  printf("\n");
 }
 printf("\n");
 //getchar();
}
用回溯法得到所有的解,但效率较低,只能算出5行5列的

 


Platform: | Size: 4395 | Author: good@588 | Hits:

[Communicationrp-pppoe-3.4.tar

Description: 0. Install the rp-pppoe-software -------------------------------- You should have already done this by the time you re reading this. If not, go back and read README. 1. Set up your Ethernet hardware -------------------------------- First, make sure the Ethernet card you intend to use with the modem is visible to the Linux kernel. Just how to do this is beyond the scope of this document. However, if the card is the only Ethernet card in the system, executing: ifconfig eth0 should display something like this: eth0 Link encap:Ethernet HWaddr 00:60:67:62:31:D4 plust some more lines. Your HWaddr will be different. As long as you see the HWaddr line, your card should be working. DO NOT assign an IP address to the Ethernet card. DO NOT configure the card to come up at boot time.-0. Install the rp - PPPOE-software ------- ------------------------- You should have al ready done this by the time you re reading this. I f not, go back and read README. 1. Set up your Ethernet h ardware -------------------------------- F irst, make sure the Ethernet card you intend to use wit h the modem is visible to the Linux kernel. Just h ow to do this is beyond the scope of this document . However, if the card is the only Ethernet card in the Syste m, executing : ifconfig eth0 should display something like th is : eth0 Link encap : Ethernet HWaddr 00:60:67:62 : 31 : D4 plust some more lines. Your HWaddr will be dif peptide. As long as you see the HWaddr line, your card should be working. DO NOT assign an IP a http://www.hotmail.com/ to the Ethernet card. DO NOT configure th e card t
Platform: | Size: 187791 | Author: chensi | Hits:

[Develop Toolst.31

Description: t.31协议,关于传真数据中的编解码,适合于传真开发-t.31 agreement on the fax data codecs suitable for the development of fax
Platform: | Size: 275349 | Author: daffad | Hits:

[Other resourcejeq

Description: JEQ is class library written in pure Java. It implements the infinite impulse response (IIR) algorithm for bandpass filtering of sound stream. So, it represents a backend code for stereo 10/15/25/31-band equalizer.-JEQ class library is written in pure Java. I t implements the infinite impulse response (II R) algorithm for bandpass filtering of sound st ream. So, it represents a backend code for stereo 10/15/2 5/31-band equalizer.
Platform: | Size: 58740 | Author: 廖广军 | Hits:

[Other resourcers_decoder_31_19_6.tar

Description: Hard-decision decoding scheme Codeword length (n) : 31 symbols. Message length (k) : 19 symbols. Error correction capability (t) : 6 symbols One symbol represents 5 bit. Uses GF(2^5) with primitive polynomial p(x) = X^5 X^2 + 1 Generator polynomial, g(x) = a^15 a^21*X + a^6*X^2 + a^15*X^3 + a^25*X^4 + a^17*X^5 + a^18*X^6 + a^30*X^7 + a^20*X^8 + a^23*X^9 + a^27*X^10 + a^24*X^11 + X^12. Note: a = alpha, primitive element in GF(2^5) and a^i is root of g(x) for i = 19, 20, ..., 30. Uses Verilog description with synthesizable RTL modelling. Consists of 5 main blocks: SC (Syndrome Computation), KES (Key Equation Solver), CSEE (Chien Search and Error Evaluator), Controller and FIFO Register. -Hard-decision decoding scheme Codeword l KV (n) : 31 symbols. Message length (k) : 19 symbols. Error correction capability (t) : 6 symbols One symbol represents five bit. Uses GF (2 ^ 5) with primitive polynomial p (x) = x ^ x ^ 5 2 1 Ge nerator polynomial. g (x) = a ^ a ^ 15 * 21 ^ 6 a X * X ^ a ^ 15 2 * X ^ a ^ 3 25 * X ^ a ^ 4 17 5 * X ^ a ^ 18 ^ 6 X * a * X 30 ^ 7 ^ a ^ 20 * X ^ a ^ 23 8 * X ^ a ^ 9 * 27 X 10 ^ a ^ 24 * 11 ^ X ^ X 12. Note : a = alpha, primitive element in GF (2 ^ 5) and a ^ i is the root of g (x) for i = 19, 20, ..., 30. Uses Verilog description with synthesizab le RTL modeling. Consists of five main blocks : SC (Syndrome Computation), KES (Key Equation Solver). CSEE (Chien Search and Error Evaluator) Controller and FIFO Register.
Platform: | Size: 14247 | Author: 孟轲敏 | Hits:

[CommunicationT.31-199607

Description: ITU T.31-199607协议.pdf
Platform: | Size: 90652 | Author: tegest | Hits:

[Communicationrp-pppoe-3.4.tar

Description: 0. Install the rp-pppoe-software -------------------------------- You should have already done this by the time you re reading this. If not, go back and read README. 1. Set up your Ethernet hardware -------------------------------- First, make sure the Ethernet card you intend to use with the modem is visible to the Linux kernel. Just how to do this is beyond the scope of this document. However, if the card is the only Ethernet card in the system, executing: ifconfig eth0 should display something like this: eth0 Link encap:Ethernet HWaddr 00:60:67:62:31:D4 plust some more lines. Your HWaddr will be different. As long as you see the HWaddr line, your card should be working. DO NOT assign an IP address to the Ethernet card. DO NOT configure the card to come up at boot time.-0. Install the rp- PPPOE-software-------------------------------- You should have al ready done this by the time you re reading this. I f not, go back and read README. 1. Set up your Ethernet h ardware-------------------------------- F irst, make sure the Ethernet card you intend to use wit h the modem is visible to the Linux kernel. Just h ow to do this is beyond the scope of this document . However, if the card is the only Ethernet card in the Syste m, executing : ifconfig eth0 should display something like th is : eth0 Link encap : Ethernet HWaddr 00:60:67:62 : 31 : D4 plust some more lines. Your HWaddr will be dif peptide. As long as you see the HWaddr line, your card should be working. DO NOT assign an IP a http://www.hotmail.com/ to the Ethernet card. DO NOT configure th e card t
Platform: | Size: 187392 | Author: chensi | Hits:

[Bookst.31

Description: t.31协议,关于传真数据中的编解码,适合于传真开发-t.31 agreement on the fax data codecs suitable for the development of fax
Platform: | Size: 275456 | Author: daffad | Hits:

[3D Graphicjeq

Description: JEQ is class library written in pure Java. It implements the infinite impulse response (IIR) algorithm for bandpass filtering of sound stream. So, it represents a backend code for stereo 10/15/25/31-band equalizer.-JEQ class library is written in pure Java. I t implements the infinite impulse response (II R) algorithm for bandpass filtering of sound st ream. So, it represents a backend code for stereo 10/15/2 5/31-band equalizer.
Platform: | Size: 58368 | Author: 廖广军 | Hits:

[VHDL-FPGA-Verilogrs_decoder_31_19_6.tar

Description: Hard-decision decoding scheme Codeword length (n) : 31 symbols. Message length (k) : 19 symbols. Error correction capability (t) : 6 symbols One symbol represents 5 bit. Uses GF(2^5) with primitive polynomial p(x) = X^5 X^2 + 1 Generator polynomial, g(x) = a^15 a^21*X + a^6*X^2 + a^15*X^3 + a^25*X^4 + a^17*X^5 + a^18*X^6 + a^30*X^7 + a^20*X^8 + a^23*X^9 + a^27*X^10 + a^24*X^11 + X^12. Note: a = alpha, primitive element in GF(2^5) and a^i is root of g(x) for i = 19, 20, ..., 30. Uses Verilog description with synthesizable RTL modelling. Consists of 5 main blocks: SC (Syndrome Computation), KES (Key Equation Solver), CSEE (Chien Search and Error Evaluator), Controller and FIFO Register. -Hard-decision decoding scheme Codeword l KV (n) : 31 symbols. Message length (k) : 19 symbols. Error correction capability (t) : 6 symbols One symbol represents five bit. Uses GF (2 ^ 5) with primitive polynomial p (x) = x ^ x ^ 5 2 1 Ge nerator polynomial. g (x) = a ^ a ^ 15* 21 ^ 6 a X* X ^ a ^ 15 2* X ^ a ^ 3 25* X ^ a ^ 4 17 5* X ^ a ^ 18 ^ 6 X* a* X 30 ^ 7 ^ a ^ 20* X ^ a ^ 23 8* X ^ a ^ 9* 27 X 10 ^ a ^ 24* 11 ^ X ^ X 12. Note : a = alpha, primitive element in GF (2 ^ 5) and a ^ i is the root of g (x) for i = 19, 20, ..., 30. Uses Verilog description with synthesizab le RTL modeling. Consists of five main blocks : SC (Syndrome Computation), KES (Key Equation Solver). CSEE (Chien Search and Error Evaluator) Controller and FIFO Register.
Platform: | Size: 14336 | Author: 许茹芸 | Hits:

[Program docT.31-199607

Description: ITU T.31-199607协议.pdf-ITU T.31-199607 agreement. Pdf
Platform: | Size: 90112 | Author: tegest | Hits:

[Linux-Unixxlr54-kernel-2.4.31-m6117d.tar

Description: embedded xlinux kernel
Platform: | Size: 735232 | Author: shaoyun xu | Hits:

[Windows DevelopWhatsMyIP

Description: iphone查看本机IP地址,31天开源工程中的第四个!-Have you ever had any trouble understanding what IP your phone is using? You may working with a friend or family member and typically you would have them use IPConfig or website to return the IP, however it isn t that simple on the iPhone. With What is my IP? you can get an IP with ease. Run the program and you see the IP being used. Please note this only runs on your iPhone, it does not return the correct output in the simulator.
Platform: | Size: 19456 | Author: blueseaineye | Hits:

[Algorithmmatrix

Description: 矩阵运算程序 matrix.h 基于TCL Matrix矩阵类,增加了一些使用的运算函数。具体看源程序。 功能分析: 本程序能完成矩阵的输入、输出。具有相同行数和列数的矩阵间的加法、减法、乘法、除法、求逆、求代数余子式、求伴随矩阵、求行列式值、求条件数等运算。符合矩阵乘法规则要求的矩阵间的乘法。方阵间的除法,方阵的求逆。矩阵的求转置矩阵等功能。 文件 TCL Matrix矩阵类.pdf 中介绍了其详细的使用方法。 -Matrix calculation program matrix.h matrices based on TCL Matrix, an increase of some use of computing functions. By looking specifically at source. Functional Analysis: This program can complete the matrix of input and output. With the same number of rows and columns between the matrix addition, subtraction, multiplication, division, inverse, seeking cofactor, seeking adjoint matrix, determinant of the value of demand, demand conditions, the number of such operations. Comply with rules require matrix multiplication between the matrix multiplication. Matrix between the division, the inverse square. Demand matrix transpose matrix functions. File TCL Matrix matrix class. Pdf introduced its detailed use.
Platform: | Size: 376832 | Author: | Hits:

[Mathimatics-Numerical algorithmstspmatlab

Description: 31个城市的TSP问题,用蚁群算法编写的程序-TSP problem for 31 cities ,ACO program
Platform: | Size: 3072 | Author: liujiao | Hits:

[Delphi VCLTMS-31

Description: TMS Component Pack 3.1 - since TMS did not provide a download link for older versions, it shouldn t be a problem sharing this file here.
Platform: | Size: 2198528 | Author: jucapirama | Hits:

[OtherCube-attack

Description: Cube 攻击的几篇文章,Cube Attack由Itai Dinur 和Adi Shamir于2008年提出。这种攻击并不是全新的,但是它把以前多种启发式攻击的技巧综合起来,仔细分析了攻击未知的、随机的主多项式成功的复杂度和成功概率。-Some papers of Cube attack,Cube attacks work well for random polynomials of small degree. Real-world ciphers, when viewed as polynomials, don t have small degree. Every real-world cipher has about half of the possible monomials of degree 0, about half of the possible monomials of degree 1, about half of the possible monomials of degree 2, about half of the possible monomials of degree 3, ..., about half of the possible monomials of degree 30, about half of the possible monomials of degree 31, about half of the possible monomials of degree 32, ..., about half of the possible monomials of degree 40, ..., about half of the possible monomials of degree 50, etc., continuing far beyond the degrees that cube attacks could possibly reach.
Platform: | Size: 735232 | Author: Yongjuan Wang | Hits:

[matlabshenjingwangluo

Description: T=[1 0 0 1 0 0 1 0 0 0 1 0 0 1 0 0 1 0 0 0 1 0 0 1 0 0 1] 输入向量的最大值和最小值 threshold=[0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1] net=newff(threshold,[31 3],{ tansig , logsig }, trainlm ) 训练次数为1000,训练目标为0.01,学习速率为0.1 net.trainParam.epochs=1000 net.trainParam.goal=0.01 LP.lr=0.1 net = train(net,P,T) 测试数据,和训练数据不一致 P_test=[0.2101 0.0950 0.1298 0.1359 0.2601 0.1001 0.0753 0.0890 0.0389 0.1451 0.0128 0.1590 0.2452 0.0512 0.1319 0.2593 0.1800 0.0711 0.2801 0.1501 0.1298 0.1001 0.1891 0.2531 0.0875 0.0058 0.1803 0.0992 0.0802 0.1002 -T = [1 0 0 1 0 0 1 0 0 0 1 0 0 1 0 0 1 0 0 0 1 0 0 1 0 0 1] ' of the maximum and minimum input vector threshold = [0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1] net = newff (threshold, [31 3], {' tansig' , ' logsig' }, ' trainlm' ) training times for the 1000 target of 0.01 training, learning rate of 0.1 net.trainParam.epochs = 1000 net. trainParam.goal = 0.01 LP.lr = 0.1 net = train (net, P, T) test data, and training data inconsistencies P_test = [0.2101 0.0950 0.1298 0.1359 0.2601 0.1001 0.0753 0.0890 0.0389 0.1451 0.0128 0.1590 0.2452 0.0512 0.1319 0.2593 0.1800 0.0711 0.2801 0.1501 0.1298 0.1001 0.1891 0.2531 0.0875 0.0058 0.1803 0.0992 0.0802 0.1002
Platform: | Size: 1024 | Author: 王飞 | Hits:

[Program docolsr-0.1.0-ns-2.31.tar

Description: vanet protocol ontains pointers to ns code that is maintained by users and that has not been incorporated into the ns distributions. Please contact code authors for details about these modules we don t maintain them and may not have tried them out. -vanet protocol ontains pointers to ns code that is maintained by users and that has not been incorporated into the ns distributions. Please contact code authors for details about these modules we don t maintain them and may not have tried them out.
Platform: | Size: 53248 | Author: mohammad | Hits:

[Applications小菜选择ss 1.31-迷你修改版

Description: autocad用的选择易,试试能不能用,初次上传,不懂怎么写(AutoCAD is easy to choose, try to use it, upload for the first time, don't know how to write)
Platform: | Size: 22528 | Author: qijun0818 | Hits:
« 12 »

CodeBus www.codebus.net