intread(){ int x = 0, f = 1; char ch = getchar(); for(; !isdigit(ch); ch = getchar()) f ^= (ch == '-'); for(; isdigit(ch); ch = getchar()) x = (x << 3) + (x << 1) + (ch xor48); return f ? x : -x; }
intmain(){ T = read(); while(T--){ D = read(), I = read(); int p = 1; // 当前结点编号 for(int i = 1; i < D; ++i){ // 因为1本来就占一层, 接下来只要往下掉D-1层 if(I & 1) p = p << 1, I = (I + 1) >> 1; // 往左走 else p = p << 1 | 1, I = I >> 1; // 往右走 } printf("%d\n", p); } T = read(); // 读不读这个-1无所谓. return0; }
#include<bits/stdc++.h> #define int long long #define N 2000005 #define M 20000005 #define inf 1145141919810LL
int n, m, s, tot; int ver[N], edge[M], nxt[M], head[N], d[N]; bool vis[N];
voidadd(int x, int y, int z){ ver[++tot] = y, edge[tot] = z, nxt[tot] = head[x], head[x] = tot; }
intread(){ int x = 0, f = 1; char ch = getchar(); for(; !isdigit(ch); ch = getchar()) f ^= (ch == '-'); for(; isdigit(ch); ch = getchar()) x = (x << 3) + (x << 1) + (ch xor48); return f? x : -x; }
voiddijkstra(int s){ std::priority_queue<std::pair<int, int> > q; for(int i = 1; i <= n; ++i) d[i] = inf; d[s] = 0; q.push({0, s}); while(q.size()){ int x = q.top().second; q.pop(); if(vis[x]) continue; vis[x] = true; for(int i = head[x]; i; i = nxt[i]){ int y = ver[i], z = edge[i]; if(d[y] > d[x] + z){ d[y] = d[x] + z; q.push({-d[y], y}); } } } }
signedmain(){ n = read(), m = read(), s = read(); for(int i = 1; i <= m; ++i){ int x = read(), y = read(); add(x, y, read()); } dijkstra(s); for(int i = 1; i <= n; ++i) printf("%lld ", d[i] == inf? (1LL << 31) - 1 : d[i]); return0; }
#define N 805 #define M 3000 #define inf 0x7f7f7f7f
int n, p, c, tot, ans = inf; int cow[N]; int head[N], nxt[M], ver[M], edge[M], d[N]; bool vis[N];
voidadd(int x, int y, int z){ ver[++tot] = y, edge[tot] = z, nxt[tot] = head[x], head[x] = tot; }
intread(){ int x = 0, f = 1; char ch = getchar(); for(; !isdigit(ch); ch = getchar()) f ^= (ch == '-'); for(; isdigit(ch); ch = getchar()) x = (x << 3) + (x << 1) + (ch xor48); return f ? x : -x; }
voiddijkstra(int s){ std::priority_queue<std::pair<int, int> > q; memset(d, 0x7f, sizeof(d)); memset(vis, 0, sizeof(vis)); d[s] = 0; q.push({0, s}); while(q.size()){ int x = q.top().second; q.pop(); if(vis[x]) continue; vis[x] = 1; for(int i = head[x]; i; i = nxt[i]){ int y = ver[i], z = edge[i]; if(d[y] > d[x] + z){ d[y] = d[x] + z; q.push({-d[y], y}); } } } }
intmain(){ n = read(), p = read(), c = read(); for(int i = 1; i <= n; ++i) cow[i] = read(); for(int i = 1; i <= c; ++i){ int x = read(), y = read(), z = read(); add(x, y, z); add(y, x, z); } for(int i = 1; i <= p; ++i){ dijkstra(i); int sum = 0; for(int j = 1; j <= n; ++j) sum += d[cow[j]]; ans = ans > sum? sum : ans; } printf("%d\n", ans); return0^(0-0)^0; }
intmain(){ n = read(), m = read(); for(int i = 1; i <= m; ++i){ int x = read(), y = read(); add(x, y); add(y, x); } dijkstra(1); for(int i = 1; i <= n; ++i) printf("%d\n", cnt[i] % mod); return0^(0-0)^0; }
intread(){ int x = 0, f = 1; char ch = getchar(); for(; !isdigit(ch); ch = getchar()) f ^= (ch == '-'); for(; isdigit(ch); ch = getchar()) x = (x << 3) + (x << 1) + (ch xor48); return f? x : -x; }
intmain(){ n = read(); m = read(); for(int i = 1; i <= n; ++i) a[i] = read() << 1; for(int i = 1; i <= m; ++i){ int x = read(), y = read(), v = read(); a[x] += v, a[y] += v; } std::stable_sort(&a[1], &a[n+1]); for(int i = n; i; i -= 2) ans += a[i] - a[i-1]; printf("%lld\n", ans >> 1); return0; }