int main(void) { int size; scanf("%d" , &size); while (size--) { allClear(); scanf("%d" , &points); scanf("%d" , &edges); } }
struct spaceNode *spaceSaverAddOverflowMultiOptionalPadding(struct spaceSaver *ss, struct spaceRange *rangeList, struct spaceNode *nodeList, boolean allowOverflow, boolean doPadding) /* Add new nodes for multiple windows to space saver. Returns NULL if can't fit item in * and allowOverflow == FALSE. If allowOverflow == TRUE then put items * that won't fit in first row (ends up being last row after * spaceSaverFinish()). Allow caller to suppress padding between items * (show adjacent items on single row */ { struct spaceRowTracker *srt, *freeSrt = NULL; int rowIx = 0; struct spaceNode *sn; if (ss->isFull) return NULL; struct spaceRange *range; struct spaceRange *cellRanges = NULL, *cellRange; for (range = rangeList; range; range = range->next) { AllocVar(cellRange); int start = range->start; int end = range->end; if ((start -= ss->winStart) < 0) start = 0; end -= ss->winStart; /* We'll clip this in cell coordinates. */ cellRange->start = round(start * ss->scale); int padding = doPadding ? 1 : 0; cellRange->end = round(end * ss->scale) + padding; if (cellRange->end > ss->cellsInRow) cellRange->end = ss->cellsInRow; cellRange->width = cellRange->end - cellRange->start; slAddHead(&cellRanges, cellRange); } slReverse(&cellRanges); if (ss->vis == 2) // tvFull for BEDLIKE tracks does not pack, so force a new line { rowIx = ss->rowCount; } else { /* Find free row. */ for (srt = ss->rowList; srt != NULL; srt = srt->next) { bool freeFound = TRUE; for (cellRange = cellRanges; cellRange; cellRange = cellRange->next) { // TODO possibly can just calculate cellRange->width instead of storing it? if (!allClear(srt->used + cellRange->start, cellRange->width)) { freeFound = FALSE; break; } } if (freeFound) { freeSrt = srt; break; } ++rowIx; } } /* If no free row make new row. */ if (freeSrt == NULL) { if (ss->rowCount >= ss->maxRows) { /* Abort if too many rows and no overflow allowed. */ if(!allowOverflow) { ss->isFull = TRUE; return NULL; } } else { AllocVar(freeSrt); freeSrt->used = needMem(ss->cellsInRow); slAddTail(&ss->rowList, freeSrt); ++ss->rowCount; } } /* Mark that part of row used (except in overflow case). */ if(freeSrt != NULL) { for (cellRange = cellRanges; cellRange; cellRange = cellRange->next) { memset(freeSrt->used + cellRange->start, 1, cellRange->width); } } // Instead of allocating nodes, just shift them // from the input to parent window's list while setting the row // struct spaceNode *snNext; for (sn=nodeList; sn; sn=snNext) { /* Make a space node. If allowing overflow it will all end up in the last row. */ //AllocVar(sn); sn->row = rowIx; //sn->val = val; snNext = sn->next; slAddHead(&sn->parentSs->nodeList, sn); } return nodeList; }
struct spaceNode *spaceSaverAddOverflow(struct spaceSaver *ss, int start, int end, void *val, boolean allowOverflow) /* Add a new node to space saver. Returns NULL if can't fit item in * and allowOverflow == FALSE. If allowOverflow == TRUE then put items * that won't fit in last row. */ { int cellStart, cellEnd, cellWidth; struct spaceRowTracker *srt, *freeSrt = NULL; int rowIx = 0; struct spaceNode *sn; if (ss->isFull) return NULL; if ((start -= ss->winStart) < 0) start = 0; end -= ss->winStart; /* We'll clip this in cell coordinates. */ cellStart = round(start * ss->scale); cellEnd = round(end * ss->scale)+1; if (cellEnd > ss->cellsInRow) cellEnd = ss->cellsInRow; cellWidth = cellEnd - cellStart; /* Find free row. */ for (srt = ss->rowList; srt != NULL; srt = srt->next) { if (allClear(srt->used + cellStart, cellWidth)) { freeSrt = srt; break; } ++rowIx; } /* If no free row make new row. */ if (freeSrt == NULL) { if (ss->rowCount >= ss->maxRows) { /* Abort if too many rows and no overflow allowed. */ if(!allowOverflow) { ss->isFull = TRUE; return NULL; } } else { AllocVar(freeSrt); freeSrt->used = needMem(ss->cellsInRow); slAddTail(&ss->rowList, freeSrt); ++ss->rowCount; } } /* Mark that part of row used (except in overflow case). */ if(freeSrt != NULL) memset(freeSrt->used + cellStart, 1, cellWidth); /* Make a space node. If allowing overflow it will all end up in the last row. */ AllocVar(sn); sn->row = rowIx; sn->val = val; slAddHead(&ss->nodeList, sn); return sn; }