#include #include #include #include using namespace std; struct cell { double amount; double leftheight; double rightheight; double leftpos; double rightpos; bool isfull; bool leftlow; double lowheight; }; struct jag{ double speed; double x; }; void step(list &cells, list &jags, int deltat){ list::iterator cit; list::iterator jit; for(cit = cells.begin() ; cit != cells.end() ; cit ++){ for(jit = jags.begin() ; jit != jags.end() ; jit ++){ if(cit->leftpos < jit->x && cit->rightpos > jit->x){ cit->amount += jit->speed*deltat; } } } int succeed=1; bool leftlow; double lowheight; list::iterator cit2; while ( succeed ) { succeed = 0; for(cit = cells.begin() ; cit != cells.end() ; cit ++){ double height; height = cit->amount / (30.*(cit->rightpos - cit->leftpos)); if(height > cit->lowheight ){ succeed++; cit->isfull=true; cit2 = cit; if ( cit->leftlow ) --cit2; else ++cit2; if ( !cit2->isfull || cit2->leftlow==cit->leftlow ) { cit2->amount += cit->amount -cit->lowheight*30.*(cit->rightpos - cit->leftpos); cit->amount = cit->lowheight*30.*(cit->rightpos - cit->leftpos); continue; } //merge if ( cit->leftlow ) { cit->amount += cit2->amount; cit->leftheight = cit2->leftheight; cit->leftpos = cit2->leftpos; cit->isfull = false; } else { cit->amount += cit2->amount; cit->rightheight = cit2->rightheight; cit->rightpos = cit2->rightpos; cit->isfull = false; } if ( cit->leftheight < cit->rightheight ) { cit->leftlow = true; cit->lowheight = cit->leftheight; } else { cit->leftlow = false; cit->lowheight = cit->rightheight; } cells.erase(cit2); break; } } } } int main(void) { int d; cin >> d; for(int i = 0 ; i < d ; i ++){ int n; list cells; vector boardx; vector boardh; cin >> n; for(int t = 0 ; t < n ; t ++){ double x,h; cin >> x >> h; boardx.push_back(x); boardh.push_back(h); } cell firstcell; // firstcell firstcell.amount = 0; firstcell.leftheight = DBL_MAX; firstcell.rightheight = boardh[0]; firstcell.leftpos = 0; firstcell.rightpos = boardx[0]; firstcell.isfull = false; firstcell.leftlow=false; firstcell.lowheight = boardh[0]; cells.push_back(firstcell); for(int t = 0 ; t < n ; t ++){ cell tempcell; tempcell.amount = 0; tempcell.leftheight = boardh[t]; tempcell.leftpos = boardx[t]; if(t == n-1){ tempcell.rightheight = DBL_MAX; tempcell.rightpos = 100; }else{ tempcell.rightheight = boardh[t+1]; tempcell.rightpos = boardx[t+1]; } tempcell.isfull = false; if ( tempcell.leftheight < tempcell.rightheight ) { tempcell.leftlow=true; tempcell.lowheight=tempcell.leftheight; } else{ tempcell.leftlow=false; tempcell.lowheight=tempcell.rightheight; } cells.push_back(tempcell); } list jags; int m; cin >> m; for(int t = 0 ; t < m ; t ++){ double x,speed; jag tempjag; cin >> x >> speed; tempjag.x = x; tempjag.speed = speed; jags.push_back(tempjag); } int c; cin >> c; for(int t = 0 ; t < c ; t ++){ list jags2; list cells2; int x,t; cin >> x >> t; jags2 = jags; cells2 = cells; step(cells2,jags2,t); list::iterator cit; for(cit = cells2.begin() ; cit != cells2.end() ; cit++){ if(cit->leftpos < x && cit->rightpos > x){ double height; height = cit->amount / (30.*(cit->rightpos - cit->leftpos)); if(height > 50.0) height = 50.0; cout << height << endl; } } } } }