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 ...
随机推荐
- Python 收集主机信息
写一个 python 脚本,收集以下信息 ( CentOS 6 ) : IP地址 <ip> 主机名 <hostname> 操作系统版本 <osver> ...
- windows命令之PING DIR DEL CD TASKLIST (转)
最简单的莫过于PING命令了. PING命令的功能就是给对方主机发送IP数据包. 一般都是测试主机是否在线. 用法如下: PING 192.168.1.1.PING命令默认发送的是四个数据包,当然也可 ...
- centos solr4.5 tomcat 简单安装[已测试ok]
一.环境准备: 1.jdk安装 2.tomcat安装 这两个基本环境的安装在这里就不说了 二.下载solr-4.5.0.tgz 三.安装solr 1.解压solr tar -zxvf /opt/sol ...
- php检测文件只读、可写、可执行权限
例子:检测文件是否可读.可写.可执行. 复制代码代码示例: <?php $myfile = "./test.txt"; if (is_readable ($myfile)) ...
- WIN10 X64下通过TLS实现反调试
目录(?)[-] TLS技术简介 1 TLS回调函数 2 TLS的数据结构 具体实现及原理 1 VS2015 X64 release下的demo 2 回调函数的具体实现 21 使用IsDebugger ...
- php 数据库练习之租房子
题目: 示例图 本次只做图4这个表,因为之前的都已做过 自己在mydb数据库建了一个house表 如图: 自己做的代码: <!DOCTYPE html PUBLIC "-//W3C// ...
- ajax jquery校验用户是否已经注册
服务端代码这里就不贴了 html代码比较简单,需要自行引入jquery库 <body> 请输入用户名:<input type="text" id="us ...
- 服务器报错 500,请确保 ASP.NET State Service(ASP.NET 状态服务)已启动
报错信息: 解决方案: 开启此服务
- 170808、生成为CVS文件
/** * Desc : 生成为CVS文件 * User : RICK * @param data 源数据List * @param map csv文件的列表头map * @param outPutP ...
- 170719、springboot编程之异步调用@Async
1.在pom.xml中增加依赖 <dependency> <groupId>org.springframework.boot</groupId> <artif ...