Codeforces Round #441 Div. 2 A B C D
题目链接
A. Trip for Meal
题意
三个点之间两两有路径,分别长为\(a,b,c\),现在从第一个点出发,走\(n-1\)条边,问总路径最小值。
思路
记起始点相邻的边为\(a,b\),相对的边为\(c\).
首先肯定走\(a,b\)中的最小值(不妨设为\(a\)),到达另一个顶点。那么这个顶点所连的两条边\(a,c\)中必然有一个是\(a,b,c\)三者中的最小值,否则最小值就为\(b\),与初始的选择矛盾。
于是接下来只需要在最小值的路上反复走即可。
Code
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int main() {
int n, a ,b,c;
scanf("%d", &n);
--n;
scanf("%d%d%d", &a,&b,&c);
if (n==0) { putchar('0'); exit(0); }
if (b > a) swap(a,b);
int ans = b;
--n;
if (b > c) ans += n*c;
else ans += n*b;
printf("%d\n", ans);
return 0;
}
B. Divisibility of Differences
题意
从\(n\)个数中取\(m\)个数关于\(\%k\)同余。
思路
统计\(\%k=0,1,...,k-1\)的数的个数。
Code
#include <bits/stdc++.h>
#define maxn 100010
using namespace std;
typedef long long LL;
int a[maxn], cnt[maxn], ans[maxn];
int main() {
int n, m, k;
scanf("%d%d%d", &n, &m, &k);
for (int i = 0; i < n; ++i) {
scanf("%d", &a[i]);
++cnt[a[i] % k];
}
for (int i = 0; i < k; ++i) {
if (cnt[i] >= m) {
printf("Yes\n");
int tot = 0;
for (int j = 0; j < n && tot < m; ++j) {
if (a[j] % k == i) ans[tot++] = a[j];
}
printf("%d", ans[0]);
for (int i = 1; i < tot; ++i) printf(" %d", ans[i]); printf("\n");
exit(0);
}
}
printf("No\n");
return 0;
}
C. Classroom Watch
题意
给定一个数\(n(n\leq 1e9)\),已知\(n=x+(x各数位上数字之和)\),求所有满足条件的\(x\).
思路
显然,\(x\)最大只有\(9\)位,于是各数位上数字之和\(\leq 9*9=81\),循环\(81\)次\(check\)即可。
Code
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int ans[100];
int digit(int x) {
int ret = 0;
while (x) {
ret += x % 10;
x /= 10;
}
return ret;
}
int main() {
int n;
scanf("%d", &n);
int tot = 0;
for (int i = max(n-81,0); i <= n; ++i) {
if (i+digit(i) == n) ans[tot++] = i;
}
printf("%d\n", tot);
for (int i = 0; i < tot; ++i) printf("%d\n", ans[i]);
return 0;
}
D. Sorting the Coins
题意
给定一个全\(0\)的串,询问\(n\)次,每次在上一次询问的基础上将串中某一个指定位置处的\(0\)变为\(1\),并问经过多少次操作能够使整个串左边全\(0\),右边全\(1\).
一次操作:从左到右扫描,每遇到一个\(1\),如果它右边是\(0\),就将它与右边的\(0\)交换位置,再从下一个位置继续开始扫描直至结束。
思路
首先,最右边的若干个\(1\)是不用处理的;而对于其左边所有的没有与最右边那块连接起来的\(1\),效果上每次只能将其中一个(即最右边的那个)移到与最右边的若干个\(1\)合并。所以操作次数即为当前总的\(1\)的个数减去最右边的连续的\(1\)的个数。
又因为最右边的连续的\(1\)在整个过程中肯定是逐渐向左延伸的,故可以记录左端点每次看是否可以向左拓展,时间复杂度\(O(n)\).
Code
#include <bits/stdc++.h>
#define maxn 300010
using namespace std;
typedef long long LL;
bool a[maxn];
int main() {
int n;
scanf("%d", &n);
int l = n+1, r = n+1;
putchar('1');
for (int i = 1; i <= n; ++i) {
int x;
scanf("%d", &x);
a[x] = 1;
while (l > 1 && a[l-1]) --l;
printf(" %d", i+1-(r-l));
}
putchar('\n');
return 0;
}
小结
这样的题目...有些遗憾晚上有课没能打_(:з」∠)_
\(B\)和\(C\)都很普通;
\(D\)很快想出了其中的道道但关于写法还是绕了路,一开始是去记录最右边的没有与最右边的\(1\)连续的一块然后各种讨论后来发现不行;
\(A\)一上来还真被蒙住了_(:з」∠)_在讨论是走两条边还是三条边...好题好题.
说遗憾什么的...反正\(EF\)也不会做,\(ABCD\)又过了超级多_(:з」∠)_
不遗憾不遗憾。
Codeforces Round #441 Div. 2 A B C D的更多相关文章
- Codeforces Round #441 (Div. 2)【A、B、C、D】
Codeforces Round #441 (Div. 2) codeforces 876 A. Trip For Meal(水题) 题意:R.O.E三点互连,给出任意两点间距离,你在R点,每次只能去 ...
- Codeforces Round #441 (Div. 2)
Codeforces Round #441 (Div. 2) A. Trip For Meal 题目描述:给出\(3\)个点,以及任意两个点之间的距离,求从\(1\)个点出发,再走\(n-1\)个点的 ...
- [日常] Codeforces Round #441 Div.2 实况
上次打了一发 Round #440 Div.2 结果被垃圾交互器卡掉 $200$ Rating后心情复杂... 然后立了个 Round #441 要翻上蓝的flag QAQ 晚饭回来就开始搞事情, 大 ...
- Codeforces Round #441 (Div. 2, by Moscow Team Olympiad) D. Sorting the Coins
http://codeforces.com/contest/876/problem/D 题意: 最开始有一串全部由"O"组成的字符串,现在给出n个数字,指的是每次把位置n上的&qu ...
- Codeforces Round #441 (Div. 2, by Moscow Team Olympiad) C. Classroom Watch
http://codeforces.com/contest/876/problem/C 题意: 现在有一个数n,它是由一个数x加上x每一位的数字得到的,现在给出n,要求找出符合条件的每一个x. 思路: ...
- Codeforces Round #441 (Div. 2, by Moscow Team Olympiad) B. Divisiblity of Differences
http://codeforces.com/contest/876/problem/B 题意: 给出n个数,要求从里面选出k个数使得这k个数中任意两个的差能够被m整除,若不能则输出no. 思路: 差能 ...
- Codeforces Round #441 (Div. 2, by Moscow Team Olympiad) A. Trip For Meal
http://codeforces.com/contest/876/problem/A 题意: 一个人一天要吃n次蜂蜜,他有3个朋友,他第一次总是在一个固定的朋友家吃蜂蜜,如果说没有吃到n次,那么他就 ...
- Codeforces Round #441 (Div. 2, by Moscow Team Olympiad)
A. Trip For Meal 题目链接:http://codeforces.com/contest/876/problem/A 题目意思:现在三个点1,2,3,1-2的路程是a,1-3的路程是b, ...
- Codeforces Round #441 Div. 1
A:显然答案与原数的差不会很大. #include<iostream> #include<cstdio> #include<cmath> #include<c ...
- Codeforces Round #441(Div.2) F - High Cry
F - High Cry 题目大意:给你n个数,让你找区间里面所有数或 起来大于区间里面最大数的区间个数. 思路:反向思维,找出不符合的区间然后用总数减去.我们找出每个数掌控的最左端 和最右端,一个数 ...
随机推荐
- 3.Cisco Packet Tracer中关于交换机端口安全的设置
本次实验将在这幅拓扑图的基础上完成 我们会对pc0在交换机上进行mac地址绑定,pc1访问时则交换机断开端口 1.为pc机配置ip地址 pc0:192.168.1.1 pc1:192.168.1.2 ...
- 使用vscode开发vue cli 3项目,配置eslint以及prettier
初始化项目时选择eslint-config-standard作为代码检测规范,vscode安装ESLint和Prettier - Code formatter两个插件,并进行如下配置 { " ...
- .net core 获取浏览器UserAgent
这两天由于自己公司的机器磁盘不够用了,果断把VS2015卸载了,只留下VS2017 当我打开一个以前一个很简单的MVC4.0的项目时候 温馨提示要安装MVC4,我犹豫了一下,还是点了安装,接下来提示要 ...
- GoF23种设计模式之创建型模式之单态模式
1概述 保证一个类仅有一个实例,并提供一个访问它的全局访问点. 2适用性 1.当类只能有一个实例而且客户可以从一个总所周知的访问点访问它的时候. 2.当这个唯一实例应该是通过子类化可扩展的,并且客户应 ...
- 适合学习的QT开源项目-SerialTool
https://github.com/Skiars/SerialTool A cross platform Serial-Port/TCP/UDP debugging tool. SerialTool ...
- Codeforces:68A-Irrational problem(暴力大法好)
A- Irrational problem p Time Limit: 2000MS Memory Limit: 262144K 64bit IO Format: %I64d& %I64 De ...
- 【Remove Duplicates from Sorted List II 】cpp
题目: Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct ...
- Windows核心编程小结1
这本书绝对经典,看看定会增加不少知识.当然这本书有很多东西比<Windows程序设计第五版>中的更加详细. 1.Unicode:宽字节字符集 这是一个国际的字符标准,16位,最大可支持65 ...
- 获取表的字段例如 col1,col2,col3
create function [dbo].[f_getcolsByName](@tableName varchar(50)) returns varchar(1000)asbegin declare ...
- [oldboy-django][2深入django]分页功能
1 django自带分页 1.1 分页模板 <!DOCTYPE html> <html lang="en"> <head> <meta c ...