#include #include #include char drei[200][200]; int max,num,max2; int check_drei(int x,int y, int teil) { int x2,y2; if(teil%2==0) return 0; /* printf("Checking (%d/%d) mit Laenge %d\n",x,y,teil); printf("Teste y von %d bis %d bzw. %d\n",y,y+(teil+1)/2-1,num); */ for(y2=y;y2<(y+(teil+1)/2)&&y2=num) return 0; /* printf("Teste Zeile %d von %d bis %d\n",y2,x+y2-y,x+teil-y2+y-1); */ for(x2=x+y2-y;x2<(x+teil-y2+y);x2++) { /* printf("(%d,%d)",x2,y2); */ if(drei[y2][x2]=='#') { return 0;} } } max=teil; /* printf("!!! %d ok\n",teil); */ return 1; } int check_drei2(int x,int y, int teil) { int x2,y2; if(teil%2==0) return 0; /* printf("*** Checking (%d/%d) mit Laenge %d\n",x,y,teil); printf("Teste y von %d bis %d bzw. %d\n",y,y-(teil+1)/2+1,num); */ for(y2=y;y2>(y-(teil+1)/2);y2--) { if(y2<0) return 0; /* printf("Teste Zeile %d von %d bis %d\n",y2,x+y2-y,x+teil-y2+y-1); */ for(x2=x-y2+y;x2<(x+teil+y2-y);x2++) { /* printf("(%d,%d)",x2,y2); */ if(drei[y2][x2]=='#') { return 0;} } } max=teil; /* printf("%d ok\n",teil); */ return 1; } main() { FILE *file=fopen("triangle.in","r"); char s[1000]; int x,y,xdel; int bsp=1,t,teil,z; while(1) { fgets(s,1000,file); num=atoi(s); if(num==0) exit(0); max=0; printf("Triangle #%d\n",bsp++); for(y=0;ymax) { /* printf("Checking max: %d\n",teil); check_drei(x-teil,y,teil); */ for(max2=max+1;max2<=teil;max2++) { for(xdel=0;xdel<=teil-max2;xdel++) if((x-teil+xdel)>0) check_drei(x-teil+xdel,y,max2); for(xdel=0;xdel<=teil-max2;xdel++) if((x-teil+xdel)>0) check_drei2(x-teil+xdel,y,max2); } teil=0; } } } } printf("The largest triangle area is %d.\n\n",((max+1)*(max+1))/4); } }