Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // TASK 8
- #include<bits/stdc++.h>
- #define all(x) begin(x),end(x)
- using namespace std;
- using ll = long long;
- using lll = __int128;
- using ld = long double;
- using pt = pair<int, int>;
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- ll a, b, c, d;
- cin >> a >> b >> c >> d;
- // a / b <= sqrt(x)
- // a <= sqrt(x) * b
- // a * a <= x * b * b
- // sqrt(x) * d <= c
- // x * d * d <= c * c
- ll left = 0;
- ll right = 2e18;
- ll mid;
- ll left_ans = 2e18;
- while (left <= right) {
- mid = (left + right) >> 1;
- if (lll(a) * a <= lll(mid) * b * b) {
- left_ans = mid;
- right = mid - 1;
- } else {
- left = mid + 1;
- }
- }
- left = 0;
- right = 2e18;
- ll right_ans = -1;
- while (left <= right) {
- mid = (left + right) >> 1;
- if (lll(mid) * d * d <= lll(c) * c) {
- right_ans = mid;
- left = mid + 1;
- } else {
- right = mid - 1;
- }
- }
- ll answer = right_ans - left_ans + 1;
- if (answer < 0) answer = 0;
- cout << answer << '\n';
- }
- // TASK 9
- #include<bits/stdc++.h>
- #define all(x) begin(x),end(x)
- using namespace std;
- using ll = long long;
- using lll = __int128;
- using ld = long double;
- using pt = pair<int, int>;
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- ll x, y;
- ll a, b, c, d;
- cin >> x >> y;
- cin >> a >> b >> c >> d;
- ll answer = min({
- a - 0,
- x - c,
- b - 0,
- y - d
- });
- cout << answer << '\n';
- }
- // TASK 10
- #include<bits/stdc++.h>
- #define all(x) begin(x),end(x)
- using namespace std;
- using ll = long long;
- using lll = __int128;
- using ld = long double;
- using pt = pair<int, int>;
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- int l, r;
- cin >> l >> r;
- vector<int> cnt(r + 1);
- for (int i = 1; i <= r; i++) {
- for (int j = i; j <= r; j += i) {
- cnt[j]++;
- }
- }
- vector<int> ans(r - l + 1);
- iota(all(ans), l);
- sort(all(ans), [&] (int a, int b) {
- return cnt[a] < cnt[b] || (cnt[a] == cnt[b] && a < b);
- });
- for (int val : ans) {
- cout << val << ' ';
- }
- cout << '\n';
- }
- // TASK 11
- #include<bits/stdc++.h>
- #define all(x) begin(x),end(x)
- using namespace std;
- using ll = long long;
- using lll = __int128;
- using ld = long double;
- using pt = pair<int, int>;
- ll dp[1 << 15];
- pair<int,int> arr[15];
- int Dist(int i, int j) {
- int dx = arr[i].first - arr[j].first;
- int dy = arr[i].second - arr[j].second;
- return dx * dx + dy * dy;
- }
- bool good(int i, int j, int k) {
- int dx1 = arr[i].first - arr[j].first;
- int dy1 = arr[i].second - arr[j].second;
- int dx2 = arr[i].first - arr[k].first;
- int dy2 = arr[i].second - arr[k].second;
- return dx1 * dy2 - dx2 * dy1 != 0;
- }
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- int n;
- cin >> n;
- memset(dp, 0x3f, sizeof dp);
- for (int i = 0; i < n; i++) {
- cin >> arr[i].first >> arr[i].second;
- }
- for (int i = 0; i < n; i++) {
- for (int j = i + 1; j < n; j++) {
- for (int k = j + 1; k < n; k++) {
- int mask = (1 << i) | (1 << k) | (1 << j);
- int a = Dist(i, j);
- int b = Dist(i, k);
- int c = Dist(j, k);
- int cur = max({a, b, c});
- if (good(i, j, k)) {
- dp[mask] = cur;
- }
- }
- }
- }
- // 2 ^ 15 * 15 * 15 * 15 / 6
- for (int mask = 0; mask < (1 << n); mask++) {
- int cnt = __builtin_popcount(mask);
- if (cnt < 3) continue;
- if (cnt % 3) continue;
- for (int i = 0; i < n; i++) {
- if (!((mask >> i) & 1)) continue;
- for (int j = i + 1; j < n; j++) {
- if (!((mask >> j) & 1)) continue;
- for (int k = j + 1; k < n; k++) {
- if (!((mask >> k) & 1)) continue;
- dp[mask] = min(dp[mask], max(dp[mask ^ (1 << i) ^ (1 << j) ^ (1 << k)], dp[(1 << i) ^ (1 << j) ^ (1 << k)]));
- }
- }
- }
- }
- ll res = dp[(1 << n) - 1];
- if (res > 1e9) {
- cout << -1 << '\n';
- } else {
- cout << fixed << setprecision(15) << sqrt(res) << '\n';
- }
- }
- // TASK 12
- #include<bits/stdc++.h>
- #define all(x) begin(x),end(x)
- using namespace std;
- using ll = long long;
- using lll = __int128;
- using ld = long double;
- using pt = pair<int, int>;
- const int N = 200200;
- vector<int> g[N];
- bool used[N];
- int timer, tin[N], fup[N];
- bool cut[N];
- void Dfs(int v, int p) {
- used[v] = true;
- tin[v] = fup[v] = timer++;
- int children = 0;
- for (int to : g[v]) {
- if (to == p) continue;
- if (used[to]) {
- fup[v] = min(fup[v], tin[to]);
- } else {
- Dfs(to, v);
- fup[v] = min (fup[v], fup[to]);
- if (fup[to] >= tin[v] && p != -1) {
- cut[v] = true;
- }
- ++children;
- }
- }
- if (p == -1 && children > 1) {
- cut[v] = true;
- }
- }
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- int n;
- cin >> n;
- int m;
- cin >> m;
- vector<pair<int,int>> edges;
- for (int i = 0; i < m; i++) {
- int f, t;
- cin >> f >> t;
- f--, t--;
- g[f].push_back(t);
- g[t].push_back(f);
- edges.push_back({f, t});
- }
- Dfs(0, -1);
- vector<int> ans;
- for (int i = 0; i < m; i++) {
- auto& [f, t] = edges[i];
- if (cut[f] && cut[t]) {
- ans.push_back(i + 1);
- }
- }
- cout << ans.size() << '\n';
- for (int val : ans) {
- cout << val << ' ';
- }
- cout << '\n';
- }
Add Comment
Please, Sign In to add comment