2018年第九届蓝桥杯C/C++ A组国赛 —— 第二题:阅兵方阵
生活随笔
收集整理的這篇文章主要介紹了
2018年第九届蓝桥杯C/C++ A组国赛 —— 第二题:阅兵方阵
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
標(biāo)題:閱兵方陣
x國要參加同盟閱兵活動(dòng)。
主辦方要求每個(gè)加盟國派出的士兵恰好能組成 2 個(gè)方陣。
x國發(fā)現(xiàn)弱小的 y國派出了130人的隊(duì)伍,他們的士兵在行進(jìn)中可以變換2種隊(duì)形:
130 = 81 + 49 = 92 + 72
130 = 121 + 9 = 112 + 32
x國君很受刺激,覺得x國面積是y國的6倍,理應(yīng)變出更多隊(duì)形。
于是他發(fā)號(hào)施令:
我們要派出一支隊(duì)伍,在行進(jìn)中要變出 12 種隊(duì)形!!!
手下人可慘了,要忙著計(jì)算至少多少人才能組成 12 種不同的雙方陣。
請你利用計(jì)算機(jī)的優(yōu)勢來計(jì)算一下,至少需要多少士兵。
(ps: 不要失去信心,1105人就能組成4種隊(duì)形了)
注意,需要提交的是一個(gè)整數(shù),表示至少需要士兵數(shù)目,不要填寫任何多余的內(nèi)容。
Code
/*^....0^ .1 ^1^.. 011.^ 1.0^ 1 ^ ^0.11 ^ ^..^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.101 10 1.1 ^^^1111110010 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. ^.11 ^ 11 1. ^^^ ^ ^ ..^^..^ ^1 ^.^ ^^^ .0 ^.00..^ ^0 01 ^^^ .. 0..^1 .. .1 ^.^ ^^^ 1 ^ ^0001^ 1. 00 0. ^^^ ^.0 ^.1. 0^. ^.^ ^.^ ^^^ ..0.01 .^^. .^ 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^ ^ 011 0 ^. 00.0^ ^00000 1.00.1 11. 1 0 1^^0.01 ^^^ 01.^ ^ 1 1^^ ^.^1 1 0... 1 ^1 1^ ^ .01 ^ 1.. 1.1 ^0.0^ 0 1..01^^100000..0^1 1 ^ 1 ^^1111^ ^^0 ^ ^ 1 1000^.1 ^.^ . 00.. 1.1 0. 01. . 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個(gè)平方數(shù),相加等于總?cè)藬?shù)的兩倍12種方陣,24個(gè)平方數(shù),相加等于總?cè)藬?shù)的十二倍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; }總結(jié)
以上是生活随笔為你收集整理的2018年第九届蓝桥杯C/C++ A组国赛 —— 第二题:阅兵方阵的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 2016年第七届蓝桥杯 - 国赛 - J
- 下一篇: 2018年第九届蓝桥杯C/C++ A组国