Zgaduj, a ja podpowiem
Zgadywanie liczby: jak szukać sprytnie, połowa po połowie - Informatyka - klasa 6 (doc)
Kolega wymyślił liczbę od 1 do 100, a na każdą próbę mówi "więcej", "mniej" albo "zgadłeś". Zgadywanie **po kolei** (1, 2, 3, ...) może wymagać nawet 100 prób. Sprytniej jest pytać o liczbę **w połowie** przedziału: każda odpowiedź wyrzuca połowę liczb. Taki sposób to **wyszukiwanie przez połowienie**. Przebieg dla liczby 37:
{"type":"doc","content":[{"type":"table","content":[{"type":"tableRow","content":[{"type":"tableHeader","content":[{"type":"paragraph","content":[{"type":"text","text":"Próba"}]}]},{"type":"tableHeader","content":[{"type":"paragraph","content":[{"type":"text","text":"Przedział"}]}]},{"type":"tableHeader","content":[{"type":"paragraph","content":[{"type":"text","text":"Pytam o"}]}]},{"type":"tableHeader","content":[{"type":"paragraph","content":[{"type":"text","text":"Odpowiedź"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","content":[{"type":"paragraph","content":[{"type":"text","text":"1"}]}]},{"type":"tableCell","content":[{"type":"paragraph","content":[{"type":"text","text":"1-100"}]}]},{"type":"tableCell","content":[{"type":"paragraph","content":[{"type":"text","text":"50"}]}]},{"type":"tableCell","content":[{"type":"paragraph","content":[{"type":"text","text":"mniej"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","content":[{"type":"paragraph","content":[{"type":"text","text":"2"}]}]},{"type":"tableCell","content":[{"type":"paragraph","content":[{"type":"text","text":"1-49"}]}]},{"type":"tableCell","content":[{"type":"paragraph","content":[{"type":"text","text":"25"}]}]},{"type":"tableCell","content":[{"type":"paragraph","content":[{"type":"text","text":"więcej"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","content":[{"type":"paragraph","content":[{"type":"text","text":"3"}]}]},{"type":"tableCell","content":[{"type":"paragraph","content":[{"type":"text","text":"26-49"}]}]},{"type":"tableCell","content":[{"type":"paragraph","content":[{"type":"text","text":"37"}]}]},{"type":"tableCell","content":[{"type":"paragraph","content":[{"type":"text","text":"zgadłeś"}]}]}]}]},{"type":"paragraph","content":[{"type":"text","text":"Liczba w połowie przedziału = (początek + koniec) : 2, zaokrąglona w dół."}]}]}Ładowanie interaktywnego edytora... Jeśli się nie pojawi, włącz JavaScript.
Wszystkie lekcje kursu Informatyka - klasa 6·Zaloguj się, aby zapisać postęp na koncie.