Codeforces Round #528 (Div. 2)题解

A. Right-Left Cipher

很明显这道题按题意逆序解码即可

Code:

  1. # include <bits/stdc++.h>
  2. int main()
  3. {
  4. std::string s, t;
  5. std::cin >> s;
  6. int len = s.length();
  7. int cnt = 0;
  8. for(int i = 0; i < len; i++)
  9. {
  10. t = t + s[((len + 1) / 2 + cnt) - 1];
  11. if(i % 2 == 0)
  12. cnt = -cnt, ++cnt;
  13. else cnt = -cnt;
  14. }
  15. std::cout << t;
  16. return 0;
  17. }

B. Div Times Mod

明显要使\(x\)最小,一定要使\(x \mod k\)最大

从\(n-1\)到\(1\)找能被\(n\)整除的最大数\(y\)

答案即为\((n/y)*k+y\)

Code:

  1. # include <bits/stdc++.h>
  2. # define ll long long
  3. int main()
  4. {
  5. ll n, k;
  6. ll ans = 0;
  7. scanf("%I64d%I64d", &n, &k);
  8. for(int i = 1; i < k; i++)
  9. if(n % i == 0)
  10. ans = i;
  11. printf("%I64d", (((n / ans) * k) + ans));
  12. return 0;
  13. }

C. Connect Three

  • 差点C没做出来退役

可以发现最优路径是曼哈顿距离上的两条路径

将\(3\)个点按\(x\)坐标排序,枚举(排序后的)\(A\)->\(B\)的两种(先上后左,先左后上),\(B\)->\(C\)的两种,共四种

取最小值输出即可

