#include #include #include #include #include #include #include #include #include using ld = long double; #define D if(0) QTcpSocket * tcp; // Qt-čková implementace tcp na připojení se k serveru char token[1234]; int remainingQ = 5000; int countGeo = 0; QSet isOut; QJsonArray api(ld p[4]) // Implementace API { // Vezme pole obsahující min_lon; max_lon; min_lat; max_lat // Vrátí json pole s odpovědí if(0) { reset: tcp->close(); tcp->connectToHost("ksp.mff.cuni.cz", 80); if(!tcp->waitForConnected()) exit(100); fprintf(stderr,"#### restart\n"); } char in [2234]; sprintf(in, "GET /api/32-5-6/map/caches?min_lon=%.10LF&max_lon=%.10LF&min_lat=%.10LF&max_lat=%.10LF&token=%s HTTP/1.1\n" "Host: ksp.mff.cuni.cz\n" "\n",p[0],p[1],p[2],p[3],token); remainingQ--; if(remainingQ <=0 ) { fprintf(stderr, "NO MORE QUERIES ---- FIND %d GC\n",countGeo); exit(0); } tcp->write(QByteArray(in)); QByteArray data; bool inData=0; int dataLen; while(1) { if(!tcp->waitForReadyRead(1000)) goto reset; QByteArray r =(tcp->readAll()); for(char c : r) { if(c=='\r') continue; if(c=='\n') { if(data=="") inData=1; int l; if(sscanf(data.data(),"Content-Length: %d",&l)==1) dataLen=l; data = ""; } else { data += c; if(inData && dataLen==data.size()) return QJsonDocument::fromJson(data).array(); } } } tcp->close(); exit(101); } ld toleration = 0.000019; void find(int orientation,ld p[4],QSet s,int h=0) // Rekurzivní funkce na hledání keší { if(p[1]-p[0]< toleration && p[3]-p[2] < toleration) { // Když už je oblast dostatečně malá auto r = api(p); for(int i = 0;i sa; // Kešky v obdélníčku a; zbytek zůstane v s auto r = api(a); for(int i = 0;iconnectToHost("ksp.mff.cuni.cz", 80); if(!tcp->waitForConnected()) exit(100); ld squareLen = 0.2; for(ld i = 0 ; i< 100;i+=squareLen) for(ld j = 0 ; j< 100;j+=squareLen) {// procházej možné čtverečky 0.2 x 0.2 ld p[4]; // Krajní polohy p[0]=i;p[1]=i+squareLen; p[2]=j;p[3]=j+squareLen; auto r = api(p); QSet s; if(r.size()==500) continue; // Když je zde moc keší, vynech for(int i = 0;i