Codeforces Round #619 (Div. 2) A~D题解
最近网课也开始了,牛客上一堆比赛题目也没补,所以就D题后面的也懒得补了
A.Three String
水题
#include <cstdio>
#include <cstring>
using namespace std;
char a[], b[], c[];
int main() {
int t;
scanf("%d", &t);
while (t--) {
memset(a, , sizeof(a));
memset(b, , sizeof(b));
memset(c, , sizeof(c));
scanf("%s%s%s", a, b, c);
int len = strlen(a), ans = ;
for (int i = ; i < len; i++) {
if (c[i] == a[i] || c[i] == b[i])
continue;
ans = -;
break;
}
if (ans == -)
puts("NO");
else
puts("YES");
}
return ;
}
B.Motarack's Birthday
其实也挺水的...但是我场上脑子有点问题,第一反应是三分(?)因为它应该是只有一个极值的函数,可以用三分来做
这是我的代码,写的很复杂而且很奇怪
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
const int N = 1e5 + ;
int a[N], n;
inline int val(int b) {
int maxn = ;
for (int i = ; i <= n; i++) {
if (a[i - ] == - && a[i] == -)
continue;
if (a[i - ] == -)
maxn = max(maxn, (int)abs(b - a[i]));
else if (a[i] == -)
maxn = max(maxn, (int)abs(b - a[i - ]));
else
maxn = max(maxn, (int)abs(a[i] - a[i - ]));
}
return maxn;
}
int main() {
int t;
scanf("%d", &t);
while (t--) {
scanf("%d", &n);
for (int i = ; i <= n; i++)
scanf("%d", &a[i]);
int l = , r = 1e9;
while (r - l >= ) {
int l1 = l + (r - l) / ;
int r1 = r - (r - l) / ;
int a = val(l1), b = val(r1);
if (a <= b)
r = r1;
else
l = l1;
}
int a, b = 1e9 + ;
if (l != r) {
for (int i = l; i <= r; i++) {
int z = val(i);
if (z < b)
b = z, a = i;
}
}
else
a = l, b = val(l);
printf("%d %d\n", b, a);
}
return ;
}
然后题解肯定不是这样的啦,最后答案的范围肯定在和-1相邻的数字之间,若这些数字中最大的是maxn, 最小的是minn,则差的最大就是max(abs(maxn - val), abs(minn - val)),所以val等于(maxn + minn)/2就行了,代码很简单,我也懒得写了。
C.Ayoub's function
场上想了很久(还是太菜了),后来突然灵机一动,想到可以用总数减去只有0的个数,然后就可以发现000...000的序列越短越好,然后就可以直接O(1)出来了。
#include <cstdio>
using namespace std;
int main() {
int t;
scanf("%d", &t);
while (t--) {
long long n, m;
scanf("%lld %lld", &n, &m);
long long ans = 1ll * n * ( + n) / ;
if ((n - m) % (m + ) == ) {
long long b = (n - m) / (m + );
ans -= 1ll * (m + ) * b * (b + ) / ;
}
else {
long long b = (n - m) / (m + );
long long c = (n - m) % (m + );
ans -= (m + - c) * b * (b + ) / ;
ans -= c * (b + ) * (b + ) / ;
}
printf("%lld\n", ans);
}
return ;
}
D.Time to Run
很容易发现它是欧拉通路,因为它没有奇度顶点,然后想一个构造的方法就行了,然后我就随便想了一个,结果有一堆细节上的问题QAQ
#include <cstdio>
#include <algorithm>
using namespace std;
int main() {
int n, m, k;
scanf("%d %d %d", &n, &m, &k);
int r = * m * n - * n - * m;
if (k > r) {
puts("NO");
return ;
}
puts("YES");
n--; m--;
//RDU
if (k == )
return ;
if (n == ) { //这种情况要特殊考虑
if (k <= m) {
puts("");
printf("%d R\n", k);
}
else {
puts("");
printf("%d R\n%d L", m, k - m);
}
return ;
}
if (m == ) { //同上
if (k <= n)
printf("1\n%d D\n", k);
else
printf("2\n%d D\n%d U\n", n, k - n);
return ;
}
int kk = k;
int t = , cnt = ;
while (k > ) { //第一遍先找要多少次操作
if (t == (n + )) {
if (k <= m) {
cnt++;
break;
}
else {
cnt++;
k -= m;
}
if (k <= m) {
cnt++;
break;
}
else {
cnt++;
k -= m;
}
if (k <= n) {
cnt++;
break;
}
else {
cnt++;
k -= m;
}
break;
}
if (k <= m * ) {
if (k / > )
cnt++;
int y = k % ;
if (y == )
cnt++;
else if (y == )
cnt++;
break;
}
else {
cnt++;
k -= m * ;
}
if (k <= m) {
cnt++;
break;
}
else {
cnt++;
k -= m;
}
cnt++;
k--;
t++;
}
t = ;
k = kk;
printf("%d\n", cnt);
while (k > ) {
if (t == (n + )) { //这个要注意,最后一行就要往回走
if (k <= m) {
printf("%d R\n", k);
break;
}
else {
printf("%d R\n", m);
k -= m;
}
if (k <= m) {
printf("%d L\n", k);
break;
}
else {
printf("%d L\n", m);
k -= m;
}
if (k <= n) {
printf("%d U\n", k);
break;
}
else {
printf("%d U\n", m);
k -= m;
}
break;
}
if (k <= m * ) {
if (k / > )
printf("%d RDU\n", k / );
int y = k % ;
if (y == )
puts("1 R");
else if (y == )
puts("1 RD");
break;
}
else {
printf("%d RDU\n", m);
k -= m * ;
}
if (k <= m) {
printf("%d L\n", k);
break;
}
else {
printf("%d L\n", m);
k -= m;
}
printf("1 D\n");
k--;
t++;
}
return ;
}
Codeforces Round #619 (Div. 2) A~D题解的更多相关文章
- Codeforces Round #612 (Div. 2) 前四题题解
这场比赛的出题人挺有意思,全部magic成了青色. 还有题目中的图片特别有趣. 晚上没打,开virtual contest打的,就会前三道,我太菜了. 最后看着题解补了第四道. 比赛传送门 A. An ...
- Codeforces Round #198 (Div. 2)A,B题解
Codeforces Round #198 (Div. 2) 昨天看到奋斗群的群赛,好奇的去做了一下, 大概花了3个小时Ak,我大概可以退役了吧 那下面来稍微总结一下 A. The Wall Iahu ...
- Codeforces Round #672 (Div. 2) A - C1题解
[Codeforces Round #672 (Div. 2) A - C1 ] 题目链接# A. Cubes Sorting 思路: " If Wheatley needs more th ...
- Codeforces Round #614 (Div. 2) A-E简要题解
链接:https://codeforces.com/contest/1293 A. ConneR and the A.R.C. Markland-N 题意:略 思路:上下枚举1000次扫一遍,比较一下 ...
- Codeforces Round #610 (Div. 2) A-E简要题解
contest链接: https://codeforces.com/contest/1282 A. Temporarily unavailable 题意: 给一个区间L,R通有网络,有个点x,在x+r ...
- Codeforces Round #611 (Div. 3) A-F简要题解
contest链接:https://codeforces.com/contest/1283 A. Minutes Before the New Year 题意:给一个当前时间,输出离第二天差多少分钟 ...
- Codeforces Round #499 (Div. 2) D. Rocket题解
题目: http://codeforces.com/contest/1011/problem/D This is an interactive problem. Natasha is going to ...
- Codeforces Round #499 (Div. 2) C Fly题解
题目 http://codeforces.com/contest/1011/problem/C Natasha is going to fly on a rocket to Mars and retu ...
- Codeforces Round #198 (Div. 2)C,D题解
接着是C,D的题解 C. Tourist Problem Iahub is a big fan of tourists. He wants to become a tourist himself, s ...
随机推荐
- 普通键盘Windows上虚拟Cherry机械键盘效果的方法
草台班子--普通键盘Windows上虚拟Cherry机械键盘效果的方法 机械键盘以其独特的手感.绚丽的外形,还有那人神共愤的音效吸引着大批爱好者.最近iQQO 3的机械键盘效果更是吸引了更多 ...
- linux--解决celery消息中间件带来的一系列问题
启动celery定时任务 1.celery -A OpsManage beat -l info -S django 2.celery -A OpsManage worker -l info 此时消息中 ...
- LINUX下EFIBOOTMGR的使用,删除UEFI主板多余启动项和添加启动项
用uefi装了几次次archlinux,搞的uefi启动选项下多出来好多启动项..这东西重格硬盘也是不好用的.发现以下方法可以解决. efibootmgr //显示efi的启动项 删除一个引导项 ...
- 剑指offer-面试题62-圆圈中最后剩下的数字-约瑟夫环-解法2
/* 题目: 约瑟夫环问题. 思路: 数学规律 f(n)=0(n=1),[f(n-1,m)+m]%n(n>1) */ #include<iostream> #include<l ...
- elsearch搜索引擎 + painless脚本语言入门
最近项目用到了elsearch,ElasticSearch是一个基于Lucene的搜索服务器.它提供了一个分布式多用户能力的全文搜索引擎. 自从版本6.0之后,其默认脚本语言变为 painless . ...
- 关于MY Sql 查询锁表信息和解锁表
1.查询锁住表信息 show OPEN TABLES where In_use > 0; 2.查看进程 show processlist; 3.解开锁住的表 需要杀掉锁住表的相关进程Id. k ...
- javaSE学习笔记(16)---网络编程
javaSE学习笔记(16)---网络编程 基本概念 如今,计算机已经成为人们学习.工作.生活必不可少的工具.我们利用计算机可以和亲朋好友网上聊天,也可以玩网游.发邮件等等,这些功能实现都离不开计算机 ...
- mysql行转列,函数GROUP_CONCAT(expr)
demo: 语句: SELECT '行' id, '' product_nameUNIONSELECT id, product_name FROM `product` WHERE id < 5 ...
- NFS部署
yum install nfs-utils -y systemctl restart/enable nfs systemctl status rpcbind vim /etc/exports /dat ...
- 怎么在IDEA中给方法添加分割线?
方法中间分割不清晰 怎么在IDEA中给方法添加分割线呢? 效果如图 方法上有一条分割线,比较明了 按照下列顺序点击修改设置即可 File→Settings→Editor→General→Appeara ...