bign divisor = *this, divid = num; divisor.sign = divid.sign = 1; int k = ans.len - 1; int j = len - 1; while (k >= 0) { while (divisor.s[j] == 0) j--; if (k > j) k = j; char z[MAX_L]; memset(z, 0, sizeof(z)); for (int i = j; i >= k; i--) z[j - i] = divisor.s[i] + '0'; bign dividend = z; if (dividend < divid) { k--; continue; } int key = 0; while (divid * key <= dividend) key++; key--; ans.s[k] = key; bign temp = divid * key; for (int i = 0; i < k; i++) temp = temp * 10; divisor = divisor - temp; k--; } ans.clean(); ans.sign = !(sign ^ num.sign); return ans; } bign bign::operator/=(const bign &num) { *this = *this / num; return *this; } bign bign::operator%(const bign &num) const { bign a = *this, b = num; a.sign = b.sign = 1; bign result, temp = a / b * b; result = a - temp; result.sign = sign; return result; } bign bign::pow(const bign &num)const { bign result = 1; for (bign i = 0; i < num; i++) result = result * (*this); return result; } bign bign::factorial()const { bign result = 1; for (bign i = 1; i <= *this; i++) result *= i; return result; } voidbign::clean() { if (len == 0) len++; while (len > 1 && s[len - 1] == '\0') len--; } bign bign::Sqrt()const { if (*this < 0) return-1; if (*this <= 1) return *this; bign l = 0, r = *this, mid; while (r - l > 1) { mid = (l + r) / 2; if (mid * mid > *this) r = mid; else l = mid; } return l; } bign::~bign() {}
inline bign quickmi(ll xx, ll n) { bign x = xx, res = 1; for (; n; n >>= 1) { if (n & 1) res *= x; x *= x; } return res; }
stack<bign> s; string str;
bign solve() { bign ans = 0, sum = 0; for (int i = 0; i < str.length(); i++) { if (str[i] == ')') { sum = 0; while (s.top() != -1) { sum += s.top(); s.pop(); } s.pop(); s.pop(); bign tmp = 1; while (sum > 0) { sum = sum - 1; tmp = tmp * 2; }
#include<bits/stdc++.h> #define ll long long usingnamespacestd; const ll mod = 1e9 + 7; constint INF = 0x3f3f3f3f; const ll INF_LL = 0x3f3f3f3f3f3f3f3f; constdouble eqs = 1e-5; constint maxn = 1e5 + 10; constint maxm = 1e5 + 10; intread() { int x = 0, flag = 0; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') flag = 1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar(); } if (flag) return -x; return x; } int t, n, m, k; int a[maxn];
structEdge { int v, w, next; } edge[maxm << 1]; int head[maxn], cnt; bool vis[maxn]; inlinevoidaddEdge(int u, int v, int w) { ++cnt; edge[cnt] = {v, w, head[u]}; head[u] = cnt; }
structNode { int id; ll c, g; } dp[maxn];
boolcmp(Node a, Node b) { if (a.g > a.c) if (b.g > b.c) return a.c < b.c; else returntrue; elseif (b.g > b.c) returnfalse; else return a.g > b.g; }
voiddfs(int u, int p) { vector<Node> comp; for(int i = head[u]; i; i = edge[i].next) { int v = edge[i].v; if(v == p) continue; dfs(v, u); dp[v].id = v; dp[v].c += edge[i].w; dp[v].g -= edge[i].w; if(dp[v].g < 0) dp[v].c -= dp[v].g, dp[v].g = 0; comp.push_back(dp[v]); } sort(comp.begin(), comp.end(), cmp);
dp[u].c = 0; ll now = a[u]; for(int i = 0; i < comp.size(); i++) { auto v = comp[i]; now -= v.c; if(now < 0) { dp[u].c -= now; now = 0; } now += v.g; } dp[u].g = now; }
intmain() { // #define COMP_DATA #ifndef ONLINE_JUDGE #ifdef COMP_DATA freopen("/mnt/f/文档/课件/ACM比赛/2020hdu多校/第四场/data/E.in", "r", stdin); freopen("out.txt", "w", stdout); #else freopen("in.txt", "r", stdin); #endif #endif t = read(); while (t--) { cnt = 0; n = read(); for (int i = 1; i <= n; i++) a[i] = read(), head[i] = 0;
for (int i = 1, u, v, w; i < n; i++) { u = read(), v = read(), w = read(); addEdge(u, v, w), addEdge(v, u, w); } dfs(1, 0); printf("%lld\n", dp[1].c); } return0; }
#include<bits/stdc++.h> #define ll long long usingnamespacestd; const ll mod = 1e9 + 7; constint INF = 0x3f3f3f3f; const ll INF_LL = 0x3f3f3f3f3f3f3f3f; constdouble eqs = 1e-5; constint maxn = 2e6 + 10; constint maxm = 1e5 + 10; intread() { int x = 0, flag = 0; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') flag = 1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar(); } if (flag) return -x; return x; }
int t, n, m, k;
structNode { int a, id; booloperator<(const Node& x) const { return a < x.a; } }node[maxn]; int tot[maxn]; intmain() { // #define COMP_DATA #ifndef ONLINE_JUDGE #ifdef COMP_DATA freopen("/mnt/f/文档/课件/ACM比赛/2020hdu多校/第四场/data/E.in", "r", stdin); freopen("out.txt", "w", stdout); #else freopen("in.txt", "r", stdin); #endif #endif n = read(); m = read(); int k; int cnt = 0; for (int i = 1; i <= n; i++) { k = read(); while(k--) { node[++cnt].a = read(); node[cnt].id = i; } } sort(node + 1, node + 1 + cnt); int l = 1, r = 1; int p = 0; int ans = 1e9; while (r <= cnt && l <= r) { while(p < m && r <= cnt) { if(!tot[node[r].id]) { p++; } tot[node[r].id]++; r++; } while (p == m && l <= r) {
usingnamespacestd; using longs = longlong; using uint = unsigned;
inlineintnextInt() { int x = 0, f = 0, ch = getchar(); while (!isdigit(ch)) ch == '-' && (f = 1), ch = getchar(); while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar(); return f ? -x : x; }
constint N = 1e5 + 5; int cnt[10];
intmain() { ios::sync_with_stdio(false);
int t = nextInt(); while (t --) { memset(cnt, 0, sizeof cnt); int n = nextInt(), xx = 0, yy = 0; while (n --) ++ cnt[nextInt()]; for (int i = 1; i < 10; ++ i) if (cnt[i]) {-- cnt[i], xx = i; break;} for (int i = 1; i < 10; ++ i) if (cnt[i]) {-- cnt[i], yy = i; break;} string s; s.append(1, yy + '0'); s.append(cnt[0], '0'); for (int i = 1; i < 10; ++ i) s.append(cnt[i], i + '0'); int top = 0, len = s.length(); while (-- len >= 0) { auto _this = s[len] - '0'; auto _tmp = _this * xx + top; top = _tmp / 10; s[len] = _tmp % 10 + '0'; } if (top) printf("%d", top); printf("%s\n", s.c_str()); }