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 ...
随机推荐
- Redis(七)-- SpringMVC整合Redis集群
1.pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www ...
- mysq对存在null值的字段排序
1.建立学生表,建表sql如下: ),age int); 2.插入几条数据,包括id字段值为null的 ,),(,),(,),(),(); 3.我们查询下,可以看到存在id字段为空的值: 4.对学生表 ...
- oct()
oct() 用于将一个十进制的整数转换成八进制字符串 In [10]: oct(10) Out[10]: ' In [11]: oct(20) Out[11]: '
- timerWithTimeInterval 方法详用
1.初始化 + (NSTimer *)timerWithTimeInterval:(NSTimeInterval)ti target:(id)aTarget selector:(SEL)aSelect ...
- AndroidのUI体验之上拉下拉
1.ScrollView监测是否滚动到顶部或底部 onScrollChanged(); 滚动到顶部判断:getScrollY() == 0 滚动到底部判断:getChildAt(0).getMeasu ...
- c++11——基于范围的for循环
c++11中有基于范围的for循环,基于范围的for循环可以不再关心迭代器的概念,只需要关系容器中的元素类型即可,同时也不必显式的给出容器的开头和结尾. int arr[] = {1, 2, 3, 4 ...
- java框架---->zxing框架的使用
今天我们就来学习一下zxing的用法,这里只涉及到java se的部分. zxing的学习 如果在java se环境中使用zxing,需要在maven的pom.xml中添加依赖: <depend ...
- Shell 将两个文件按列合并
file1. 1 2 2 3 3 4 4 5 5 6 file2. a b b c c d d e e f 需要把file2的第二列合并到file1,使File1并成三列. 第一种方法:paste p ...
- pano2vr制作360全景图
1.下载pano2vr中文破解版2.制作360全景选择"矩形球面投影" 3.输出格式选择HTML5, 也可选择Flash(快被淘汰) 4.HTML5输出选项中3个重要选项4.1 F ...
- postgresql数据库中对重复数据的处理
我们在使用postgresql数据库的时候,如果一张数据表在未做任何约束的情况下,很可能会出现几条完全一样的数据,即重复数据.如下图所示: 那么如果我们要删除其中的2条该怎么办呢?第一种我们可以清空表 ...