algorithm light more light - andstudy/forge GitHub Wiki

문제보기 7μž₯ Summit Pages

CynicJJ

  • 졜초 ν’€μ΄λŠ” 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
    

Mastojun

λ¬Έμ œν’€μ΄

  • μ–΄μ²˜κ΅¬λ‹ˆ μ—†μ„μ •λ„λ‘œ 간단 :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;
    }

ParkPD

  • 정닡일 λ“―ν•˜λ‚˜, 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 */
      
⚠️ **GitHub.com Fallback** ⚠️