int t, hp, atk, h, a; auto solve = [&]() -> int { int xx = h / atk; int yy = h - xx*atk; int tt = yy ? xx : xx-1; int dmg = a*tt; cerr << dmg << endl; if (!dmg) return-1; elsereturn hp%dmg ? hp/dmg : hp/dmg-1; };
cin >> t; while (t --) { cin >> hp >> atk >> h >> a; cout << solve() << endl; }
intsolve(int n, int m) { if (n == m) return n; int x = max(n,m), y = min(n,m); if (x == y<<1) return y<<1^1; elseif (x < y<<1) return x+1; elsereturnsolve(x,y<<1)+1; }
int na, nb, nc, nd, m; int x, y, p[13]; for (int i = 0; i <= 12; ++ i) p[i] = i; function<int(int)> father = [&](int ii) -> int { if (p[ii] == ii) return ii; elsereturn p[ii] = father(p[ii]); }; auto join = [&](int x, int y) { int px = father(x), py = father(y); p[px] = py; }; int num[13], cnt = 0, ans = 0; map<int,int> mm;
function<int(int,int,int,int,int)> search = [&](int s, int a,int b, int c, int d) -> int { if (s == cnt) return1; elseif (num[s] > max4(a,b,c,d)) return0; int ret = 0; if (a >= num[s]) ret += search(s+1,a-num[s],b,c,d); if (b >= num[s]) ret += search(s+1,a,b-num[s],c,d); if (c >= num[s]) ret += search(s+1,a,b,c-num[s],d); if (d >= num[s]) ret += search(s+1,a,b,c,d-num[s]); return ret; };
cin >> na >> nb >> nc >> nd >> m; while (m --) { cin >> x >> y; join(x,y); } memset(num,0,sizeof num); for (int i = 1; i <= 12; ++ i) { if (!mm[father(i)]) mm[p[i]] = ++cnt; ++ num[mm[p[i]]]; } cout << search(1,na,nb,nc,nd) << endl;
int na, nb, nc, nd, m; int x, y, p[13]; for (int i = 0; i <= 12; ++ i) p[i] = i; function<int(int)> father = [&](int ii) -> int { if (p[ii] == ii) return ii; elsereturn p[ii] = father(p[ii]); }; auto join = [&](int x, int y) { int px = father(x), py = father(y); p[px] = py; }; int num[13], cnt = 0, ans = 0; map<int,int> mm; int f[13][13][13][13][13];
auto dp = [&] { memset(f, 0, sizeof(f)); f[0][0][0][0][0] = 1; for (int i = 1; i <= cnt; ++ i) for (int a = 0; a <= na; ++ a) for (int b = 0; b <= nb; ++ b) for (int c = 0; c <= nc; ++ c) for (int d = 0; d <= nd; ++ d) { auto &xx = num[i]; if (a + xx <= na) f[i][a+xx][b][c][d] += f[i-1][a][b][c][d]; if (b + xx <= nb) f[i][a][b+xx][c][d] += f[i-1][a][b][c][d]; if (c + xx <= nc) f[i][a][b][c+xx][d] += f[i-1][a][b][c][d]; if (d + xx <= nd) f[i][a][b][c][d+xx] += f[i-1][a][b][c][d]; } return f[cnt][na][nb][nc][nd]; };
cin >> na >> nb >> nc >> nd >> m; while (m --) { cin >> x >> y; join(x,y); } memset(num,0,sizeof num); for (int i = 1; i <= 12; ++ i) { if (!mm[father(i)]) mm[p[i]] = ++cnt; ++ num[mm[p[i]]]; } cout << dp() << endl;
voidaddedge(int u, int v, int w) { ee[tot] = edge(u,v,w,head[u]); head[u] = tot ++; ee[tot] = edge(v,u,w,tail[v]); tail[v] = tot ++; } }
namespace dij { usingnamespace FWS;
bool vis[N]; longs ds[N], dt[N];
voiddijkstra(int goal) { priority_queue<pair<longs ,int>> q; int* li = goal == n ? tail : head; longs* dis = goal == n ? dt : ds;
q.push(make_pair(0, goal)); memset(vis,0, sizeof(bool)*(n+1)); memset(dis,0x3f, sizeof(longs)*(n+1)); dis[goal] = 0; while (!q.empty()) { int u = q.top().second; q.pop(); if (vis[u]) continue; vis[u] = true; for (int c = li[u]; ~c; c = ee[c].next) { edge& e = ee[c]; int v = e.v; if (dis[v] >= dis[u] + e.w) q.push(make_pair( -(dis[v] = dis[u] + e.w), v )); } } } }
intmain() { ios::sync_with_stdio(false); cin.tie(nullptr); using dij::dijkstra;
int u, v, c; int x, q;
cin >> n >> m; FWS::init(); while (m --) { cin >> u >> v >> c; FWS::addedge(u,v,c); } dijkstra(1); dijkstra(n); const longs shortest = dij::ds[n];
cin >> q; while (q --) { cin >> x; auto& ii = FWS::ee[(x-1)<<1]; longs to = dij::ds[ii.v] + dij::dt[ii.u] + ii.w; if (to < shortest) cout << "YES" << endl; else cout << "NO" << endl; }
auto check = [&](int mid) -> bool { if (mid == 0) returntrue; using StringHash::getHashCode; static unordered_map<ulongs, int> map; int ret = 0, lim = n - mid; for (int i = 0; i <= lim; ++ i) { if (i - mid >= 0) map[getHashCode(i - mid, i)] = i - mid; ulongs hashcode = getHashCode(i, i + mid); ff[i] = map.count(hashcode) ? ff[map[hashcode]] + 1 : 1; ret = max(ret, ff[i]); } map.clear(); return ret >= k; };
cin >> n >> k >> s; StringHash::init(s);
int ll = 0, rr = n, ans = 0; check(0); while (ll <= rr) { int mm = ll + rr >> 1; if (check(mm)) ans = mm, ll = ++ mm; else rr = -- mm; } cout << ans << endl;