Code:

  1. #include <bits/stdc++.h>
  2. #define mp(i, j) std::make_pair(i, j)
  3. #define p std::pair<int, int>
  4. p a[4];
  5. std::map<p, int> m1, m2, m3, m4;
  6. void add1()
  7. {
  8. for (int i = a[1].first; i <= a[2].first; i++)
  9. m1[mp(i, a[1].second)] = 1;
  10. if (a[1].second <= a[2].second)
  11. {
  12. for (int i = a[1].second; i <= a[2].second; i++)
  13. m1[mp(a[2].first, i)] = 1;
  14. }
  15. else
  16. {
  17. for (int i = a[1].second; i >= a[2].second; i--)
  18. m1[mp(a[2].first, i)] = 1;
  19. }
  20. for (int i = a[2].first; i <= a[3].first; i++)
  21. m1[mp(i, a[2].second)] = 1;
  22. if (a[2].second <= a[3].second)
  23. {
  24. for (int i = a[2].second; i <= a[3].second; i++)
  25. m1[mp(a[3].first, i)] = 1;
  26. }
  27. else
  28. {
  29. for (int i = a[2].second; i >= a[3].second; i--)
  30. m1[mp(a[3].first, i)] = 1;
  31. }
  32. }
  33. void add2()
  34. {
  35. for (int i = a[1].first; i <= a[2].first; i++)
  36. m2[mp(i, a[1].second)] = 1;
  37. if (a[1].second <= a[2].second)
  38. {
  39. for (int i = a[1].second; i <= a[2].second; i++)
  40. m2[mp(a[2].first, i)] = 1;
  41. }
  42. else
  43. {
  44. for (int i = a[1].second; i >= a[2].second; i--)
  45. m2[mp(a[2].first, i)] = 1;
  46. }
  47. if (a[2].second <= a[3].second)
  48. {
  49. for (int i = a[2].second; i <= a[3].second; i++)
  50. m2[mp(a[2].first, i)] = 1;
  51. }
  52. else
  53. {
  54. for (int i = a[2].second; i >= a[3].second; i--)
  55. m2[mp(a[2].first, i)] = 1;
  56. }
  57. for (int i = a[2].first; i <= a[3].first; i++)
  58. m2[mp(i, a[3].second)] = 1;
  59. }
  60. void add3()
  61. {
  62. if (a[1].second <= a[2].second)
  63. {
  64. for (int i = a[1].second; i <= a[2].second; i++)
  65. m3[mp(a[1].first, i)] = 1;
  66. }
  67. else
  68. {
  69. for (int i = a[1].second; i >= a[2].second; i--)
  70. m3[mp(a[1].first, i)] = 1;
  71. }
  72. for (int i = a[1].first; i <= a[2].first; i++)
  73. m3[mp(i, a[2].second)] = 1;
  74. if (a[2].second <= a[3].second)
  75. {
  76. for (int i = a[2].second; i <= a[3].second; i++)
  77. m3[mp(a[2].first, i)] = 1;
  78. }
  79. else
  80. {
  81. for (int i = a[2].second; i >= a[3].second; i--)
  82. m3[mp(a[2].first, i)] = 1;
  83. }
  84. for (int i = a[2].first; i <= a[3].first; i++)
  85. m3[mp(i, a[3].second)] = 1;
  86. }
  87. void add4()
  88. {
  89. if (a[1].second <= a[2].second)
  90. {
  91. for (int i = a[1].second; i <= a[2].second; i++)
  92. m4[mp(a[1].first, i)] = 1;
  93. }
  94. else
  95. {
  96. for (int i = a[1].second; i >= a[2].second; i--)
  97. m4[mp(a[1].first, i)] = 1;
  98. }
  99. for (int i = a[1].first; i <= a[2].first; i++)
  100. m4[mp(i, a[2].second)] = 1;
  101. for (int i = a[2].first; i <= a[3].first; i++)
  102. m4[mp(i, a[2].second)] = 1;
  103. if (a[2].second <= a[3].second)
  104. {
  105. for (int i = a[2].second; i <= a[3].second; i++)
  106. m4[mp(a[3].first, i)] = 1;
  107. }
  108. else
  109. {
  110. for (int i = a[2].second; i >= a[3].second; i--)
  111. m4[mp(a[3].first, i)] = 1;
  112. }
  113. }
  114. inline int print(std::map<p, int> m)
  115. {
  116. for (std::map<p, int>::iterator it = m.begin(); it != m.end(); it++)
  117. printf("%d %d\n", it->first.first, it->first.second);
  118. }
  119. int main()
  120. {
  121. int cnt = 0;
  122. for (int i = 1; i <= 3; i++)
  123. scanf("%d%d", &a[i].first, &a[i].second);
  124. std::sort(a + 1, a + 3 + 1);
  125. add1(), add2(), add3(), add4();
  126. cnt = std::min(std::min(m1.size(), m2.size()), std::min(m3.size(), m4.size()));
  127. printf("%d\n", cnt);
  128. if (m1.size() == cnt)
  129. return 0 * print(m1);
  130. if (m2.size() == cnt)
  131. return 0 * print(m2);
  132. if (m3.size() == cnt)
  133. return 0 * print(m3);
  134. if (m4.size() == cnt)
  135. return 0 * print(m4);
  136. return 0;
  137. }

