Page 1 of 2 12 LastLast
Results 1 to 10 of 18

Thread: [มาตอบกันดูครับ]ปัญหานับเลขแบบ simple

  1. #1
    Senior Member retool2's Avatar
    Join Date
    Aug 2008
    Location
    Under Relocation
    Posts
    178


    นานมาแล้วผมเจอปัญหาที่ simple อยู่ปัญหาหนึ่ง
    แต่วิธีแก้มันไม่ง่ายอย่างคำถามเลย

    ปัญหามีอยู่ว่า มีคนอยู่จำนวนหนึ่งยืนล้อมวงกันเป็นวงกลม
    โดยทุกคนติดหลายเลขประจำตัวที่เสื้อ
    คนที่ 1 จะเริ่มนับ 0 แล้วคนต่อไปจะนับ 1
    คนต่อไปจะนับ 0 ไปเรื่อยๆ
    คนที่นับ 0 จะต้องออกจากวง ส่วนคนที่นับ 1 จะอยู่ในวงต่อไป
    คำถาม ?????
    ถ้ามีคนอยู่ 500,000 คน คนที่ติดหมายเลขอะไรจะอยู่เป็นคนสุดท้าย

    ลองคิดกันดูเล่นๆนะครับ
    ความท้าทายอยู่ที่การหาคำตอบว่าเราจะหามันได้ยังไงครับ
    (ผมใช้คอมพิวเตอร์ช่วยคำนวน หุหุ)


    ผมอต้องการหาคำตอบเลยได้เขียนโปรแกรมขึ้นมาดังนี้
    [hide=5][code]<html><body>
    <form action="" method="post">
    <table>
    <TR><TD>Total people</TD><TD><input type="number" name="people"/></TD></TR>
    <TR><TD>Start say</TD><TD><select name=startsay><option value ="0">0</option><option value ="1">1</option></select> 0 = out</TD></TR>
    </table>
    <input name="submit" type="submit" value="Count"/><input name="submit" type="submit" value="Count with print"/>
    </form>
    </body></html>
    <?
    if(isset($people) && $people<1){ ?>
    <script language="Javascript">
    <!--
    alert ("Total people must be NUMBER must more than 0")
    //-->
    </script>
    <?
    }else{

  2. #2
    Junior Member
    Join Date
    Mar 2008
    Posts
    3


    อยากนับเลขจัง
    เดี๋ยวต้องไปโพสเยอะๆก่อน พอดีผมไม่ค่อยเก่ง เรื่องอธิบายนู้นนี่อ่า

  3. #3
    Junior Member
    Join Date
    Feb 2008
    Posts
    15


    **Hidden Content: To see this hidden content your post count must be 5 or greater.**

  4. #4
    Senior Member retool2's Avatar
    Join Date
    Aug 2008
    Location
    Under Relocation
    Posts
    178


    50000 อยู่ในช่วง 32768 แต่ไม่ถึง 65536
    จึงตอบว่า 32768
    [/b]
    ยังไม่ถูกนะครับ
    ถ้าเป็น 50,000 จะได้คนที่ 34,464 ครับ
    ส่วน ถ้ามีทั้งหมด 500,000 คนที่อยู่คนสุดท้ายจะอยู่ระหว่างคนที่ 400,000 - 500,000 ครับ

  5. #5
    Junior Member
    Join Date
    Dec 2008
    Location
    Lampang
    Posts
    13


    500000 ไม่ได้คับ เครื่องเน่า


    [hide=2][code]
    <?php
    $ppls = 50000;

    do{//สร้างคน
    Progressive rock blood.

  6. #6
    Junior Member
    Join Date
    Dec 2008
    Posts
    1


    น่าทึ่งสุดๆ ตอนแรกเรานึกว่าจะเปนอะไรกวนๆ อ่านไปอ่านมาเริ่มรุสึกว่ามันไม่ใช่ล้อเล่น มาเจอคำตอบยิ่งแบบว่า ถ้าฉบับนมอุโด้ตต้องอุทานว่า แม่จ้าววววว มันสมองสุดยอดมากๆค่ะ

  7. #7
    Senior Member retool2's Avatar
    Join Date
    Aug 2008
    Location
    Under Relocation
    Posts
    178


    <?php
    $ppls = 50000;

    do{//สร้างคน
    $ppl_arr[] = ++$i; // เริ่มจาก 1
    }while($i < $ppls);

    while( $ppls != 1 ){
    for($i =0; $i < $ppls; $i++){ //คนที่เหลือ
    if($i % 2)
    $new_arr[] = $ppl_arr[$i]; //เอาแต่คนที่นับ 1
    }

    $ppl_arr = $new_arr; //เอาคนที่เหลือ ไปนับใหม่
    unset($new_arr);

    $ppls = count($ppl_arr);
    }

    echo $ppl_arr[0]; //ผลลัพท์

    //ปล. เครื่องผมทำ 500000 ไม่ได้อ่ะคับ เเออเร่อ
    ?>
    [/b]
    รู้สึกว่าวิธีเขียนแบบนี้จะไม่นับเป้นวงกลมนะครับ
    เพราะว่าเท่าที่ดูคือ รู้ได้อย่างไรว่าคนสุดท้ายของการนับแต่ละรอบนับเลขอะไร
    แล้วเริ่มใหม่แต่ละรอบนับเลขอะไร
    เช่น นับ 100 คนควรจะออกมาเป็นแบบนี้
    Code:
    Total people = 100
    Round 1 total people 100 count start with 0 and end with 1
    People left => 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 
    Round 2 total people 50 count start with 0 and end with 1
    People left => 4 8 12 16 20 24 28 32 36 40 44 48 52 56 60 64 68 72 76 80 84 88 92 96 100 
    Round 3 total people 25 count start with 0 and end with 0
    People left => 8 16 24 32 40 48 56 64 72 80 88 96 
    Round 4 total people 12 count start with 1 and end with 0
    People left => 8 24 40 56 72 88 
    Round 5 total people 6 count start with 1 and end with 0
    People left => 8 40 72 
    Round 6 total people 3 count start with 1 and end with 1
    People left => 8 72 
    Round 7 total people 2 count start with 0 and end with 1
    People left => 72

  8. #8
    Junior Member
    Join Date
    Dec 2008
    Location
    Lampang
    Posts
    13


    โทษที ผมเข้าใจผิดเอง
    อันนี้ แก้ให้ใหม่คับ
    [code]<?php
    $ppls = 50000;

    do{//สร้างคน
    Progressive rock blood.

  9. #9
    Senior Member retool2's Avatar
    Join Date
    Aug 2008
    Location
    Under Relocation
    Posts
    178


    มีใครเขียนโปรแกรมเพื่อให้จัดการกับ 500,000 ได้หรือยังครับ
    ผมมีคำตอบอยู่แล้วนะครับ
    โจทย์ข้อนี้ยากตรงที่จะจัดการกับ memory อย่างไร
    แล้วก็จะเขียนโปรแกรมเพื่อให้ทำงานกับเลขเยอะๆได้อย่างไรครับ


    ขอบคุณคุณ xxxxy ด้วยนะครับที่เข้ามร่วมแสดงความคิด

  10. #10
    Junior Member
    Join Date
    Dec 2008
    Posts
    5


    500000 หาร 2 ไปเรื่อย ๆ จนเหลือ 0

    จะได้วงรอบ เอาวงรอบคูณ 2 ลบด้วย 500000

    จะได้ตัวเลขสุดท้ายที่จะอยู่

    ใช่รึเปล่าครับ เลขอะไรไม่รู้อ่ะครับ

    ไม่มีความรู้ทางด้านการเขียนโปรแกรมเลยครับ

    ไครรู้ช่วยทีซิ

Page 1 of 2 12 LastLast

Similar Threads

  1. A simple TCP spoofing attack
    By Dragking in forum Hacking,How to Articles/Tutorial/Techniques (English)
    Replies: 0
    Last Post: 22-11-2008, 10:37 PM
  2. Simple DNS Plus Denial of Service
    By newsbot in forum Exploits
    Replies: 0
    Last Post: 18-07-2008, 03:14 AM
  3. Simple Crypter v2
    By SheLLniX in forum Security Tools
    Replies: 0
    Last Post: 08-02-2008, 09:19 AM
  4. Simple Inline Javascript
    By Gen0TypE in forum แนะความรู้ด้าน Programming ต่างๆ
    Replies: 0
    Last Post: 05-01-2008, 12:52 PM
  5. Simple Virus Code
    By asylu3 in forum C/C++,C#,VC++,MFC,Win32
    Replies: 0
    Last Post: 01-01-1970, 07:00 AM

Members who have read this thread : 0

Actions : (View-Readers)

There are no names to display.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •