zoukankan      html  css  js  c++  java
  • 数据结构 —— 阅兵方阵

    今日一言:
    谢谢你,成为我前进的理由。
    ——《言叶之庭》

    数据结构 —— 约瑟夫环


    C语言实现

    /*********************************************************************************
     *
     * 阅兵方阵 (暴力破解) 
     * create: 2020年5月24日 22点56分 
     * author: LOS(小鱼) 
     *
     * *******************************************************************************/
     
    #include<stdio.h>

    void main(){
        int troop[12][2];
        int n = 160000;
        int x,y,count,i;
        for ( ; n < 200000 ; n++ ){
            count = 0;
            for ( x = 1 ; x < 10000 ; x++ ){
                for ( y = 1 ; y < 10000 ; y++ ){
                    if( x*x + y*y == n ){
                        troop[count][0] = x;
                        troop[count][1] = y;
                        count++;
                        if( count == 12 ){
                            for ( i=0 ; i<12; i++ ){
                                printf("第%d支队伍 --> %d^2 + %d^2 = %d + %d = %d ",i+1,
                                troop[i][0],troop[i][1],troop[i][0]*troop[i][0],troop[i][1]*troop[i][1],n);
                            }
                            return;
                        }
                    }
                }
            }
        }

    }

    运行结果

    1支队伍 --> 5^2 + 400^2 = 25 + 160000 = 160025
    2支队伍 --> 125^2 + 380^2 = 15625 + 144400 = 160025
    3支队伍 --> 128^2 + 379^2 = 16384 + 143641 = 160025
    4支队伍 --> 229^2 + 328^2 = 52441 + 107584 = 160025
    5支队伍 --> 236^2 + 323^2 = 55696 + 104329 = 160025
    6支队伍 --> 244^2 + 317^2 = 59536 + 100489 = 160025
    7支队伍 --> 317^2 + 244^2 = 100489 + 59536 = 160025
    8支队伍 --> 323^2 + 236^2 = 104329 + 55696 = 160025
    9支队伍 --> 328^2 + 229^2 = 107584 + 52441 = 160025
    10支队伍 --> 379^2 + 128^2 = 143641 + 16384 = 160025
    11支队伍 --> 380^2 + 125^2 = 144400 + 15625 = 160025
    12支队伍 --> 400^2 + 5^2 = 160000 + 25 = 160025

    --------------------------------
    Process exited after 5.712 seconds with return value 50
    请按任意键继续. . .

  • 相关阅读:
    SqlMap入门
    本地文件上载到Docker容器
    CentOS7 安装Docker-ce
    windows10 子系统(WSL) 文件位置
    慕课网-安卓工程师初养成-5-1 编程练习
    慕课网-安卓工程师初养成-4-14 Java 循环语句之多重循环
    慕课网-安卓工程师初养成-4-13 练习题
    慕课网-安卓工程师初养成-4-12 Java循环跳转语句之 continue
    慕课网-安卓工程师初养成-4-11 Java循环跳转语句之 break
    慕课网-安卓工程师初养成-4-10 练习题
  • 原文地址:https://www.cnblogs.com/rcklos/p/12953468.html
Copyright © 2011-2022 走看看