Codeforces Round #528 (Div. 2)题解的更多相关文章

  1. Codeforces Round #182 (Div. 1)题解【ABCD】

    Codeforces Round #182 (Div. 1)题解 A题:Yaroslav and Sequence1 题意: 给你\(2*n+1\)个元素,你每次可以进行无数种操作,每次操作必须选择其 ...

  2. Codeforces Round #608 (Div. 2) 题解

    目录 Codeforces Round #608 (Div. 2) 题解 前言 A. Suits 题意 做法 程序 B. Blocks 题意 做法 程序 C. Shawarma Tent 题意 做法 ...

  3. Codeforces Round #525 (Div. 2)题解

    Codeforces Round #525 (Div. 2)题解 题解 CF1088A [Ehab and another construction problem] 依据题意枚举即可 # inclu ...

  4. Codeforces Round #466 (Div. 2) 题解940A 940B 940C 940D 940E 940F

    Codeforces Round #466 (Div. 2) 题解 A.Points on the line 题目大意: 给你一个数列,定义数列的权值为最大值减去最小值,问最少删除几个数,使得数列的权 ...

  5. Codeforces Round #677 (Div. 3) 题解

    Codeforces Round #677 (Div. 3) 题解 A. Boring Apartments 题目 题解 简单签到题,直接数,小于这个数的\(+10\). 代码 #include &l ...

  6. Codeforces Round #665 (Div. 2) 题解

    Codeforces Round #665 (Div. 2) 题解 写得有点晚了,估计都官方题解看完切掉了,没人看我的了qaq. 目录 Codeforces Round #665 (Div. 2) 题 ...

  7. Codeforces Round #160 (Div. 1) 题解【ABCD】

    Codeforces Round #160 (Div. 1) A - Maxim and Discounts 题意 给你n个折扣,m个物品,每个折扣都可以使用无限次,每次你使用第i个折扣的时候,你必须 ...

  8. Codeforces Round #383 (Div. 2) 题解【ABCDE】

    Codeforces Round #383 (Div. 2) A. Arpa's hard exam and Mehrdad's naive cheat 题意 求1378^n mod 10 题解 直接 ...

  9. Codeforces Round #271 (Div. 2)题解【ABCDEF】

    Codeforces Round #271 (Div. 2) A - Keyboard 题意 给你一个字符串,问你这个字符串在键盘的位置往左边挪一位,或者往右边挪一位字符,这个字符串是什么样子 题解 ...

随机推荐

  1. Python2和3字符编码的区别

    Python2和3字符编码的区别 一.字符编码应用之Python 1.1 执行Python程序的三个阶段 Python test.py(我再强调一遍,执行test.py的第一步,一定是先将文件内容从硬 ...

  2. ActiveMQ 消息队列服务

      1 ActiveMQ简介 1.1 ActiveMQ是什么 ActiveMQ是一个消息队列应用服务器(推送服务器).支持JMS规范. 1.1.1 JMS概述 全称:Java Message Serv ...

  3. 深度学习的激活函数 :sigmoid、tanh、ReLU 、Leaky Relu、RReLU、softsign 、softplus、GELU

    深度学习的激活函数  :sigmoid.tanh.ReLU .Leaky Relu.RReLU.softsign .softplus.GELU 2019-05-06 17:56:43 wamg潇潇 阅 ...

  4. VBA While Wend循环

    在While...Wend循环中,如果条件为True,则会执行所有语句,直到遇到Wend关键字. 如果条件为false,则退出循环,然后控件跳转到Wend关键字后面的下一个语句. 语法 以下是VBA中 ...

  5. React/虚拟DOM

    在说虚拟DOM之前,先来一个引子,从输入url到展现出整个页面都有哪些过程? 1.输入网址 2.DNS解析 3.建立tcp连接 4.客户端发送HTPP请求 5.服务器处理请求 6.服务器响应请求 7. ...

  6. Fortify漏洞之XML External Entity Injection(XML实体注入)

    继续对Fortify的漏洞进行总结,本篇主要针对  XML External Entity Injection(XML实体注入) 的漏洞进行总结,如下: 1.1.产生原因: XML External ...

  7. unittest 运行slenium(五)---运行代码并生成HTMLTestRunner报告

    整体代码如下: import os import sys import time import datetime import unittest import HTMLTestRunner # git ...

  8. jupyter notebook new Python3报错:Permission denied: Untitled.ipynb,修改workspace

    点击新建Python文件即弹出弹窗显示 Permission denied: Untitled.ipynb 看到Permission denied 尝试是权限问题进行解决,各种百度结果都是对文件进行权 ...

  9. Springboot分别使用乐观锁和分布式锁(基于redisson)完成高并发防超卖

    原文 :https://blog.csdn.net/tianyaleixiaowu/article/details/90036180 乐观锁 乐观锁就是在修改时,带上version版本号.这样如果试图 ...

  10. 虚拟dom应用

    vdom如何应用,核心api是什么 1.介绍snabbdom(开源社区用的多,vue2用的是他) 首先回顾下之前的vdom格式 真实的dom <body> <ul id=" ...