pair<pair<int, int>, double> close0(TPoint *ps, int l, int r) { if (r - l <= 1) return MP(MP(-1, -1), 1e100); pair<pair<int, int>, double> ret; ret.second = 1e100; int m = (l + r) / 2, i; for (i = m; i >= l && sig(ps[i].x - ps[m].x) == 0; i--); pair<pair<int, int>, double> temp = close0(ps, l, i + 1); if (temp.second < ret.second) { ret = temp; } for (i = m; i < r && sig(ps[i].x - ps[m].x) == 0; i++); temp = close0(ps, i, r); if (temp.second < ret.second) { ret = temp; } int len = 0; for (i = m; i >= l && sig(ps[m].x - ret.second - ps[i].x) < 0; i--) { psy[len++] = ps[i]; } for (i = m + 1; i < r && sig(ps[m].x + ret.second - ps[i].x) > 0; i++) { psy[len++] = ps[i]; } sort(psy, psy + len, cmp_y); for (i = 0; i < len; i++) for (int j = i + 1; j < len && psy[j].y < psy[i].y + ret.second; j++) { double d = dist(psy[i], psy[j]); if (d < ret.second) { ret.first = MP(psy[i].id, psy[j].id); ret.second = d; } } return ret; }
void main(void){ int socket0status; unsigned char ip_addr[] = {192,168,0,182}; //{169,254,180,2}; // delay(100); printf("\nOlduino Bagels Server V5\n"); wiz_Init(ip_addr); //initialize the wiznet chip while(1){ // Loop forever socket0status=wiz_Read(S0_SR); //printf("s0s=%x ",socket0status); switch (socket0status){ case SOCK_CLOSED: //initial condition socket0_init(); //initialize socket 0 break; case SOCK_ESTABLISHED: //someone wants to talk to the server handlesession(); break; //following are cases where we have to reset and reopen the socket case SOCK_FIN_WAIT: case SOCK_CLOSING: case SOCK_TIME_WAIT: case SOCK_CLOSE_WAIT: case SOCK_LAST_ACK: close0(); break; } tbrnd();//keep the random number generator cycling delay(100);//delay in ms @1.6mhz uptime+=46;//counting ms; } }
void main(void){ int socket0status; //ledmode=0; digitalWrite(0,LOW); cmdip[0]=0; pagehits=0; delay(100); printf("\nOlduino Web Server v5.1\n"); W5100_Init(); //initialize the wiznet chip while(1){ // Loop forever socket0status=SPI_Read(S0_SR); //printf("s0s=%x ",socket0status); switch (socket0status){ case SOCK_CLOSED: //initial condition socket0_init(); //initialize socket 0 break; case SOCK_ESTABLISHED: //someone wants to talk to the server handlesession(); break; //following are cases where we have to reset and reopen the socket case SOCK_FIN_WAIT: case SOCK_CLOSING: case SOCK_TIME_WAIT: case SOCK_CLOSE_WAIT: case SOCK_LAST_ACK: close0(); break; } delay(100); } }