/* init_char_type */ static void init_char_type(void) { fill_range(0, 255, C_WHITE); fill_range('A', 'Z', C_ALPHA); fill_range('a', 'z', C_ALPHA); type_info['_'] = C_ALPHA; fill_range('0', '9', C_DIGIT); type_info['!'] = C_OPERATOR; type_info['#'] = C_OPERATOR; type_info['$'] = C_OPERATOR; type_info['%'] = C_OPERATOR; type_info['^'] = C_OPERATOR; type_info['&'] = C_OPERATOR; type_info['*'] = C_OPERATOR; type_info['-'] = C_OPERATOR; type_info['+'] = C_OPERATOR; type_info['='] = C_OPERATOR; type_info['|'] = C_OPERATOR; type_info['~'] = C_OPERATOR; type_info[','] = C_OPERATOR; type_info[':'] = C_OPERATOR; type_info['?'] = C_OPERATOR; type_info['.'] = C_OPERATOR; type_info['<'] = C_OPERATOR; type_info['>'] = C_OPERATOR; type_info['/'] = C_SLASH; type_info['\n'] = C_NEWLINE; type_info['('] = C_L_PAREN; type_info[')'] = C_R_PAREN; type_info['{'] = C_L_CURLY; type_info['}'] = C_R_CURLY; type_info['"'] = C_DOUBLE; type_info['\''] = C_SINGLE; }
void dijkstra(int source) { fill_range(dist, dist + graph.vertex_num, INF); // \SourceRef{source:utility} fill_range(prev, prev + graph.vertex_num, -1); fill_range<Edge *>(path, path + graph.vertex_num, NULL); dist[source] = 0; std::set<int, bool(*)(int ,int)> queue(dijkstra_compare); // use binary heap for (int vi = 0; vi < graph.vertex_num; ++vi) { queue.insert(vi); } for (; !queue.empty(); ) { int u = *queue.begin(); queue.erase(u); for (SPEdge * edge = graph.head[u]; edge != NULL; edge = edge->next) { if (queue.count(edge->v) > 0 && dist[edge->u] + edge->w < dist[edge->v]) { queue.erase(edge->v); dist[edge->v] = dist[edge->u] + edge->w; prev[edge->v] = edge->u; path[edge->v] = edge; queue.insert(edge->v); } } } }
bool find_dijkstra() { fill_range(cost, cost + graph.vertex_num, INF); // \SourceRef{source:utility} fill_range(prev, prev + graph.vertex_num, -1); fill_range<Edge *>(path, path + graph.vertex_num, NULL); cost[source] = 0; std::set<int, bool(*)(int ,int)> queue(dijkstra_compare); for (int vi = 0; vi < graph.vertex_num; ++vi) { queue.insert(vi); } for (; !queue.empty(); ) { int u = *queue.begin(); queue.erase(u); for (Edge * edge = graph.head[u]; edge != NULL; edge = edge->next) { if (queue.count(edge->v) > 0 && edge->flow < edge->capacity && cost[edge->u] + edge->cost < cost[edge->v]) { queue.erase(edge->v); cost[edge->v] = cost[edge->u] + edge->cost; prev[edge->v] = edge->u; path[edge->v] = edge; queue.insert(edge->v); } } } return cost[sink] != INF; }
int main(int argc, char **argv) { int *A; if (argc != 2 && argc != 4) { printf("Usage: ./rgen n (numbers) (from) x (to) y (x and y are optional)\n"); return 0; } else { A = (int*) malloc (atoi(argv[1]) * sizeof (int)); if (argc == 2) fill(A, atoi(argv[1])); else fill_range(A, atoi(argv[1]), atoi(argv[2]), atoi(argv[3])); } print(A, atoi(argv[1])); free(A); return 0; }
void fill(LPXLOPER12 excelArray, const std::vector<T>&... args) { auto tuple = std::tuple<const std::vector<T>&...>(args...); auto rows = std::get<0>(tuple).size(); auto cols = sizeof...(args); int rwcol = cols * rows; LPXLOPER12 pxArray = new XLOPER12[rwcol]; excelArray->val.array.columns = cols; excelArray->val.array.rows = rows; excelArray->xltype = xltypeMulti | xlbitDLLFree; excelArray->val.array.lparray = pxArray; int n = 0; int dummy[sizeof...(args)] = { (fill_range(excelArray, n++, args), 0)... }; }