Advertentie | |
|
![]() |
||
![]() |
Citaat:
![]() inclusief alle draaiingen en spiegelingen vond ik deze 10 oplossingen voor N=5: Code:
type A: *.... ..*.. ....* .*... ...*. ....* ..*.. *.... ...*. .*... ...*. .*... ....* ..*.. *.... .*... ...*. *.... ..*.. ....* type B: *.... ...*. .*... ....* ..*.. ....* .*... ...*. *.... ..*.. ..*.. *.... ...*. .*... ....* ..*.. ....* .*... ...*. *.... type C: .*... ....* ..*.. *.... ...*. ...*. *.... ..*.. ....* .*... ![]() |
![]() |
||
![]() |
Citaat:
![]() Code:
/* by Johan de Ruiter - jdrsoft@worldonline.nl */ #include <iostream.h> #include <stdio.h> int oplossing[75000][13]; int aantaloplossing=0; int n; //swaps two solutions in list void wissel(int a, int b) { int i, temp; for(i=0;i<n;i++) { temp=oplossing[a][i]; oplossing[a][i]=oplossing[b][i]; oplossing[b][i]=temp; } } //sorts only first three solutions void sorteernieuwe() { bool gevonden=false; bool zoeknog; int i=-1,j; while(!gevonden && i<3) { i++; zoeknog=true; for(j=0;j<n && zoeknog;j++) { if(oplossing[aantaloplossing-1][j]!=oplossing[i][j]) { zoeknog=false; if(oplossing[aantaloplossing-1][j]<oplossing[i][j]) { gevonden=true; wissel(aantaloplossing-1,i); } } } } } void plakvolgende(int huidig[13], int aantalhuidig) { int i; bool mag=true; //controle for(i=0;i<aantalhuidig-1;i++) { if((huidig[i]==huidig[aantalhuidig-1])|| //horizontaal (aantalhuidig-1-i==huidig[aantalhuidig-1]-huidig[i]|| aantalhuidig-1-i==huidig[i]-huidig[aantalhuidig-1])) mag=false; } if(mag) { if(aantalhuidig<n) //nog een erbij proberen for(huidig[aantalhuidig]=1;huidig[aantalhuidig]<=n;huidig[aantalhuidig]++) plakvolgende(huidig,aantalhuidig+1); else //toevoegen { for(i=0;i<n;i++) oplossing[aantaloplossing][i]=huidig[i]; aantaloplossing++; sorteernieuwe(); if(huidig[0]<=n/2) { for(i=0;i<n;i++) oplossing[aantaloplossing][i]=n+1-huidig[i]; aantaloplossing++; sorteernieuwe(); } } } } int main() { FILE *invoer; FILE *uitvoer; invoer = fopen("checker.in", "r"); uitvoer = fopen("checker.out", "w"); fscanf(invoer, "%d", &n); int huidig[13]; int aantalhuidig=0; int c; for(c=1;c<=n/2;c++) { huidig[0]=c; plakvolgende(huidig,1); } if(n%2==1) { huidig[0]=n/2+1; plakvolgende(huidig,1); } int a,b; for(a=0;a<3;a++) { for(b=0;b<n;b++) { fprintf(uitvoer, "%d", oplossing[a][b]); if(b<n-1) fprintf(uitvoer, " "); } fprintf(uitvoer, "\n"); } fprintf(uitvoer, "%d\n", aantaloplossing); fclose(invoer); fclose(uitvoer); return 0; } |
![]() |
|
|
![]() |
||||
Forum | Topic | Reacties | Laatste bericht | |
Huiswerkvragen: Exacte vakken |
[Wiskunde] Hamilton Circuit damsco | 2 | 02-03-2007 22:02 | |
Levensbeschouwing & Filosofie |
de grenzen van het menselijk kunnen cup a soup | 44 | 25-04-2004 20:23 | |
Verhalen & Gedichten |
Nina & Sara Giles | 18 | 24-07-2003 22:37 | |
Eindexamens 2003 |
Staatsexamen mondeling Duplo | 39 | 04-07-2003 20:35 | |
Huiswerkvragen: Exacte vakken |
hoeveel rechthoeken zitten er op een schaakbord?? flevomaster | 31 | 22-04-2002 15:58 | |
Huiswerkvragen: Exacte vakken |
Schaakbord en rijstkorrels *Butterfly* | 20 | 19-04-2002 22:46 |