algorithm light more light - andstudy/forge GitHub Wiki
λ¬Έμ 보기 7μ₯ Summit Pages
-
μ΅μ΄ νμ΄λ 10μ€ μ λ, μλ λ μ΄λ κ² μ¬μ΄ λ¬Έμ κ°? λΌκ³ μκ°
-
μ μΆ ν΄λ³΄λ μκ° μ΄κ³Ό
-
ν~ κ°λ¨ν μ΅μ ν
-
κ·Έλλ μκ° μ΄κ³Ό
-
μ΄μꡬ리? μ΄μ¬ν μ΅μ ν, μ΅μ΄κ΅¬νμ λΉν΄ 9λ°° μ λμ μ±λ₯
-
κ·Έλλ μκ° μ΄κ³Ό, μμꡬ리
-
λ°λμ κ° μ½μ§
-
λ§μΉ¨λ΄ κΉ¨λ«κ² λλ€. νμ¬ μνλ‘λ μ΄ λ¬Έμ λ₯Ό νμ§ λͺ»νλ€.
-
μ½λ‘¬λ²μ€μ λ¬κ±μ΄ νμνλ€.
-
ν΄λ΅μ μ΄μ²κ΅¬λ μμ μ λλ‘ κ°λ¨νμ§ μμκΉ?
-
λ§μμ λΉμ°κ³ λ§₯λ°μ λ¬κ±μ΄λ λ¨ΉμΌλ©΄μ μκ°ν΄λ³΄μ.
Public Class Light Function GetLastBulbStatus(ByVal bulbCount As UInteger) As Boolean Dim count As UInteger = 1 ' 첫λ²μ§Έ λ°λ³΅μμ 무쑰건 μΌμ§κΈ° λλ¬Έ Dim loopLimit As UInteger = bulbCount \ 2 ' μ§μ μ²λ¦¬ While (bulbCount And 1) = 0 bulbCount >>= 1 count += 1 loopLimit >>= 1 End While Dim n As UInteger = 3 While n <= loopLimit If (bulbCount Mod n) = 0 Then bulbCount \= n count += 1 loopLimit = bulbCount Else n += 2 End If End While If count = 1 Then count += 1 ' count κ° μ¬μ ν 1μ΄λ©΄ μμ μ΄ μμλΌλ μλ―Έ Return ((count And 1) = 1) End Function End Class
- μ΄μ²κ΅¬λ μμμ λλ‘ κ°λ¨ :D
- λ¬Έμ μ μμ μ μ κ³±μμΈμ§λ₯Ό 묻λ κ².
#include <stdio.h>
#include <math.h>
#define ever (;;)
int main()
{
unsigned int n,t;
for ever
{
scanf("%u", &n);
if( n == 0 ) break;
t = (unsigned int)sqrt((double)n);
printf("%s\n", (t*t == n)?"yes":"no");
}
return 0;
}
- μ λ΅μΌ λ―νλ, never solved λ¬Έμ λΌμ νμΈν΄ λ³΄μ§ λͺ»ν¨.(wrong answer λ‘ λμ΄)
-
μ λ ₯ λ²μκ° 2^32-1 κΉμ§ μ λλ€. intνμλ²μλ₯Ό λμ΄μ Wrong answer λμ€λ κ²λλ€. [Mastojun]
/* @JUDGE_ID:parkpd 110401 Cpp "test" */ /* @BEGIN_OF_SOURCE_CODE */ #include <iostream> #include <vector> #include <set> #include <deque> #include <list> #include <stack> #include <string> #include <algorithm> #include <map> #include <limits> #include <assert.h> #include <iomanip> #include <complex> #include <math.h> //#define _UNIT_TEST #ifdef _UNIT_TEST #include <Windows.h> #include "../UnitTest++/src/UnitTest++.h" #endif using namespace std; #ifdef max #undef max #endif #ifdef min #undef min #endif // Minimum Spanning Tree -> Prim Algorithm μ μκ°νλ©° νμμ. namespace ATUtil { bool IsInRange(int value, int from, int to) { return (from <= value) && (value <= to); } int ConvertToIndex(char c) { if ('a' <= c && c <= 'z') { return c - 'a'; } else { return -1; } } char ConvertToChar(int i) { return (char)i + 'a'; } #ifdef _UNIT_TEST class CStopWatch { public: CStopWatch() { m_StartTick = GetTickCount(); // gcc μμ μ λ μ μμΌλκΉ } ~CStopWatch() { cout << "Time passed : " << GetTickCount() - m_StartTick << " milisec.\n"; } int m_StartTick; }; #endif typedef map<int, int> IntDB; typedef vector<int> Ints; typedef list<int> IntList; }; using namespace ATUtil; #ifdef _UNIT_TEST int main() { UnitTest::RunAllTests(); char temp; cin >> temp; return 0; } #endif // code implement namespace ATCode { /////////////////////////////////////////////////////////////// // CSolver class CSolver { public: int GetDivisorNum(int num) { if (num == 1) { return 1; } int divisor = 2; // 1 κ³Ό μκΈ° μμ . int s = num; for (int i = 2; i < s; ++i) { int remain = num % i; if (0 == remain) { s = num / i; if (i == s) // 1, 2, 4 μ 2μ κ°μ κ²½μ°λ ν λ²λ§ λνλ€. { divisor++; } else { divisor += 2; } } } return divisor; } bool Input(int index) { // μ΅μ ν //if (0 == GetDivisorNum(index) % 2) //{ // return false; //} //else //{ // return true; //} int s = (int)sqrt((double)index); if (index == s * s) { return true; } else { return false; } } }; /////////////////////////////////////////////////////////////// // CConsole class CConsole { public: static void ConsoleTest(istream& input, ostream& output); }; void CConsole::ConsoleTest(istream& input, ostream& output) { CSolver s; int index; while (input >> index) { if (0 == index) { break; } if (s.Input(index)) { output << "yes" << '\n'; } else { output << "no" << '\n'; } } }; } using namespace ATCode; #ifndef _UNIT_TEST int main() { CConsole::ConsoleTest(cin, cout); return 0; } #else // tests struct FixtureBase { FixtureBase() { } int x, y; stringstream input; stringstream output; }; TEST_FIXTURE(FixtureBase, GetDivisorNum) { CSolver g; int tests[] = { 1, 1, 2, 2, 3, 2, 4, 3, 5, 2, 6, 4, 7, 2, 8, 4, 9, 3, 10, 4, 11, 2, 12, 6, 13, 2, 14, 4 }; for (int i = 0; i < sizeof(tests) / sizeof(int); i += 2) { cout << tests[i] << '\n'; CHECK_EQUAL(tests[i + 1], g.GetDivisorNum(tests[i])); } } TEST_FIXTURE(FixtureBase, Input) { CSolver g; int tests[] = { 3, 0, 6241, 1, 8191, 0, 9, 1, 14, 0 }; for (int i = 0; i < sizeof(tests) / sizeof(int); i += 2) { //cout << i / 2 << '\n'; CHECK_EQUAL(tests[i + 1], g.Input(tests[i]) ? 1 : 0); } } TEST_FIXTURE(FixtureBase, ConsoleTest) { input << "3\n" "6241\n" "8191\n" "0\n" ; CConsole::ConsoleTest(input, output); CHECK_EQUAL( "no\n" "yes\n" "no\n", output.str()); } #endif /* @END_OF_SOURCE_CODE */
-