N-ლაზიერის ამოცანა ვთქვათ, მოცემულია საჭადრაკო დაფა და 8 ლაზიერი

Slides:



Advertisements
Similar presentations
Complete Structure class Date {class Date { private :private : // private data and functions// private data and functions public :public : // public data.
Advertisements

Recursive Descent Technique CMSC 331. UMBC 2 The Header /* This program matches the following A -> B { '|' B } B -> C { '&' C } C -> D { '^' D } D ->
For(int i = 1; i
void count_down (int count) { for(i=count; i>1; i--) printf(" %d\t", count); } printf("A%d\n", count); if(count>1) count_down(count-1); printf("B%d\n",
Functions Prototypes, parameter passing, return values, activation frams.
LCS Non-Dynamic Version int function lcs (x, y, i, j) begin if (i = 0) or (j = 0) return 0; else if (x[i] = y[j]) return lcs(x, y, i-1, j-1)+1; else return.
Def f(n): if (n == 0): return else: print(“*”) return f(n-1) f(3)
Lab 8 User Defined Function.
PASSING PARAMETERS 1. 2 Parameter Passing (by Value) Parameters Formal Parameters – parameters listed in the header of the function Variables used within.
The N-Queens Problem lab01.
Understanding Loops Using C Language Week 15 Mr.Omer Salih.
Pointers Example Use int main() { int *x; int y; int z; y = 10; x = &y; y = 11; *x = 12; z = 15; x = &z; *x = 5; z = 8; printf(“%d %d %d\n”, *x, y, z);
Recursion Examples Fundamentals of CS Case 1: Code /* Recursion: Case 1 */ #include void count (int index); main () { count (0); getchar(); } void count.
Return function Random function Recursion function Function in C 1.
Looping Construct or Statements. Introduction of looping constructs In looping,a sequence of statements are executed until some condition for termination.
Computer Programming A simple example /* HelloWorld: A simple C program */ #include int main (void) { printf (“Hello world!\n”); return.
Review (before the 1 st test): while (conditions) { statements; } while loop: if/else if/else statements: if (conditions) { statements; } else if (different.
Print Row Function void PrintRow(float x[ ][4],int i) { int j; for(j=0;j
Int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } 5 void main () { Int Sum; : Sum = fact (5); : } Factorial Program Using Recursion.
Презентацию подготовила Хайруллина Ч.А. Муслюмовская гимназия Подготовка к части С ЕГЭ.
ADT Stack What Is a Stack? Standard Template Library Stack Class
LINKED LISTS.
Introduction to Computer Algorithmics and Programming Ceng 113
C/C++: type sizes in memory pointers
Understand argc and argv
Number guessing game Pick a random number between 1 and 10
Introduction to C Language
Structure of C Programs
PGT 106: Computer Programming
Week 5 – Functions (1) EKT120: Computer Programming.
EKT120: Computer Programming
CS1010 Programming Methodology
Exercises on String Operations
The Binary Tree Data Structure
LINKED LISTS.
Introduction to Programming and the C Language
ФОНД ЗА РАЗВОЈ РЕПУБЛИКЕ СРБИЈЕ
Yung-Hsiang Lu Purdue University
מבני נתונים ויעילות אלגוריתמים
Chapter 8 The Loops By: Mr. Baha Hanene.
მხედრით საჭადრაკო დაფის შემოვლის ამოცანა
Functions, Part 2 of 3 Topics Functions That Return a Value
Stacks.
Command Line Parameters
Qsort.
Example Using Functions
'III \-\- I ', I ,, - -
Relational, Logical, and Equality Operators
class PrintOnetoTen { public static void main(String args[]) {
REPETITION STATEMENTS
C Security Pre Function
Extra Practice for Recursion
Week 6 CPS125.
Pertemuan Hari ke - 1 Sesi-3.
Functions Extra Examples.
Character Arrays char string1[] = “first”;
Exercise 5 1. We learned bubble sort during class. This problem requires you to modify the code for bubble sorting method to implement the selection sorting.
Strings #include <stdio.h>
Main() { int fact; fact = Factorial(4); } main fact.
Characters and Strings Functions
,, 'III \-\-
CSCE 206 Lab Structured Programming in C
pointer-to-pointer (double pointer)
Recursive example 1 double power(double x, int n) // post: returns x^n
Functions, Part 2 of 3 Topics Functions That Return a Value
Chapter 11 Classes.
and Functions to Simplify Code
Functions, Part 2 of 3 Topics Functions That Return a Value
Rudra Dutta CSC Spring 2007, Section 001
and Functions to Simplify Code
Presentation transcript:

N-ლაზიერის ამოცანა ვთქვათ, მოცემულია საჭადრაკო დაფა და 8 ლაზიერი ვთქვათ, მოცემულია საჭადრაკო დაფა და 8 ლაზიერი შესაძლებელია თუ არა რვავე ლაზიერის ისე განლაგება დაფაზე, რომ არცერთი მათგანი არ ემუქრებოდეს სხვას?

N-ლაზიერის ამოცანა ორი ლაზიერი ერთმანეთს ემუქრება, თუ ისინი მდებარეობენ ერთ და იმავე ვერტიკალზე, ჰორიზონტალზე ან დიაგონალზე

N-ლაზიერის ამოცანა ზოგადად, ეს ამოცანა შეიძლება დაისვას N x N ზომის დაფისათვის და შესაბამისად, N ლაზიერისათვის N ლაზიერი N სვეტი N სტრიქონი

N-ლაზიერის ამოცანა ამოცანის ამოსახსნელად საჭიროა გადარჩევა უკან დაბრუნებით. ცხადია, რომ ამონახსნში ყოველი ლაზიერი განლაგებული იქნება განსხვავებულ ვერტიკალზე (და ჰორიზონტალზეც). ავირჩიოთ რაიმე მიმართულება ლაზიერების დასმისათვის: ვთქვათ ,ზემოდან ქვემოთ და მარცხნიდან მარჯვნივ. პირველი ლაზიერი დავსვათ (1,1) უჯრაზე და დავიწყოთ თავისუფალი უჯრის ძებნა მეორე სვეტში. პირველივე თავისუფალ უჯრაზე დავსვათ მეორე ლაზიერი და დავიწყოთ თავისუფალი უჯრის ძებნა მესამე სვეტში და ა.შ. საზოგადოდ თუკი 1-დან i-ური სვეტის ჩათვლით ლაზიერები დავსვით, (i+1)-ე სვეტში ვიწყებთ თავისუფალი უჯრის ძებნას (ანუ ისეთი უჯრისას, რომელსაც არცერთი უკვე დასმული ლაზიერი არ ემუქრება). თუკი ასეთი უჯრა მოინახა, ვსვამთ (i+1)-ე ლაზიერს და ვამოწმებთ, ხომ არ მივაღწიეთ N-ურ სვეტს (მაშინ ამონახსნი უკვე მიგვიღია), ხოლო თუკი (i+1)-ე სვეტში თავისუფალი უჯრა არ არის, მაშინ დაფიდან ვიღებთ i-ურ ლაზიერს (ანუ ვახორციელებთ უკან დაბრუნებას) და ვცდილობთ მოვძებნოთ მისთვის თავისუფალი უჯრა იმ უჯრის ქვემოთ, სადაც ის აქამდე იყო მოთავსებული. თუ ასეთი უჯრა არ მოიძებნა, დაფიდან ვიღებთ (i-1)-ე ლაზიერს და ა.შ.

N-ლაზიერის ამოცანა

პირველი 2 ამოხსნა 92-დან, რომელიც ზემოთ აღწერილი ალგორითმით მიიღება N-ლაზიერის ამოცანა პირველი 2 ამოხსნა 92-დან, რომელიც ზემოთ აღწერილი ალგორითმით მიიღება

N-ლაზიერის ამოცანა 15863724 16837425 17468253 17582463 24683175 25713864 25741863 26174835 26831475 27368514 27581463 28613574 31758246 35281746 35286471 35714286 35841726 36258174 36271485 36275184 36418572 36428571 36814752 36815724 36824175 37285146 37286415 38471625 41582736 41586372 42586137 42736815 42736851 42751863 42857136 42861357 46152837 46827135 46831752 47185263 47382516 47526138 47531682 48136275 48157263 48531726 51468273 51842736 51863724 52468317 52473861 52617483 52814736 53168247 53172864 53847162 57138642 57142863 57248136 57263148 57263184 57413862 58413627 58417263 61528374 62713584 62714853 63175824 63184275 63185247 63571428 63581427 63724815 63728514 63741825 64158273 64285713 64713528 64718253 68241753 71386425 72418536 72631485 73168524 73825164 74258136 74286135 75316824 82417536 82531746 83162574 84136275 . 92-ივე ამოხსნა 8x8 ზომის დაფისათვის. თითოეული ამონახსნი ჩაწერილია 8 ციფრით. ციფრის პოზიცია ჩანაწერში შეესაბამება სვეტის ნომერს, ხოლო თავად ციფრი - სტრიქონის ნომერს. ამოხსნები შეიძლება დაიყოს 23 ოთხეულად, სადაც თითოეულ ოთხეულში შემავალი ამოხსნები ერთმანეთისაგან მიიღება დაფის შემობრუნებით.

N-ლაზიერის ამოცანა პირველი ამოხსნის პოვნისათვის საჭირო სვლების რაოდენობა ამოხსნების რაოდენობა სხვადასხვა ზომის დაფისათვის

N-ლაზიერის ამოცანა #include <stdio.h> #include <stdlib.h> #define N 9 int x[N]; void print () { int i; for (i=0; i<N; i++) printf ("%d",x[i]); system("PAUSE"); } int is_free (int ix, int iy) { for (i=0; i<iy; i++) if ((x[i]==ix) || (abs(x[i]-ix)==abs(i-iy))) return 0; return 1; } void svla (int n) { int i; if (n==N) print(); else for (i=0; i<N; i++) if (is_free(i,n)>0) { x[n]=i; svla (n+1); } int main ( ){ svla (0); return 0; system("PAUSE"); But each new placement must be checked for potential conflicts with the previous queen. If there is a conflict, then the newly-placed queen is shifted rightward.