괴짜 프로그래머의 일상사~@@
프로그래밍, 컴퓨터, 그리고 일상에 관한 소소한 이야기들...
Blog | Guestbook
Keyword | Local | Tag
T 102 / Y 700 / Total 3405160
Catergories
Calendar
«   2023/06   »
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30  
Tag
존 로메로, 손해, vim 7.1, PROCESS_QUERY_LIMITED_INFORMATION, 후지쯔, userinit, 엔진, 모임, PE, 뉴스그룹, 세벌식, 잠언, 헥사 에디터, 추천, 블로그, 출발, 법정, 빗방울처럼 나는 혼자였다., 쓰레드, 리슨,
Archive
Link
Search
  submit
Recent Articles
Recent Comments
Recent Trackbacks
2006/09/18 01:13
GLAT...
양수 n에 대해서 1과 n 사이에 1이 나오는 횟수를 나타내는 함수를 f(n)이라고 한다. 예를 들어 f(13)=6이다. f(n)=n이 되는 첫번째 양수는 1이다. 두번째 양수는 무엇인가.

수학 참고서에나 나올 법한 얘기지만 이 문제는 구글의 입사 지원자들이 통과해야 할 구글 연구소 능력 시험(GLAT) 중 하나다. '최고 괴짜'를 찾아내겠다는 목표로 시작된 프로그램으로 길거리 광고판 등에 문제를 내놓고 이 문제를 푼 사람은 이력서와 함께 정답을 구글로 보내면 된다.

출처: http://news.media.daum.net/economic/finance/200609/17/mk/v14060984.html

[GGGG] 다음에 난 기사를 보다가 살짜쿵 호기심이 생겼다. 구글이라는데 또 발끈해서 문제를 풀어볼라고 낑낑대다가 안돼는 것이었다. 점화식 어쩌고 저쩌고 식 세우다가 나의 초라한 수학적 한계를 실감하고는 컴퓨터에게 물었다. 컴퓨터는 199981이라고 나에게 알려줬으나 정답인지 확인할 길은 없다. 그거 다 헤아리고 있을 수도 없공 ㅋㅋ- 구글에 들어가려면 역시 똑똑해야 하긴 하나 보다. ㅎㅎ- 수학 잘하는 사람이 부러울 때는 정말 이럴때 말고는 ㅎㅎ-~ ^^

아래는 풀어본 소스 코드다. 그냥 재귀로 만드니 스택 오버플로 나는거 같아서 캐쉬를 쓰도록 고쳤다가 생각해보니 그럴 필요도 없을것 같았다. 그래서 변수 하나로 대체한것이 두번째 루프다.

[CPP]#include <stdio.h>
#include <map>

using namespace std;
map<int, int> g_Cache;

int gf(int n)
{  
   int k, r = 0;  

   do  
   {       
       k = n % 10;       
       if(k == 1)           
           ++r;  
   } while ((n /= 10) > 0);  

   return r;
}

int f(int n)
{  
   map<int,int>::iterator it = g_Cache.find(n);  

   if(it != g_Cache.end())       
       return it->second;  

   int result;  
   if(n <= 1) 
   {       
       result = n;  
   }  
   else  
   {       
       it = g_Cache.find(n-1);       

       if(it != g_Cache.end())           
           result = it->second + gf(n);       
       else           
           result = f(n-1) + gf(n);  
   }  

   g_Cache.insert(make_pair(n, result));  
   return result;
}

int main()
{  
   int i;  

   for(i = 2; f(i) != i; ++i)       
       ;  

   printf("%d\n", i);  

   int last = 1;  
   for(i = 2; (last += gf(i)) != i; ++i)       
       ;  

   printf("%d\n", i);  
   return 0;
}[/CPP]
Trackback : http://jiniya.net/tt/trackback/299
Porn (2022/05/30 17:26)
Thanks for this article!!!

OKBET esports online betting (2023/01/20 18:11)
The most secure sportsbook in the Philippines is here. OKBET is legally operating sports betting and online casino in the Philippines. If you're into legal form of online gambling, join OKBET. Visit us for more information.

Football world cup betting (2023/01/26 16:14)
Join OKBET if you're interested in playing legal online casino and sports betting. The best online gambling experience is provided by OKBET, which offers hundreds of casino games and sports betting every day. For additional amazing incentives, visit and register with us using the <a href="https://tinyurl.com/bdkx8ncm">OKBET Referral Code</a> Play Responsibly!

Fence Company Metairie, LA (2023/01/26 21:01)
What an excellent post. This is so informative!

Name   Password   Home   Secret   Submit
 Prev   1  ...  342   343   344   345   346   347   348   349   350  ...  604   Next 
codewiz’s Blog is powered by Tattertools.com / Designed by faido