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 ...
随机推荐
- python2.0_s12_day21_web聊天室一
本节内容: 项目实战:开发一个WEB聊天室 功能需求: 用户可以与好友一对一聊天 可以搜索.添加某人为好友 用户可以搜索和添加群 每个群有管理员可以审批用户的加群请求,群管理员可以用多个,群管理员可以 ...
- Linux 远程同步:rsync
rsync 简介: (1) rsync 是一个远程数据同步工具,可通过 LAN/WAN 快速同步多台主机间的文件(2) rsync 使用所谓的“rsync算法”来使本地和远程两个主机之间的文件达到同步 ...
- Python 流程控制:if
语法: if 判断条件1: # 如果判断条件1成立,就执行语句1 语句1... if 判断条件1: # 如果判断条件1成立,就执行语句1,否则执行语句2 语句1... else: 语句2... if ...
- docker run 详解
docker run 用于把镜像启动为容器,语法如下: docker run [OPTIONS] IMAGE [COMMAND] [ARG...] 常见用法: [root@localhost ~]$ ...
- osgEarth的agglite插件使用例子feature_rasterize.earth
<!-- osgEarth Sample Demonstrates use of the "agglite" feature rasterization driver. -- ...
- UE4.16播放全景视频
全景视频有两种:一种是常见的一帧画面里面包含一张全景图,另外一种是一帧画面里面包含了左眼和右眼两张全景图. 根据种类的不同,选择不同的材质分别对应MAT_Single_Image和MAT_Stereo ...
- Nginx遇上Access Denied提示怎么解决
这几天在摆弄linux下面的各种服务器,对nginx非常有兴趣. 于是把phpmyadmin传上去了,先是phpmyadmin配了半天,结果配好之后发现phpmyadmin一些logo.css.js文 ...
- Core Location和MapKit的一些简单使用
Core Location 1. 基本对象是CLLocation,有属性coordinate, altitude, horizontal/vertical Accuracy, timestamp, ...
- PyQt4布局管理——绝对定位方式
PyQt4中的布局管理器 布局管理器是编程中重要的一部分.所谓布局管理器是指我们在窗口中安排部件位置的方法.布局管理器有两种工作方式:绝对定位方式(absolute positioning)和布局类别 ...
- MongoDb Mmap引擎分析
版权声明:本文由孔德雨原创文章,转载请注明出处: 文章原文链接:https://www.qcloud.com/community/article/137 来源:腾云阁 https://www.qclo ...