From 45e935f3f8ba7ec52b0b9bba3c0a68cb974f582b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=BC=D0=B8=D1=82=D1=80=D0=B8=D0=B9=20=D0=93=D0=B0?= =?UTF-8?q?=D1=88=D0=BA=D0=BE?= Date: Wed, 13 Mar 2019 18:31:39 +0200 Subject: [PATCH] =?UTF-8?q?Create=200008=20-=20Matches=20-=20=D0=A1=D0=BF?= =?UTF-8?q?=D0=B8=D1=87=D0=BA=D0=B8=20-=20Kibrit=20=C3=A7=C3=B6pl=C9=99ri?= =?UTF-8?q?=20-=20=D0=A1=D1=96=D1=80=D0=BD=D0=B8=D0=BA=D0=B8=20(no=20loops?= =?UTF-8?q?).cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...75\320\270\320\272\320\270 (no loops).cpp" | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 "0000-0999/0008 - Matches - \320\241\320\277\320\270\321\207\320\272\320\270 - Kibrit \303\247\303\266pl\311\231ri - \320\241\321\226\321\200\320\275\320\270\320\272\320\270 (no loops).cpp" diff --git "a/0000-0999/0008 - Matches - \320\241\320\277\320\270\321\207\320\272\320\270 - Kibrit \303\247\303\266pl\311\231ri - \320\241\321\226\321\200\320\275\320\270\320\272\320\270 (no loops).cpp" "b/0000-0999/0008 - Matches - \320\241\320\277\320\270\321\207\320\272\320\270 - Kibrit \303\247\303\266pl\311\231ri - \320\241\321\226\321\200\320\275\320\270\320\272\320\270 (no loops).cpp" new file mode 100644 index 00000000..8d5ba398 --- /dev/null +++ "b/0000-0999/0008 - Matches - \320\241\320\277\320\270\321\207\320\272\320\270 - Kibrit \303\247\303\266pl\311\231ri - \320\241\321\226\321\200\320\275\320\270\320\272\320\270 (no loops).cpp" @@ -0,0 +1,27 @@ +#include +#include + +using namespace std; + +int getMinMatches(int n) { + int a = (int)sqrt(n); + n -= a * a; + + int res = 2 * a * (a + 1); + if (n == 0) return res; + + int ones = (n > a) ? 2 : 1; + res += (n - ones) * 2 + ones * 3; + + return res; +} + +int main() { + int n; + cin >> n; + + cout << getMinMatches(n) << endl; + + system("pause"); + return 0; +}