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 ...
随机推荐
- linux连接sybase数据库-isql
转自:http://blog.knowsky.com/196438.htm 想要linux连接sybase数据库用命令isql: isql [-U login id] [-P password] [- ...
- linux系统输入法设置
首先是要安装了中文输入法,下面以搜狗为例. 2 从system settings 进入language support ,在keyboard input method system 中是看不到自己安装 ...
- 《C++ Primer Plus》第13章 类继承 笔记
类继承通过使用已有的类(基类)定义新的来(派生类),使得能够根据需要修改编程代码.共有继承建立is-a关系,这意味着派生类对象也应该是某种基类对象.作为is-a模型的一部分,派生类继承基类的数据称源和 ...
- Android 命令行打包和签名
使用命令行方式进行签名需要JDK中的两个命令行工具:keytool.exe和jarsigner.exe.可按如下两步对apk文件进行签名: 1. # keytool -genkey -v -keyst ...
- MQTT-SN协议乱翻之小结篇
前言 这里简单做一些小结和对比,针对前面的协议翻译部分,一阶段的学习完结. MQTT-SN VS MQTT MQTT-SN基于MQTT原有语义,但做了很多的调整.比如: 一个CONNECT消息被拆分为 ...
- jstl标签怎么实现分页中下一页
<script type="text/javascript"> //分页按钮处理 function goPageAction(page ...
- 【BZOJ2938】[Poi2000]病毒 AC自动机+DFS
[BZOJ2938][Poi2000]病毒 Description 二进制病毒审查委员会最近发现了如下的规律:某些确定的二进制串是病毒的代码.如果某段代码中不存在任何一段病毒代码,那么我们就称这段代码 ...
- 问答项目---用户注册的那些事儿(JS验证)
做注册的时候,由于每一个页面都有都要可以注册,可以把注册方法写到一个公用的方法里去,其他方法继承这个方法: 简单注册JS示例: <script type='text/javascript'> ...
- 树形DP求树的直径
hdu4607 Park Visit Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- ZOJ 3537 Cake(凸包判定+区间DP)
Cake Time Limit: 1 Second Memory Limit: 32768 KB You want to hold a party. Here's a polygon-shaped c ...