Codeforces Round #528 (Div. 2)题解

A. Right-Left Cipher

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

Code:

# include <bits/stdc++.h>

int main()
{
std::string s, t;
std::cin >> s;
int len = s.length();
int cnt = 0;
for(int i = 0; i < len; i++)
{
t = t + s[((len + 1) / 2 + cnt) - 1];
if(i % 2 == 0)
cnt = -cnt, ++cnt;
else cnt = -cnt;
}
std::cout << t;
return 0;
}

B. Div Times Mod

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

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

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

Code:

# include <bits/stdc++.h>
# define ll long long
int main()
{
ll n, k;
ll ans = 0;
scanf("%I64d%I64d", &n, &k);
for(int i = 1; i < k; i++)
if(n % i == 0)
ans = i;
printf("%I64d", (((n / ans) * k) + ans));
return 0;
}

C. Connect Three

  • 差点C没做出来退役

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

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

取最小值输出即可

Code:

#include <bits/stdc++.h>
#define mp(i, j) std::make_pair(i, j)
#define p std::pair<int, int>
p a[4];
std::map<p, int> m1, m2, m3, m4;
void add1()
{
for (int i = a[1].first; i <= a[2].first; i++)
m1[mp(i, a[1].second)] = 1;
if (a[1].second <= a[2].second)
{
for (int i = a[1].second; i <= a[2].second; i++)
m1[mp(a[2].first, i)] = 1;
}
else
{
for (int i = a[1].second; i >= a[2].second; i--)
m1[mp(a[2].first, i)] = 1;
}
for (int i = a[2].first; i <= a[3].first; i++)
m1[mp(i, a[2].second)] = 1;
if (a[2].second <= a[3].second)
{
for (int i = a[2].second; i <= a[3].second; i++)
m1[mp(a[3].first, i)] = 1;
}
else
{
for (int i = a[2].second; i >= a[3].second; i--)
m1[mp(a[3].first, i)] = 1;
}
}
void add2()
{
for (int i = a[1].first; i <= a[2].first; i++)
m2[mp(i, a[1].second)] = 1;
if (a[1].second <= a[2].second)
{
for (int i = a[1].second; i <= a[2].second; i++)
m2[mp(a[2].first, i)] = 1;
}
else
{
for (int i = a[1].second; i >= a[2].second; i--)
m2[mp(a[2].first, i)] = 1;
} if (a[2].second <= a[3].second)
{
for (int i = a[2].second; i <= a[3].second; i++)
m2[mp(a[2].first, i)] = 1;
}
else
{
for (int i = a[2].second; i >= a[3].second; i--)
m2[mp(a[2].first, i)] = 1;
}
for (int i = a[2].first; i <= a[3].first; i++)
m2[mp(i, a[3].second)] = 1;
}
void add3()
{ if (a[1].second <= a[2].second)
{
for (int i = a[1].second; i <= a[2].second; i++)
m3[mp(a[1].first, i)] = 1;
}
else
{
for (int i = a[1].second; i >= a[2].second; i--)
m3[mp(a[1].first, i)] = 1;
}
for (int i = a[1].first; i <= a[2].first; i++)
m3[mp(i, a[2].second)] = 1;
if (a[2].second <= a[3].second)
{
for (int i = a[2].second; i <= a[3].second; i++)
m3[mp(a[2].first, i)] = 1;
}
else
{
for (int i = a[2].second; i >= a[3].second; i--)
m3[mp(a[2].first, i)] = 1;
}
for (int i = a[2].first; i <= a[3].first; i++)
m3[mp(i, a[3].second)] = 1;
}
void add4()
{
if (a[1].second <= a[2].second)
{
for (int i = a[1].second; i <= a[2].second; i++)
m4[mp(a[1].first, i)] = 1;
}
else
{
for (int i = a[1].second; i >= a[2].second; i--)
m4[mp(a[1].first, i)] = 1;
}
for (int i = a[1].first; i <= a[2].first; i++)
m4[mp(i, a[2].second)] = 1;
for (int i = a[2].first; i <= a[3].first; i++)
m4[mp(i, a[2].second)] = 1;
if (a[2].second <= a[3].second)
{
for (int i = a[2].second; i <= a[3].second; i++)
m4[mp(a[3].first, i)] = 1;
}
else
{
for (int i = a[2].second; i >= a[3].second; i--)
m4[mp(a[3].first, i)] = 1;
}
}
inline int print(std::map<p, int> m)
{
for (std::map<p, int>::iterator it = m.begin(); it != m.end(); it++)
printf("%d %d\n", it->first.first, it->first.second);
}
int main()
{
int cnt = 0;
for (int i = 1; i <= 3; i++)
scanf("%d%d", &a[i].first, &a[i].second);
std::sort(a + 1, a + 3 + 1);
add1(), add2(), add3(), add4();
cnt = std::min(std::min(m1.size(), m2.size()), std::min(m3.size(), m4.size()));
printf("%d\n", cnt);
if (m1.size() == cnt)
return 0 * print(m1);
if (m2.size() == cnt)
return 0 * print(m2);
if (m3.size() == cnt)
return 0 * print(m3);
if (m4.size() == cnt)
return 0 * print(m4);
return 0;
}

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. O(1) gcd 板子

    const int N = 2e5+10; const int M = 500; int cnt, p[N], _gcd[M][M]; int v[N][3],vis[N]; int gcd(int ...

  2. Luogu5400 CTS2019随机立方体(容斥原理)

    考虑容斥,计算至少有k个极大数的概率.不妨设这k个数对应的格子依次为(k,k,k)……(1,1,1).那么某一维坐标<=k的格子会对这些格子是否会成为极大数产生影响.先将这样的所有格子和一个数集 ...

  3. 4_PHP流程控制语句_2_循环结构

    以下为学习孔祥盛主编的<PHP编程基础与实例教程>(第二版)所做的笔记. PHP流程控制共有3种类型:条件控制结构.循环结构以及程序跳转和终止语句. 4.2 循环结构 4.2.1 whil ...

  4. Go context 介绍和使用

    context 上下文管理 context 翻译过来就是上下文管理,主要作用有两个: 控制 goroutine 的超时 保存上下文数据 WithTimeout 通过下面的一个简单的 http 例子进行 ...

  5. Privacy Description

    This application respects and protects the privacy of all users who use the service. In order to pro ...

  6. Vue指令之`v-model`和`双向数据绑定

     v-bind 只能实现数据的单向绑定,从 M 自动绑定到 V, 无法实现数据的双向绑定 <input type="text" v-bind:value="msg& ...

  7. 【Linux】修改CentOS7启动方式

    ## 查看当前系统的默认启动方式: systemctl get-default ## 查看如下文件 cat /etc/inittab 可以看到 此文件中提示了如何进行修改默认的启动方式 ## 命令行启 ...

  8. vsftpd设置虚拟用户

    centos6.5环境 软件安装: yum install vsftpd db4-utils 1. 添加虚拟用户口令文件 #添加一个虚拟用户testvim /etc/vsftpd/vftp_vuser ...

  9. [Jenkins][GitHub]2 持续集成环境初探

    预计阅读时间:30分钟 部署环境:Jenkins ver. 2.61 + Centos7 + Java 1.8 参考链接: http://www.jianshu.com/p/22b7860b4e81 ...

  10. 用Jmeter做性能测试,之后报表展示

    https://octoperf.com/blog/2017/10/19/how-to-analyze-jmeter-results/ 看到性能测试平台的开发,我在想需要什么功能,报表需要什么样子的 ...