Advertisement
Galebickosikasa

Untitled

Jun 16th, 2021
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.58 KB | None | 0 0
  1. task 2
  2.  
  3. int imp (int a, int b) {
  4. if (a == 1 && b == 0) return 0;
  5. return 1;
  6. }
  7.  
  8. signed main () {
  9. ios_base::sync_with_stdio (0);
  10. cin.tie (0);
  11. fr (x, 2) {
  12. fr (y, 2) {
  13. fr (z, 2) {
  14. fr (w, 2) {
  15. int a = imp (y, w);
  16. int b = imp (x, 1 - z);
  17. int c = a == b;
  18. int d = x || w;
  19. int e = c && d;
  20. cerr << x << ' ' << y << ' ' << z << ' ' << w << ' ' << e << '\n';
  21. }
  22. }
  23. }
  24. }
  25. }
  26.  
  27. task 5
  28.  
  29. int kek (int n) {
  30. vector<int> goo;
  31. while (n) {
  32. goo.pb (n % 2);
  33. n /= 2;
  34. }
  35. reverse (all (goo));
  36. while (!goo.empty () && goo.back () == 0) goo.pop_back ();
  37. int ans = 0;
  38. fr (i, sz (goo)) ans += (1<<i) * goo[i];
  39. return ans;
  40. }
  41.  
  42. signed main () {
  43. ios_base::sync_with_stdio (0);
  44. cin.tie (0);
  45. for (int i = 100; i > 0; --i) {
  46. if (kek (i) == 13) {
  47. dbg (i);
  48. exit (0);
  49. }
  50. }
  51. }
  52.  
  53. task 6
  54.  
  55. int kek (int s) {
  56. int n = 1;
  57. while (s > 200) {
  58. s -= 15;
  59. n += 3;
  60. }
  61. return n;
  62. }
  63.  
  64. signed main () {
  65. ios_base::sync_with_stdio (0);
  66. cin.tie (0);
  67. for (int i = 10000; i > 0; --i) {
  68. if (kek (i) == 46) {
  69. dbg (i);
  70. exit (0);
  71. }
  72. }
  73. }
  74.  
  75. task 8
  76.  
  77. signed main () {
  78. ios_base::sync_with_stdio (0);
  79. cin.tie (0);
  80. string s = "OLQGA";
  81. sort (all (s));
  82. int ans = 0;
  83. do {
  84. int f = 1;
  85. if (s.front () == 'Q') f = 0;
  86. else {
  87. fl (i, 1, sz (s)) {
  88. if (s[i] == 'Q') {
  89. if (s[i - 1] == 'O' || s[i - 1] == 'A') f = 0;
  90. }
  91. }
  92. }
  93. ans += f;
  94. } while (next_permutation (all (s)));
  95. dbg (ans);
  96. }
  97.  
  98. task 14
  99.  
  100. x = 343 ** 5 + 343 ** 4 + 49 ** 6 - 7 ** 13 - 21
  101. a = set ()
  102. while (x > 0):
  103. a.add (x % 7)
  104. x //= 7
  105. # print (a)
  106. print (len (a))
  107.  
  108. task 15
  109.  
  110. int check (int a, int x, int y) {
  111. int b = y > a;
  112. int c = x > a;
  113. int d = x * y < 120;
  114. return b || c || d;
  115. }
  116.  
  117. signed main () {
  118. ios_base::sync_with_stdio (0);
  119. cin.tie (0);
  120. for (int a = 10000; a >= 0; --a) {
  121. int f = 1;
  122. fr (x, 1000) fr (y, 1000) f &= check (a, x, y);
  123. if (f) {
  124. dbg (a);
  125. exit (0);
  126. }
  127. }
  128. }
  129.  
  130. task 16
  131.  
  132. int g(int);
  133.  
  134. int f (int n) {
  135. if (n == 1) return 1;
  136. return 2 * f (n - 1) - g (n - 1);
  137. }
  138.  
  139. int g (int n) {
  140. if (n == 1) return 1;
  141. return f (n - 1) + 2 * g (n - 1);
  142. }
  143.  
  144. signed main () {
  145. ios_base::sync_with_stdio (0);
  146. cin.tie (0);
  147. dbg (g (25) + f (25));
  148.  
  149. }
  150.  
  151. task 17
  152.  
  153. signed main () {
  154. ios_base::sync_with_stdio (0);
  155. cin.tie (0);
  156. int cnt = 0, mx = 0;
  157. fl (i, 100, 10000 + 1) {
  158. if (i % 10 == 3) {
  159. if (i % 8 == 7) {
  160. vector<int> a{13, 16, 19};
  161. int f = 1;
  162. for (auto& x: a) if (i % x == 0) f = 0;
  163. if (f && i % 21 == 0) {
  164. ++cnt;
  165. mx = i;
  166. }
  167. }
  168. }
  169. }
  170. dbg (cnt);
  171. dbg (mx);
  172. }
  173.  
  174. task 18
  175.  
  176. const int n = 12;
  177.  
  178. array <array <int, n>, n> goo, dp1, dp2;
  179.  
  180. signed main () {
  181. ios_base::sync_with_stdio (0);
  182. cin.tie (0);
  183. for (auto& v: goo) for (auto& x: v) cin >> x;
  184.  
  185. fr (i, n) fr (j, n) {
  186. int mx = 0, mn = 1e9;
  187. if (goo[i][j] > 100) {
  188. dp1[i][j] = -1e18;
  189. dp2[i][j] = 1e18;
  190. continue;
  191. }
  192. if (i > 0) {
  193. mx = max (mx, dp1[i - 1][j]);
  194. mn = min (mn, dp2[i - 1][j]);
  195. }
  196. if (j > 0) {
  197. mx = max (mx, dp1[i][j - 1]);
  198. mn = min (mn, dp2[i][j - 1]);
  199. }
  200. dp1[i][j] = mx + goo[i][j], dp2[i][j] = mn + goo[i][j];
  201. if (mn == 1e9) dp1[i][j] = dp2[i][j] = goo[i][j];
  202. }
  203. cout << dp1[n - 1][n - 1] << ' ' << dp2[n - 1][n - 1] << '\n';
  204. }
  205.  
  206. task 20
  207.  
  208. array <array <int, 100>, 100> dp;
  209.  
  210. vector<pair<int, int>> gen (int a, int b) {
  211. return {{a + 1, b}, {a * 2, b}, {a, b + 1}, {a, b * 2}};
  212. }
  213.  
  214. int calc (int a, int b) {
  215. if (a + b >= 39) return 0;
  216. if (dp[a][b] != -1) return dp[a][b];
  217. auto t = gen (a, b);
  218. int cnt = 0;
  219. for (auto& x: t) cnt += calc (x.first, x.second);
  220. if (cnt == sz (t)) return dp[a][b] = 0;
  221. return dp[a][b] = 1;
  222. }
  223.  
  224. signed main () {
  225. ios_base::sync_with_stdio (0);
  226. cin.tie (0);
  227. for (auto& v: dp) for (auto& x: v) x = -1;
  228.  
  229. fl (i, 1, 30) {
  230. if (calc (i, 9)) {
  231. auto t = gen (i, 9);
  232. int f = 0;
  233. for (auto& x: t) {
  234. if (x.first + x.second >= 39) f = 1;
  235. }
  236. if (!f) {
  237. // dbg (make_pair (i, 9));
  238. f = 0;
  239. for (auto& x: t) {
  240. if (calc (x.first, x.second)) continue;
  241. // dbg (x);
  242. int c = 0;
  243. auto tt = gen (x.first, x.second);
  244. for (auto& xx: tt) {
  245. // dbg (xx);
  246. int ff = 0;
  247. auto ttt = gen (xx.first, xx.second);
  248. for (auto& xxx: ttt) {
  249. if (xxx.first + xxx.second >= 39) ff = 1;
  250. // dbg (xxx);
  251. }
  252. c += ff;
  253. }
  254. if (c == sz (tt)) f = 1;
  255. }
  256. if (f) {
  257. cout << i << ' ';
  258. // exit (0);
  259. }
  260. }
  261. }
  262. }
  263. }
  264.  
  265. task 21
  266.  
  267. array <array <int, 100>, 100> dp;
  268.  
  269. vector<pair<int, int>> gen (int a, int b) {
  270. return {{a + 1, b}, {a * 2, b}, {a, b + 1}, {a, b * 2}};
  271. }
  272.  
  273. int calc (int a, int b) {
  274. if (a + b >= 39) return 0;
  275. if (dp[a][b] != -1) return dp[a][b];
  276. auto t = gen (a, b);
  277. int cnt = 0;
  278. for (auto& x: t) cnt += calc (x.first, x.second);
  279. if (cnt == sz (t)) return dp[a][b] = 0;
  280. return dp[a][b] = 1;
  281. }
  282.  
  283. signed main () {
  284. ios_base::sync_with_stdio (0);
  285. cin.tie (0);
  286. for (auto& v: dp) for (auto& x: v) x = -1;
  287.  
  288. fl (i, 1, 30) {
  289. if (!calc (i, 9)) {
  290. auto t = gen (i, 9);
  291. int cnt1 = 0, j = 0;
  292. vector<int> used (sz (t));
  293. for (auto& x: t) {
  294. int f = 0;
  295. auto tt = gen (x.first, x.second);
  296. for (auto& xx: tt) {
  297. if (xx.first + xx.second >= 39) f = 1;
  298. }
  299. cnt1 += f;
  300. used[j] = f;
  301. ++j;
  302. }
  303. if (cnt1 > 0 && cnt1 < sz (t)) {
  304. j = 0;
  305. for (auto& x: t) {
  306. if (!used[j]) {
  307. int f = 0;
  308. auto tt = gen (x.first, x.second);
  309. for (auto& xx: tt) {
  310. if (calc (xx.first, xx.second)) continue;
  311. int c = 0;
  312. auto ttt = gen (xx.first, xx.second);
  313. for (auto& xxx: ttt) {
  314. int ff = 0;
  315. auto tttt = gen (xxx.first, xxx.second);
  316. for (auto& xxxx: tttt) {
  317. if (xxxx.first + xxxx.second >= 39) ff = 1;
  318. }
  319. c += ff;
  320. }
  321. if (c == sz (ttt)) f = 1;
  322. }
  323. cnt1 += f;
  324. }
  325. ++j;
  326. }
  327. if (cnt1 == sz (t)) cout << i << ' ';
  328. }
  329. }
  330. }
  331. }
  332.  
  333. task 22
  334.  
  335. int kek (int x) {
  336. int a = 0, b = 0;
  337. while (x > 0) {
  338. a += x % 8;
  339. ++b;
  340. x /= 8;
  341. }
  342. return a * b;
  343. }
  344.  
  345. signed main () {
  346. ios_base::sync_with_stdio (0);
  347. cin.tie (0);
  348. fl (i, 1, 1000) {
  349. if (kek (i) == 20) {
  350. dbg (i);
  351. exit (0);
  352. }
  353. }
  354. }
  355.  
  356. task 23
  357.  
  358. array<int, 100> dp;
  359.  
  360. signed main () {
  361. ios_base::sync_with_stdio (0);
  362. cin.tie (0);
  363. dp[1] = 1;
  364. fl (i, 1, 31) {
  365. if (i < 14) {
  366. if (i + 2 <= 14) dp[i + 2] += dp[i];
  367. if (i * 2 <= 14) dp[i * 2] += dp[i];
  368. } else {
  369. dp[i + 2] += dp[i];
  370. dp[i * 2] += dp[i];
  371. }
  372. }
  373. dbg (dp[30]);
  374. }
  375.  
  376. task 24
  377.  
  378. signed main () {
  379. ios_base::sync_with_stdio (0);
  380. cin.tie (0);
  381. vector<string> goo;
  382. for (string s; cin >> s; ) goo.pb (s);
  383. int mn = 1e9;
  384. int pos = -1;
  385. fr (i, sz (goo)) {
  386. int cnt = 0;
  387. for (auto& x: goo[i]) cnt += x == 'A';
  388. if (cnt < mn) {
  389. mn = cnt;
  390. pos = i;
  391. }
  392. }
  393. map <char, int> cnt;
  394. for (auto& x: goo[pos]) ++cnt[x];
  395. int mx = 0;
  396. char kek;
  397. for (auto& x: cnt) {
  398. if (x.second >= mx) {
  399. mx = x.second;
  400. kek = x.first;
  401. }
  402. }
  403. cout << kek << ' ';
  404. int c = 0;
  405. for (auto& s: goo) for (auto& x: s) c += x == kek;
  406. cout << c << '\n';
  407. }
  408.  
  409. task 25
  410.  
  411. signed main () {
  412. ios_base::sync_with_stdio (0);
  413. cin.tie (0);
  414. int cnt = 0;
  415. int mx = 0;
  416. int kek = 0;
  417. fl (a, 1, 5000 + 1) {
  418. fl (b, a, 5000 + 1) {
  419. int c = a * a + b * b;
  420. int c_kek = sqrt(c);
  421. if (c_kek * c_kek == c && c_kek <= 5000) {
  422. ++cnt;
  423. if (a + b + c_kek > mx) {
  424. mx = a + b + c_kek;
  425. kek = c_kek;
  426. }
  427. cerr << a << ' ' << b << ' ' << c_kek << '\n';
  428. }
  429. }
  430. }
  431. cout << cnt << ' ' << kek << '\n';
  432. }
  433.  
  434. task 26
  435.  
  436. signed main () {
  437. ios_base::sync_with_stdio (0);
  438. cin.tie (0);
  439. int n;
  440. cin >> n;
  441. vector<int> goo (n);
  442. for (auto& x: goo) cin >> x;
  443. unordered_set<int> kek;
  444. for (auto& x: goo) kek.insert (x);
  445. int cnt = 0, mx = 0;
  446. fr (i, n) {
  447. if (goo[i] % 2 == 0) continue;
  448. fl (j, i + 1, n) {
  449. if (goo[j] % 2 == 0) continue;
  450. if (kek.count ((goo[i] + goo[j]) / 2)) {
  451. ++cnt;
  452. mx = max (mx, (goo[i] + goo[j]) / 2);
  453. }
  454. }
  455. }
  456. cout << cnt << ' ' << mx << '\n';
  457. }
  458.  
  459. task 27
  460.  
  461. signed main () {
  462. ios_base::sync_with_stdio (0);
  463. cin.tie (0);
  464. int n;
  465. cin >> n;
  466. vector<int> goo (n);
  467. for (auto& x: goo) cin >> x;
  468. vector<int> mx1 (80), mx2 (80);
  469. for (auto& x: goo) {
  470. if (x > mx1[x % 80]) {
  471. mx2[x % 80] = mx1[x % 80];
  472. mx1[x % 80] = x;
  473. } else if (x > mx2[x % 80]) {
  474. mx2[x % 80] = x;
  475. }
  476. }
  477. int mx = 0;
  478. fr (i, 80) {
  479. if (mx2[i] > 0) mx = max (mx, mx1[i] + mx2[i]);
  480. }
  481. cout << mx << '\n';
  482. }
  483.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement