bool IOObject::GetMessages( std::string &str ) { inQueue_.Lock(); MessageQueue &inQ( inQueue_.Access() ); if( inQ.size() > 0 ) { str = inQ.front(); inQ.pop_front(); inQueue_.Unlock(); return true; } inQueue_.Unlock(); return false; }
void operator()() { std::queue<int> Q; std::vector<bool> inQ((*this).G.V(), false); Q.push((*this).s); inQ[(*this).s] = true; wt[(*this).t] = - ( wt[(*this).s] = max_val<type_flow>() ); h[(*this).s] = 1; /* while(true) { if(Q.empty()) { for(int i = 0; i < addToQ.size(); i++) if(addToQ[i]) Q.push_back(*/ while(!Q.empty()) { int next = Q.front(); Q.pop(); inQ[next] = false; typename Graph::iterator it((*this).G, next); for(Edge *e = it.beg(); !it.end(); e = it.nxt()) { int w = e->other(next), cap = e->capRto(w), red = std::min(cap, wt[next]); if(red > 0 && ( next == (*this).s || h[next] == h[w] + 1 )) { e->addflowRto(w, red); wt[next] -= red; wt[w] += red; if( !inQ[w] && (w != (*this).s) && (w != (*this).t) ) Q.push(w); } } if( next != (*this).s && next != (*this).t && wt[next] > 0) { h[next]++; Q.push(next); } } }
int main(int argc, char* argv[]) { std::cout.precision(17); Mesh P, Q; if(argc < 3) { std::cerr << "Usage: do_intersect <mesh_1.off> <mesh_2.off>" << std::endl; return EXIT_FAILURE; } std::ifstream inP(argv[1]); inP >> P; std::ifstream inQ(argv[2]); inQ >> Q; Timer timer; timer.start(); unsigned int num_intersections = intersect(P,Q); timer.stop(); std::cout << "Counted " << num_intersections << " in " << timer.time() << " seconds." << std::endl; return 0; }
int main() { int i, k, Qhash, tarHash, hash, isFind; char target[11]={'1', '2', '3', '4', '5', '6', '7', '8', '9','8', '\0'}; char a; char path[362880]; i=0; while(scanf("%c", &a) && a!=10) { if(a<='8' && a>='0') help[i++] = a; else if(a=='x') { help[9] = i+48; help[i++] = '9'; } } help[10] = '\0'; tarHash = getHash(target); for(i=0; i<362881; i++) Flag[i].parent = -1; isFind = 0; front = 0; rear = 0; Flag[getHash(help)].parent = -2; inQ(); while(front!=rear) { outQ(); Qhash = getHash(u); if(Qhash==tarHash) { isFind = 1; break; } if(u[9]=='4') { for(i = 1; i<=7; i+=2) { strcpy(help, u); swap(help, i, 4); help[9] = i+48; hash = getHash(help); if(Flag[hash].parent==-1) { Flag[hash].parent = Qhash; Flag[hash].mathod = (i-1)/2 + 1 + 48; inQ(); } } } else if(u[9]=='0') { for(i = 1; i<=3; i+=2) { strcpy(help, u); swap(help, i, 0); help[9] = i+48; hash = getHash(help); if(Flag[hash].parent==-1) { Flag[hash].parent = Qhash; Flag[hash].mathod = i/2+3+48; inQ(); } } } else if(u[9]=='1') { for(i = 0; i<=4; i+=2) { strcpy(help, u); swap(help, i, 1); help[9] = i+48; hash = getHash(help); if(Flag[hash].parent==-1) { Flag[hash].parent = Qhash; Flag[hash].mathod = i/2 + 2 + 48; inQ(); } } } else if(u[9]=='2') { for(i = 1; i<=5; i+=4) { strcpy(help, u); swap(help, i, 4); help[9] = i+48; hash = getHash(help); if(Flag[hash].parent==-1) { Flag[hash].parent = Qhash; Flag[hash].mathod = i/2 + 2 + 48; inQ(); } } } else if(u[9]=='3') { for(i = 6; i>=0; i = (i-4)*2) { strcpy(help, u); swap(help, i, 3); help[9] = i+48; hash = getHash(help); if(Flag[hash].parent==-1) { Flag[hash].parent = Qhash; Flag[hash].mathod = i/2 + 1 + 48; inQ(); } } } else if(u[9]=='5') { for(i = 2; i<=8; i *= 2) { strcpy(help, u); swap(help, i, 5); help[9] = i+48; hash = getHash(help); if(Flag[hash].parent==-1) { Flag[hash].parent = Qhash; Flag[hash].mathod = i/2 + 48; inQ(); } } } else if(u[9]=='6') { for(i = 3; i<=7; i += 4) { strcpy(help, u); swap(help, i, 6); help[9] = i+48; hash = getHash(help); if(Flag[hash].parent==-1) { Flag[hash].parent = Qhash; Flag[hash].mathod = (i-1)/2 + 48; inQ(); } } } else if(u[9]=='7') { for(i = 4; i<=8; i += 2) { strcpy(help, u); swap(help, i, 7); help[9] = i+48; hash = getHash(help); if(Flag[hash].parent==-1) { Flag[hash].parent = Qhash; Flag[hash].mathod = (i-2)/2 + 48; inQ(); } } } else if(u[9]=='8') { for(i = 5; i<=7; i += 2) { strcpy(help, u); swap(help, i, 8); help[9] = i+48; hash = getHash(help); if(Flag[hash].parent==-1) { Flag[hash].parent = Qhash; Flag[hash].mathod = (i-3)/2 + 48; inQ(); } } } } if(isFind==0) { printf("unsolvable\n"); return 1; } i = Qhash; k = 0; while(i!=-2) { if(Flag[i].mathod=='1') path[k++] = 'u'; else if(Flag[i].mathod=='2') path[k++] = 'l'; else if(Flag[i].mathod=='3') path[k++] = 'r'; else if(Flag[i].mathod=='4') path[k++] = 'd'; i = Flag[i].parent; } for(i=k-1; i>=0; i--) printf("%c", path[i]); printf("\n"); return 1; }