题目链接

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的更多相关文章

  1. Codeforces Round #441 (Div. 2)【A、B、C、D】

    Codeforces Round #441 (Div. 2) codeforces 876 A. Trip For Meal(水题) 题意:R.O.E三点互连,给出任意两点间距离,你在R点,每次只能去 ...

  2. Codeforces Round #441 (Div. 2)

    Codeforces Round #441 (Div. 2) A. Trip For Meal 题目描述:给出\(3\)个点,以及任意两个点之间的距离,求从\(1\)个点出发,再走\(n-1\)个点的 ...

  3. [日常] Codeforces Round #441 Div.2 实况

    上次打了一发 Round #440 Div.2 结果被垃圾交互器卡掉 $200$ Rating后心情复杂... 然后立了个 Round #441 要翻上蓝的flag QAQ 晚饭回来就开始搞事情, 大 ...

  4. Codeforces Round #441 (Div. 2, by Moscow Team Olympiad) D. Sorting the Coins

    http://codeforces.com/contest/876/problem/D 题意: 最开始有一串全部由"O"组成的字符串,现在给出n个数字,指的是每次把位置n上的&qu ...

  5. Codeforces Round #441 (Div. 2, by Moscow Team Olympiad) C. Classroom Watch

    http://codeforces.com/contest/876/problem/C 题意: 现在有一个数n,它是由一个数x加上x每一位的数字得到的,现在给出n,要求找出符合条件的每一个x. 思路: ...

  6. 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. 思路: 差能 ...

  7. Codeforces Round #441 (Div. 2, by Moscow Team Olympiad) A. Trip For Meal

    http://codeforces.com/contest/876/problem/A 题意: 一个人一天要吃n次蜂蜜,他有3个朋友,他第一次总是在一个固定的朋友家吃蜂蜜,如果说没有吃到n次,那么他就 ...

  8. 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, ...

  9. Codeforces Round #441 Div. 1

    A:显然答案与原数的差不会很大. #include<iostream> #include<cstdio> #include<cmath> #include<c ...

  10. Codeforces Round #441(Div.2) F - High Cry

    F - High Cry 题目大意:给你n个数,让你找区间里面所有数或 起来大于区间里面最大数的区间个数. 思路:反向思维,找出不符合的区间然后用总数减去.我们找出每个数掌控的最左端 和最右端,一个数 ...

随机推荐

  1. 在windows server 2008 64位服务器上配置php环境

    1.安装windows2008 R2 46位 安装2008 R2 关键步骤,网上有很多诸如此类的安装介绍.在些南昌网站建设公司百恒网络工程师就不作详细介绍.关键是要选择适合实际应用的部署.    2. ...

  2. JZOJ 1266. 玉米田

    1266. 玉米田(cowfood.pas/c/cpp) (File IO): input:cowfood.in output:cowfood.out Time Limits: 1000 ms  Me ...

  3. 使用shell脚本添加用户

    该文演示如何使用shell脚本完成添加用户,首先进行一个判断,如果用户存在,提示该用户已经存在,否则进行添加新的用户. 示例代码如下: #!/bin/bash grep_user() { R=`gre ...

  4. 4 Template层 -定义模板

    1.模板介绍 作为Web框架,Django提供了模板,可以很便利的动态生成HTML 模版系统致力于表达外观,而不是程序逻辑 模板的设计实现了业务逻辑(view)与显示内容(template)的分离,一 ...

  5. Go语言之并发编程(三)

    Telnet回音服务器 Telnet协议是TCP/IP协议族中的一种.它允许用户(Telnet客户端)通过一个协商过程与一个远程设备进行通信.本例将使用一部分Telnet协议与服务器进行通信. 服务器 ...

  6. IOS开发学习笔记037-九宫格代码实现

    九宫格布局,用手机输入法时经常见到.先按3行3列写. 代码的实现主要是计算插入图片的位置. 每一张图片的位置和所在的行列密切相关.分析过程如下: 界面: 代码实现 1.把需要的图片资源添加进来 然后给 ...

  7. 嵌入式之download

    ISP ISP(In-System Programming)在系统可编程,指电路板上的空白器件可以编程写入最终用户代码, 而不需要从电路板上取下器件,已经编程的器件也可以用ISP方式擦除或再编程.IS ...

  8. XSS Challenges(1-12关)

    XSS Challenges解析: 1. 什么过滤也没有,而且是直接输出.<scrip>alert(document.domain);</script>即可通过 2. 直接输入 ...

  9. python - web自动化测试 - 元素操作 - 等待

    # -*- coding:utf-8 -*- ''' @project: web学习 @author: Jimmy @file: wait.py @ide: PyCharm Community Edi ...

  10. linux/mac下的配置自定义命令alias

    linux/mac下的自定义命令alias,并保存别名使其永久生效(重启不会失效) 在做开发每次提交代码的命令都是一长串参数,不想去记,于是可以使用alias命令来解决这个问题:alias aComm ...