Welcome![Sign In][Sign Up]
Location:
Search - h.26

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:

[CommunicationH[1].26L标准论述以及熵编码的研究与分析

Description: H[1].26L标准论述以及熵编码的研究与分析.PDF-H [1] .26 L standard exposition and entropy coding research and analysis. PDF
Platform: | Size: 127146 | Author: 罗生 | Hits:

[Parallel PortH[1].26

Description: H[1].26L视频编码器并行性分析与实现-H [1] .26 L video encoder Parallel Analysis and Implementation
Platform: | Size: 55880 | Author: xsl | Hits:

[File OperateData4final

Description: 移位密码、代换密码的加密及解密 实现移位密码:k表示26个字母向前循环位移的字符个数 加密: 输入:k,以及小写表示的明文字母,输出:大写字母表示的密文 解密:输入: k,以及大写字母表示的密文,输出:小写字母表示的明文 例如,当k=11时 明文:wewillmeetatmidnight 密文:HPHTWWXPPELEXTOYTRSE 实现代换密码 例如输入密匙guangzhouuniversity,则建立字母对应关系: a b c d e f g h i j K l m G U A N Z H O I V E R S T n o p q r s t u v w X y z Y B C D F J K L M P Q W X 字母对应关系的说明:把密匙按照a-z的顺序对应,去掉重复字母,如guangzhouuniversity中的g第二次出现时被滤掉, 在n对应Y之后,把在密匙中没出现过的其他字母按顺序排列:BCDFJ…… -translocation password substitution password encryption and decryption of achieving shift Password : k said 26 letters forward displacement cycle of the number of characters encryption : Admission : k, and explicitly expressed in lowercase letters, output : capital letters said the ciphertext declassified : Admission : k, and the uppercase letters dense text output : lowercase letters explicitly said for example, when k = 11:00 explicit : wewillmeetatmidnight dense text : HPHTWWXPPELEXTOYTRSE achieve import substitution such as password key guangzho uuniversity, the establishment of correspondence between letters : a b c d e f g h i j k l m G U A N Z H O R E V I S T n o p q r s t u v w x y z Y B C D F J K L M P Q W X correspondence between letters Note : In accordance with a key put-z corr
Platform: | Size: 8617 | Author: 何志 | Hits:

[VOIP programH_323_SDK_Lib

Description: ITU-T H.323 V3 音频codec(支持静音检测) g.723.1 6.4kbps发送,6.4/5.3kbps接收 g.729a 8kbps发送,8kbps接收(仅在单一模式下可用) gsm 6.10 10kbps lpc 10 3kbps g.711 uLaw/aLaw 64kbps 视频codec(动态流量控制) h.261 支持QCIF(176*144)/CIF(352*288) h.263 支持QCIF(176*144)/CIF(352*288) -- 需要VISh263m.dll的支持,该动态连接库随VIS H.323 DLL Library一同发布 标准H.323网守(Gatekeeper)支持 ILS(Internet Locator Service)支持 -ITU-T H.323 V3 Audio codec (Support quiet detection) g.723.1 6. 4kbps sending, receiving g.729a 6.4/5.3kbps bps sent, k receiver (only in a single mode available) gsm 6.10 10kbps lpc 10 3kbp 's g.711 uLaw / aLaw 47,060 video codec (dynamic flow control) h.26 a support QCIF (176 * 144) / CIF (352 * 288) h.263 support QCIF (176 * 144) / CIF (352 * 288) -- needs the support VISh263m.dll holders. The dynamic link library DLL with the VIS Library H.323 standard with the release of H.323 Gatekeeper (G atekeeper) support ILS (Internet Locator Service) support holders
Platform: | Size: 827268 | Author: wushuang | Hits:

[VOIP programh263

Description: 视频压缩编解码ITU h.263源代码.经典的视频会议和远程监控算法.- The video frequency compression arranges decodes ITU the h.263 source code Classical video frequency conference and long-distance monitoring algorithm
Platform: | Size: 56320 | Author: 吴大伟 | Hits:

[Streaming Mpeg4h.264

Description: 上下文自适 应二进制算术编码(CABAC),-Context-based Adaptive Binary Arithmetic Coding (CABAC)
Platform: | Size: 184320 | Author: 张一帆 | Hits:

[Multimedia Developh.263编解码软件

Description: h.263编码、解码源代码,及一个小例子程序-H.263 encoder and decoder source code, and a small example of procedures
Platform: | Size: 1506304 | Author: 扬载伦 | Hits:

[OtherH263协议中文版

Description: H.263协议中文版,翻译的不是很好,大家凑活着看吧-H.263 Chinese version of the agreement, the translation is not good, we got very bright and alive
Platform: | Size: 737280 | Author: xlj | Hits:

[Program docH[1].26L标准论述以及熵编码的研究与分析

Description: H[1].26L标准论述以及熵编码的研究与分析.PDF-H [1] .26 L standard exposition and entropy coding research and analysis. PDF
Platform: | Size: 126976 | Author: 罗生 | Hits:

[Parallel PortH[1].26

Description: H[1].26L视频编码器并行性分析与实现-H [1] .26 L video encoder Parallel Analysis and Implementation
Platform: | Size: 55296 | Author: xsl | Hits:

[Compress-Decompress algrithmsH263B

Description: h.263+ vc++商业源代码,具体公司名称保密!-h.263 vc commercial source code, specific company names confidential!
Platform: | Size: 72704 | Author: gao | Hits:

[VOIP programH_323_SDK_Lib

Description: ITU-T H.323 V3 音频codec(支持静音检测) g.723.1 6.4kbps发送,6.4/5.3kbps接收 g.729a 8kbps发送,8kbps接收(仅在单一模式下可用) gsm 6.10 10kbps lpc 10 3kbps g.711 uLaw/aLaw 64kbps 视频codec(动态流量控制) h.261 支持QCIF(176*144)/CIF(352*288) h.263 支持QCIF(176*144)/CIF(352*288) -- 需要VISh263m.dll的支持,该动态连接库随VIS H.323 DLL Library一同发布 标准H.323网守(Gatekeeper)支持 ILS(Internet Locator Service)支持 -ITU-T H.323 V3 Audio codec (Support quiet detection) g.723.1 6. 4kbps sending, receiving g.729a 6.4/5.3kbps bps sent, k receiver (only in a single mode available) gsm 6.10 10kbps lpc 10 3kbp 's g.711 uLaw/aLaw 47,060 video codec (dynamic flow control) h.26 a support QCIF (176* 144)/CIF (352* 288) h.263 support QCIF (176* 144)/CIF (352* 288)-- needs the support VISh263m.dll holders. The dynamic link library DLL with the VIS Library H.323 standard with the release of H.323 Gatekeeper (G atekeeper) support ILS (Internet Locator Service) support holders
Platform: | Size: 827392 | Author: wushuang | Hits:

[Windows Developpccode_2006910125856305

Description: * 提供多达26种图象格式的读写插件,新的插件还在不断地开发当中。 * 支持从EXE、剪贴板、窗口、HBITMAP句柄、内存等多种介质中直接读写图象。 * 拥有极简易的使用方法。引擎常用的接口函数只有4个。 * 提供极易扩展的图象处理接口。开发人员可以很容易的在此接口上挂接自己的图象处理模块。 * 图象插件的安装、卸载、管理等工作均由引擎自己负责,调用者无需干预(全自动)。 * 图象插件及引擎内部拥有完善的异常处理机制,以及专用的内存防护系统,工作稳定可靠。 * 提供非常详尽的全中文开发手册及使用范例,使开发人员可以很快的掌握引擎的使用方法。 * 有专人负责该引擎的持续开发,并有官方网站提供技术支持。 * 全部源代码可以免费查阅。 * 有多种使用许可证可供选择。商业软件和GPL自由软件均可找到对应的使用许可。 压缩包中含有详细的说明文档。希望这个库能对别人有用。
Platform: | Size: 1133568 | Author: 杨秉岐 | Hits:

[ListView/ListBoxgridctrl_demo226

Description: 一个十分强大的表格控件,作者已经升级到了2.26版-A very powerful form of control, the author has been upgraded to version 2.26
Platform: | Size: 304128 | Author: tdf | Hits:

[Compress-Decompress algrithmssjpeg

Description: /* Copyright (C) 2001-2006 artofcode LLC. All Rights Reserved. This file is part of GNU ghostscript GNU ghostscript is free software you can redistribute it and/or modify it under the terms of the version 2 of the GNU General Public License as published by the Free Software Foundation. GNU ghostscript is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with ghostscript see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ /* $Id: sjpeg.h,v 1.6 2007/08/01 14:26:43 jemarch Exp $ */ /* IJG entry point wrappers */ /* Requires sdct.h, jpeg/jpeglib.h */ -/* Copyright (C) 2001-2006 artofcode LLC. All Rights Reserved. This file is part of GNU ghostscript GNU ghostscript is free software you can redistribute it and/or modify it under the terms of the version 2 of the GNU General Public License as published by the Free Software Foundation. GNU ghostscript is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with ghostscript see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ /* $Id: sjpeg.h,v 1.6 2007/08/01 14:26:43 jemarch Exp $ */ /* IJG entry point wrappers */ /* Requires sdct.h, jpeg/jpeglib.h */
Platform: | Size: 1024 | Author: hadmi | Hits:

[Linux-Unixns-2.26-gcc410.patch

Description: ns-2.26的补丁程序,安装ns2.26时可能需要。此程序不太容易从网上找到。-ns-2.26 patches, may need to install ns2.26. This program is not easy to find from the Internet.
Platform: | Size: 6144 | Author: 赵航 | Hits:

[Special EffectsH.26x

Description: H.26x系列算法的研究与实际应用案例 H.26x系列算法的研究与实际应用案例-H. 26 x series algorithm research and application cases
Platform: | Size: 1992704 | Author: DAVE | Hits:

[assembly languageLED

Description: 首先,你用的C18编译器只能编译PIC高端的8位单片机PIC18系列单片机。不建议初学者开始就先学PIC18单片机,建议先学PIC10、PIC12、PIC16系列单片机。如需要编译C文件,可以在Microchip的官网下载HT-PICC for PIC12/16那个。但也不建议初学者开始学就用C编写。如果你不了解单片机内部结构和指令(指令就是汇编),那你永远也没法学懂单片机(不管是否PIC的)。啰嗦的话说完了,现在说一下你的问题。装好以后,先要建立好一个项目,在建立项目的时候需要你指定编译器,则找到Microchip C18 toolsuite,并且确认下面的编译器和连接器的路径都指向MCC18目录下。-Make: The target "D:\equipment\410\MXPR-410\tmp\USERSPC3.o" is out of date.Executing: "C:\Program Files\Microchip\MPLAB C30\bin\pic30-gcc.exe"-mcpu=generic-16bit-x c-c "USERSPC3.C"-o"D:\equipment\410\MXPR-410\tmp\USERSPC3.o"-I"D:\equipment\410\MXPR-410\h"-g-WallIn file included from D:/equipment/410/MXPR-410/h/p33f_device.h:24, from D:/equipment/410/MXPR-410/h/p33f_Tasks.h:15, from USERSPC3.C:14:D:/equipment/410/MXPR-410/h/p33FJ256GP710.h:8:2: error:#error "Include file does not match processor setting"In file included from D:/equipment/410/MXPR-410/h/p33f_device.h:26, from D:/equipment/410/MXPR-410/h/p33f_Tasks.h:15,
Platform: | Size: 10240 | Author: yb | Hits:

[OtherScienceDirect_articles_07Aug2017_19-26-09.063

Description: the paper is very important
Platform: | Size: 660480 | Author: huychampi | Hits:
« 12 3 »

CodeBus www.codebus.net