zoukankan      html  css  js  c++  java
  • 2018年第九届蓝桥杯C/C++ A组国赛 —— 第二题:阅兵方阵

    标题:阅兵方阵

    x国要参加同盟阅兵活动。
    主办方要求每个加盟国派出的士兵恰好能组成 2 个方阵。
    x国发现弱小的 y国派出了130人的队伍,他们的士兵在行进中可以变换2种队形:
    130 = 81 + 49 = 92 + 72
    130 = 121 + 9 = 112 + 32

    x国君很受刺激,觉得x国面积是y国的6倍,理应变出更多队形。
    于是他发号施令:
    我们要派出一支队伍,在行进中要变出 12 种队形!!!

    手下人可惨了,要忙着计算至少多少人才能组成 12 种不同的双方阵。
    请你利用计算机的优势来计算一下,至少需要多少士兵。

    (ps: 不要失去信心,1105人就能组成4种队形了)

    注意,需要提交的是一个整数,表示至少需要士兵数目,不要填写任何多余的内容。

    Code

    /*
                                    ^....0
                                   ^ .1 ^1^
                                   ..     01
                                  1.^     1.0
                                 ^ 1  ^    ^0.1
                                 1 ^        ^..^
                                 0.           ^ 0^
                                 .0            1 .^
                                 .1             ^0 .........001^
                                 .1               1. .111100....01^
                                 00                 11^        ^1. .1^
                                 1.^                              ^0  0^
                                   .^                                 ^0..1
                                   .1                                   1..^
                                 1 .0                                     ^  ^
                                  00.                                     ^^0.^
                                  ^ 0                                     ^^110.^
                              0   0 ^                                     ^^^10.01
                       ^^     10  1 1                                      ^^^1110.1
                       01     10  1.1                                      ^^^1111110
                       010    01  ^^                                        ^^^1111^1.^           ^^^
                       10  10^ 0^ 1                                            ^^111^^^0.1^       1....^
                        11     0                                               ^^11^^^ 0..  ....1^   ^ ^
                        1.     0^                                               ^11^^^ ^ 1 111^     ^ 0.
                       10   00 11                                               ^^^^^   1 0           1.
                       0^  ^0  ^0                                                ^^^^    0            0.
                       0^  1.0  .^                                               ^^^^    1 1          .0
                       ^.^  ^^  0^                             ^1                ^^^^     0.         ^.1
                       1 ^      11                             1.                ^^^     ^ ^        ..^
                      ^..^      ^1                             ^.^               ^^^       .0       ^.0
                      0..^      ^0                              01               ^^^       ..      0..^
                     1 ..        .1                             ^.^              ^^^       1 ^  ^0001
                    ^  1.        00                              0.             ^^^        ^.0 ^.1
                    . 0^.        ^.^                             ^.^            ^^^         ..0.0
                   1 .^^.         .^                  1001        ^^            ^^^         . 1^
                   . ^ ^.         11                0.    1         ^           ^^          0.
                    0  ^.          0              ^0       1                   ^^^          0.
                  0.^  1.          0^             0       .1                   ^^^          ..
                  .1   1.          00            .        .1                  ^^^           ..
                 1      1.         ^.           0         .^                  ^^            ..
                 0.     1.          .^          .         0                                  .
                 .1     1.          01          .        .                                 ^ 0
                ^.^     00          ^0          1.       ^                                 1 1
                .0      00           .            ^^^^^^                                   .
                .^      00           01                                                    ..
               1.       00           10                                                   1 ^
              ^.1       00           ^.                                            ^^^    .1
              ..        00            .1                                        1..01    ..
             1.1         00           1.                                       ..^      10
            ^ 1^         00           ^.1                                      0 1      1
            .1           00            00                                       ^  1   ^
             .           00            ^.^                                        10^  ^^
           1.1           00             00                                              10^
           ..^           1.             ^.                                               1.
          0 1            ^.              00                 00                            .^
            ^            ^.              ^ 1                00   ^0000^     ^               01
         1 0             ^.               00.0^              ^00000   1.00.1              11
         . 1              0               1^^0.01                      ^^^                01
          .^              ^                1   1^^                                       ^.^
        1 1                                                                              0.
        ..                                                                              1 ^
         1                                                                               1
       ^ ^                                                                             .0
       1                                                                             ^ 1
       ..                                                          1.1            ^0.0
      ^ 0                                                           1..01^^100000..0^
      1 1                                                            ^ 1 ^^1111^ ^^
      0 ^                                                             ^ 1      1000^
      .1                                                               ^.^     .   00
      ..                                                                1.1    0.   0
      1.                                                                  .    1.   .^
      1.                                                                 1    1.   ^0
     ^ .                                                                 ^.1 00    01
     ^.0                                                                  001.     .^
     */
    // VB_king —— 2018_Finals_A_C++_2.cpp created by VB_KoKing on 2019-05-18:14.
    /* Procedural objectives:
    
     Variables required by the program:
    
     Procedural thinking:
     2种方阵,4个平方数,相加等于总人数的两倍
     12种方阵,24个平方数,相加等于总人数的十二倍
     Functions required by the program:
    
     Determination algorithm:
    
     Determining data structure:
    
    
    */
    /* My dear Max said:
    "I like you,
    So the first bunch of sunshine I saw in the morning is you,
    The first gentle breeze that passed through my ear is you,
    The first star I see is also you.
    The world I see is all your shadow."
    
    FIGHTING FOR OUR FUTURE!!!
    */
    #include <algorithm>
    #include <iostream>
    #include <cstring>
    #include <cmath>
    
    using namespace std;
    
    int num[2000000], minn = 10000000;
    
    int main() {
        memset(num, 0, sizeof(num));
        for (int i = 1; i < 1000; i++) {
            for (int j = i; j < 1000; j++) {
                int temp = i * i + j * j;
                num[temp]++;
                if (num[temp] > 11)
                    minn = min(minn, temp);
            }
        }
        cout << minn << endl;
        for (int i = 1; minn > 2 * i * i; i++) {
            int temp = (int) sqrt(minn - i * i);
            if (temp * temp == minn - i * i) {
                cout << temp << '*' << temp << '+' << i << '*' << i << '=' << minn << endl;
            }
        }
        return 0;
    }
    
  • 相关阅读:
    当梦想渐行渐远的时候
    android开发系列之aidl
    看到这页代码,我要疯了
    android开发系列之性能优化
    近期的一个项目反思与总结
    IOS中摇一摇实现截屏(可实现问题反馈的功能)
    IOS设计模式浅析之外观模式(Facade)
    IOS项目开发中的文件和文件夹操作
    XCode 4.6下XIB文件提示“...could not be opened..."的问题
    "Xcode"意外退出
  • 原文地址:https://www.cnblogs.com/AlexKing007/p/12338292.html
Copyright © 2011-2022 走看看