Codeforces Round #528 Solution
A. Right-Left Cipher
Solved.
注意长度的奇偶
#include <bits/stdc++.h>
using namespace std; string s;
int main()
{
while (cin >> s)
{
string res = "";
int len = s.size();
if (len == )
{
cout << s << endl;
continue;
}
int l, r;
if (len & )
{
res += s[s.size() / ];
l = len / - , r = l + ;
while (l >= )
{
res += s[r];
res += s[l];
--l, ++r;
}
}
else
{
l = len / - ;
r = l + ;
while (l >= )
{
res += s[l];
res += s[r];
--l, ++r;
}
}
cout << res << endl;
}
return ;
}
B. Div Times Mod
Solved.
题意:
$给出一个n,求使得下面这个等式成立的x$
$(\frac{x}{k}) \cdot (x \;mod\; k) = n$
思路:
$k很小,并且第二项的取值肯定在[1, k - 1]之间,枚举第二项,算第一项更新答案即可$
#include <bits/stdc++.h>
using namespace std; #define ll long long
int n, k;
int main()
{
while (scanf("%d%d", &n, &k) != EOF)
{
ll res = (ll)1e18;
for (int i = ; i < k; ++i) if (n % i == )
res = min(res, 1ll * (n / i) * k + i);
printf("%lld\n", res);
}
return ;
}
C. Connect Three
Solved.
题意:
在一个二维平面上,有三个点,在不同的地方,行走只能走相邻的格子且被涂色的格子,求最小的涂格子的数量
思路:
我们随便找两个点,构成的矩形,那么这两个点的路径可以经过这个矩形里面任意一点
那么我们枚举里面每一点,要么第三点也在这个矩形里面,要么肯定存在一点使得这一点到第三点的路径不经过矩形
这样的话答案就会最小
或者这样理解,三点需要汇聚到同一点,那么这个点的候选范围必然是任取两点构成的矩形当中,因为如果不是
那么把这个点移到矩形内必然更优
#include <bits/stdc++.h>
using namespace std; int x[], y[];
int f(int x1, int y1, int x2, int y2)
{
return abs(x1 - x2) + abs(y1 - y2);
} void print(int x1, int y1, int x2, int y2)
{
while (x2 != x1)
{
if (x2 < x1) ++x2;
else --x2;
printf("%d %d\n", x2, y2);
}
while (y2 != y1)
{
if (y2 < y1) ++y2;
else --y2;
printf("%d %d\n", x2, y2);
}
} int main()
{
while (scanf("%d%d", x, y) != EOF)
{
for (int i = ; i <= ; ++i) scanf("%d%d", x + i, y + i);
int tmp = (int)1e6, posx = -, posy = -;
int l[] = {x[], y[]}, r[] = {x[], y[]};
for (int i = ; i < ; ++i) if (l[i] > r[i]) swap(l[i], r[i]);
for (int i = l[]; i <= r[]; ++i) for (int j = l[]; j <= r[]; ++j)
{
if (f(i, j, x[], y[]) < tmp)
{
tmp = f(i, j, x[], y[]);
posx = i, posy = j;
}
}
int res = tmp + f(x[], y[], x[], y[]) + ;
printf("%d\n", res);
print(x[], y[], posx, posy);
print(x[], y[], posx, posy);
print(x[], y[], posx, posy);
printf("%d %d\n", posx, posy);
}
return ;
}
D. Minimum Diameter Tree
Solved.
题意:
一棵树,一共有$s的点权,分配给这些点,使得直径最短$
思路:
我们考虑到将点权分配给度数>1的点是没用的,因为它们不会作为路径的端点
那么被作为路径的端点的只有度数=1的点
我们可以这样理解,任意两个度数=1的点都可以构成一条极长路径,也就是说,问题可以转化为
$有x个数,要将s分配给它们,使得两两相加的最大值最小$
$那不就是平均分配吗?$
#include <bits/stdc++.h>
using namespace std; #define N 100010
int n, s, degree[N]; int main()
{
while (scanf("%d%d", &n, &s) != EOF)
{
memset(degree, , sizeof degree);
for (int i = , u, v; i < n; ++i)
{
scanf("%d%d", &u, &v);
++degree[u];
++degree[v];
}
int cnt = ;
for (int i = ; i <= n; ++i) cnt += degree[i] == ;
printf("%.10f\n", s * 2.0 / cnt);
}
return ;
}
Codeforces Round #528 Solution的更多相关文章
- Codeforces Round #528 (Div. 2)题解
Codeforces Round #528 (Div. 2)题解 A. Right-Left Cipher 很明显这道题按题意逆序解码即可 Code: # include <bits/stdc+ ...
- (AB)Codeforces Round #528 (Div. 2, based on Technocup 2019 Elimination Round
A. Right-Left Cipher time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #528 (Div. 2, based on Technocup 2019 Elimination Round 4) C. Connect Three 【模拟】
传送门:http://codeforces.com/contest/1087/problem/C C. Connect Three time limit per test 1 second memor ...
- Codeforces Round #528 Div. 1 自闭记
整天自闭. A:有各种讨论方式.我按横坐标排了下然后讨论了下纵坐标单调和不单调两种情况.写了15min也就算了,谁能告诉我printf和cout输出不一样是咋回事啊?又调了10min啊?upd:突然想 ...
- Codeforces Round #528 div1
完了,看来上一次的flag要应验了,我大概是真的要掉成pupil了吧.. A - Connect Three 这个就是找到x的中间值,y的中间值,然后切一下,然后把所有的点挂到这条边上.但是我做的还是 ...
- Educational Codeforces Round 56 Solution
A. Dice Rolling 签到. #include <bits/stdc++.h> using namespace std; int t, n; int main() { scanf ...
- Educational Codeforces Round 57 Solution
A. Find Divisible 签到. #include <bits/stdc++.h> using namespace std; int t, l, r; int main() { ...
- Educational Codeforces Round 58 Solution
A. Minimum Integer 签到. #include <bits/stdc++.h> using namespace std; #define ll long long ll l ...
- Educational Codeforces Round 59 Solution
A. Digits Sequence Dividing 签. #include <bits/stdc++.h> using namespace std; #define N 1010 ch ...
随机推荐
- oracle dblink结合同义词的用法 PLS-00352:无法访问另一数据库
我从源库导出数据PCK报错如下:
- 第三篇:关于TIME_WAIT状态
前言 为何TCP ”四次分手“ 的过程中会有一个TIME_WAIT状态?这个状态有什么意义呢?这是网络中的一个经典问题,本文将给出精简的回答. 什么是TIME_WAIT状态 这是TCP通信协议中出现的 ...
- 如何使用css影藏滚动条
1.单纯的一句代码: div ::-webkit-scrollbar {width: 0px;}//或者display:none 但是这代码最大的弊端就是只能在webkit内核的浏览器上进行显示,无法 ...
- java基础---->FilenameFilter之文件过滤
FilenameFilter用于对列表中文件名的过滤,今天我们就开始java中FilenameFilter的学习.好多年了,你一直在我的伤口中幽居,我放下过天地,却从未放下过你,我生命中的千山万水,任 ...
- 深入浅出Docker(六):像谷歌一样部署你的应用
1.概述 谷歌发起的开源项目从来都是广受技术圈的关注和讨论,本文将介绍的就是最新的容器编排管理系统Kubernetes.Kubernetes开源项目版本更新频繁,对于初次使用者来说其定义大量的技术术语 ...
- sql语句查询条件的不同表达方式对查询性能的影响
今天操作数据库遇到一个问题 目标表RA_AD_DAILY_DATA的数据量大概有5千万左右,其中的BUSINESS_DATE字段为日期类型 我要查询8月20号导入的三条记录,刚开始用这种方式去查: S ...
- DGbroker快速失败转移
1.先决条件 DGMGRL> ENABLE FAST_START FAILOVER; Error: ORA-: requirements not met for enabling fast-st ...
- 详解Go语言中的屏蔽现象
在刚开始学习Go语言的过程中,难免会遇到一些问题,尤其是从其他语言转向Go开发的人员,面对语法及其内部实现的差异,在使用Go开发时也避免不了会踩"坑".本文主要针对Go设计中的屏蔽 ...
- rman备份的其它特性
1.7.3.1并发: 主要用于提高备份的速度,可以分为手动并发或自动并发 手动并发:通过分配多个通道并将文件指定到特定的通道 RMAN> run { 2> allocate channe ...
- 310实验室(六)CMake学习心得
树形结构方式布局. OTL 中每一个文件中的CMakeLists.txt 有不同的作用:按查看文件的先后顺便进行分层理解, 根文件即第一次 中的.txt是 启用 CMAKE_MODULE_PATH模板 ...