999ms

Untitled

Dec 10th, 2020
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.02 KB | None | 0 0
  1. // TASK 8
  2. #include<bits/stdc++.h>
  3. #define all(x) begin(x),end(x)
  4.  
  5. using namespace std;
  6.  
  7. using ll = long long;
  8. using lll = __int128;
  9. using ld = long double;
  10. using pt = pair<int, int>;
  11.  
  12.  
  13. int main() {
  14. ios_base::sync_with_stdio(false);
  15. cin.tie(nullptr);
  16. cout.tie(nullptr);
  17. ll a, b, c, d;
  18. cin >> a >> b >> c >> d;
  19. // a / b <= sqrt(x)
  20. // a <= sqrt(x) * b
  21. // a * a <= x * b * b
  22.  
  23. // sqrt(x) * d <= c
  24. // x * d * d <= c * c
  25.  
  26. ll left = 0;
  27. ll right = 2e18;
  28. ll mid;
  29. ll left_ans = 2e18;
  30. while (left <= right) {
  31. mid = (left + right) >> 1;
  32. if (lll(a) * a <= lll(mid) * b * b) {
  33. left_ans = mid;
  34. right = mid - 1;
  35. } else {
  36. left = mid + 1;
  37. }
  38. }
  39.  
  40. left = 0;
  41. right = 2e18;
  42. ll right_ans = -1;
  43.  
  44. while (left <= right) {
  45. mid = (left + right) >> 1;
  46. if (lll(mid) * d * d <= lll(c) * c) {
  47. right_ans = mid;
  48. left = mid + 1;
  49. } else {
  50. right = mid - 1;
  51. }
  52. }
  53.  
  54. ll answer = right_ans - left_ans + 1;
  55. if (answer < 0) answer = 0;
  56. cout << answer << '\n';
  57. }
  58.  
  59. // TASK 9
  60. #include<bits/stdc++.h>
  61. #define all(x) begin(x),end(x)
  62.  
  63. using namespace std;
  64.  
  65. using ll = long long;
  66. using lll = __int128;
  67. using ld = long double;
  68. using pt = pair<int, int>;
  69.  
  70.  
  71. int main() {
  72. ios_base::sync_with_stdio(false);
  73. cin.tie(nullptr);
  74. cout.tie(nullptr);
  75. ll x, y;
  76. ll a, b, c, d;
  77. cin >> x >> y;
  78. cin >> a >> b >> c >> d;
  79.  
  80. ll answer = min({
  81. a - 0,
  82. x - c,
  83. b - 0,
  84. y - d
  85. });
  86. cout << answer << '\n';
  87. }
  88.  
  89. // TASK 10
  90. #include<bits/stdc++.h>
  91. #define all(x) begin(x),end(x)
  92.  
  93. using namespace std;
  94.  
  95. using ll = long long;
  96. using lll = __int128;
  97. using ld = long double;
  98. using pt = pair<int, int>;
  99.  
  100.  
  101. int main() {
  102. ios_base::sync_with_stdio(false);
  103. cin.tie(nullptr);
  104. cout.tie(nullptr);
  105. int l, r;
  106. cin >> l >> r;
  107. vector<int> cnt(r + 1);
  108. for (int i = 1; i <= r; i++) {
  109. for (int j = i; j <= r; j += i) {
  110. cnt[j]++;
  111. }
  112. }
  113. vector<int> ans(r - l + 1);
  114. iota(all(ans), l);
  115. sort(all(ans), [&] (int a, int b) {
  116. return cnt[a] < cnt[b] || (cnt[a] == cnt[b] && a < b);
  117. });
  118. for (int val : ans) {
  119. cout << val << ' ';
  120. }
  121. cout << '\n';
  122. }
  123.  
  124.  
  125. // TASK 11
  126. #include<bits/stdc++.h>
  127. #define all(x) begin(x),end(x)
  128.  
  129. using namespace std;
  130.  
  131. using ll = long long;
  132. using lll = __int128;
  133. using ld = long double;
  134. using pt = pair<int, int>;
  135.  
  136. ll dp[1 << 15];
  137. pair<int,int> arr[15];
  138.  
  139. int Dist(int i, int j) {
  140. int dx = arr[i].first - arr[j].first;
  141. int dy = arr[i].second - arr[j].second;
  142. return dx * dx + dy * dy;
  143. }
  144.  
  145. bool good(int i, int j, int k) {
  146. int dx1 = arr[i].first - arr[j].first;
  147. int dy1 = arr[i].second - arr[j].second;
  148. int dx2 = arr[i].first - arr[k].first;
  149. int dy2 = arr[i].second - arr[k].second;
  150. return dx1 * dy2 - dx2 * dy1 != 0;
  151. }
  152.  
  153. int main() {
  154. ios_base::sync_with_stdio(false);
  155. cin.tie(nullptr);
  156. cout.tie(nullptr);
  157. int n;
  158. cin >> n;
  159. memset(dp, 0x3f, sizeof dp);
  160. for (int i = 0; i < n; i++) {
  161. cin >> arr[i].first >> arr[i].second;
  162. }
  163. for (int i = 0; i < n; i++) {
  164. for (int j = i + 1; j < n; j++) {
  165. for (int k = j + 1; k < n; k++) {
  166. int mask = (1 << i) | (1 << k) | (1 << j);
  167. int a = Dist(i, j);
  168. int b = Dist(i, k);
  169. int c = Dist(j, k);
  170. int cur = max({a, b, c});
  171.  
  172. if (good(i, j, k)) {
  173. dp[mask] = cur;
  174. }
  175. }
  176. }
  177. }
  178. // 2 ^ 15 * 15 * 15 * 15 / 6
  179. for (int mask = 0; mask < (1 << n); mask++) {
  180. int cnt = __builtin_popcount(mask);
  181. if (cnt < 3) continue;
  182. if (cnt % 3) continue;
  183. for (int i = 0; i < n; i++) {
  184. if (!((mask >> i) & 1)) continue;
  185. for (int j = i + 1; j < n; j++) {
  186. if (!((mask >> j) & 1)) continue;
  187. for (int k = j + 1; k < n; k++) {
  188. if (!((mask >> k) & 1)) continue;
  189. dp[mask] = min(dp[mask], max(dp[mask ^ (1 << i) ^ (1 << j) ^ (1 << k)], dp[(1 << i) ^ (1 << j) ^ (1 << k)]));
  190. }
  191. }
  192. }
  193. }
  194. ll res = dp[(1 << n) - 1];
  195. if (res > 1e9) {
  196. cout << -1 << '\n';
  197. } else {
  198. cout << fixed << setprecision(15) << sqrt(res) << '\n';
  199. }
  200. }
  201.  
  202.  
  203. // TASK 12
  204. #include<bits/stdc++.h>
  205. #define all(x) begin(x),end(x)
  206.  
  207. using namespace std;
  208.  
  209. using ll = long long;
  210. using lll = __int128;
  211. using ld = long double;
  212. using pt = pair<int, int>;
  213.  
  214. const int N = 200200;
  215.  
  216. vector<int> g[N];
  217. bool used[N];
  218. int timer, tin[N], fup[N];
  219. bool cut[N];
  220.  
  221. void Dfs(int v, int p) {
  222. used[v] = true;
  223. tin[v] = fup[v] = timer++;
  224. int children = 0;
  225. for (int to : g[v]) {
  226. if (to == p) continue;
  227. if (used[to]) {
  228. fup[v] = min(fup[v], tin[to]);
  229. } else {
  230. Dfs(to, v);
  231. fup[v] = min (fup[v], fup[to]);
  232. if (fup[to] >= tin[v] && p != -1) {
  233. cut[v] = true;
  234. }
  235. ++children;
  236. }
  237. }
  238. if (p == -1 && children > 1) {
  239. cut[v] = true;
  240. }
  241. }
  242. int main() {
  243. ios_base::sync_with_stdio(false);
  244. cin.tie(nullptr);
  245. cout.tie(nullptr);
  246. int n;
  247. cin >> n;
  248. int m;
  249. cin >> m;
  250. vector<pair<int,int>> edges;
  251. for (int i = 0; i < m; i++) {
  252. int f, t;
  253. cin >> f >> t;
  254. f--, t--;
  255. g[f].push_back(t);
  256. g[t].push_back(f);
  257. edges.push_back({f, t});
  258. }
  259. Dfs(0, -1);
  260. vector<int> ans;
  261. for (int i = 0; i < m; i++) {
  262. auto& [f, t] = edges[i];
  263. if (cut[f] && cut[t]) {
  264. ans.push_back(i + 1);
  265. }
  266. }
  267. cout << ans.size() << '\n';
  268. for (int val : ans) {
  269. cout << val << ' ';
  270. }
  271. cout << '\n';
  272. }
  273.  
  274.  
Add Comment
Please, Sign In to add comment