Codeforces Edu Round 60 A-E
A. Best Subsegment
显然,选择数列中的最大值当做区间(长度为\(1\))。只要尝试最大值这个区间是否能扩展(左右两边值是否跟它一样就行了)
#include <cstdio>
#include <iostream>
#include <cmath>
using namespace std;
const int N = 100010;
int n, a[N], val = -1, res = -1;
int main(){
scanf("%d", &n);
for(int i = 1; i <= n; i++) {
scanf("%d", a + i);
val = max(val, a[i]);
}
int len = 0;
for(int i = 1; i <= n; i++){
if(a[i] == val) len ++;
else len = 0;
res = max(res, len);
}
printf("%d\n", res);
return 0;
}
B. Emotes
贪心。让总和最大,考虑可以尽量选最大的,每次选\(k\)次,然后选一个第二大的,接着选\(k\)次最大的...就这样轮替。这个过程可以用取余来快速完成,每一轮的次数是\(k + 1\)。
#include <cstdio>
#include <iostream>
#include <cmath>
using namespace std;
typedef long long LL;
const int N = 200010;
int n, m, k, a[N], max1 = -1, max2 = -1;
LL res = 0;
int main(){
scanf("%d%d%d", &n, &m, &k);
for(int i = 1; i <= n; i++) {
scanf("%d", a + i);
if(a[i] > max1){
max2 = max1;
max1 = a[i];
}else if(a[i] > max2){
max2 = a[i];
}
}
int num = m / (k + 1), ot = m % (k + 1);
printf("%lld\n", (LL)num * k * max1 + (LL)num * max2 + (LL)ot * max1);
return 0;
}
C. Magic Ship
二分答案。容易看出,时刻符合单调性。若\(d\)天能到,那么\(d + 1\)也能到。因为可以保持跟风相反的方向就可以保持不动,晚一个时刻在到。如果设置\(check\)函数,我们先把这些天风走的走完,再看现在的曼哈顿距离是否够天数走完的即可。对于二分答案的上界,可以设置为\(1e14\),最坏情况所有\(n\)次只有一次是顺方向,剩下都是逆方向,那么每\(n\)次只能动\(2\)步,结合最大需求曼哈顿是\(1e9 * 2 = 2e9\),所以最高时间就是\(n * 2e9 / 2 = 100000 * 2e9 / 2 = 1e14\)。
#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
using namespace std;
const int N = 100010;
typedef long long LL;
int x, y, x2, y2, n, sum[N][2];
char s[N];
//检查x时间是否可行。
bool check(LL d){
LL nx = x, ny = y;
nx += (d / n) * sum[n][0] + sum[d % n][0];
ny += (d / n) * sum[n][1] + sum[d % n][1];
return abs(x2 - nx) + abs(y2 - ny) <= d;
}
int main(){
scanf("%d%d%d%d%d%s", &x, &y, &x2, &y2, &n, s + 1);
for(int i = 1; i <= n; i++){
sum[i][1] += sum[i - 1][1] + (s[i] == 'U');
sum[i][1] -= (s[i] == 'D');
sum[i][0] -= (s[i] == 'L');
sum[i][0] += sum[i - 1][0] + (s[i] == 'R');
}
if(!check(1e14)) puts("-1");
else{
LL l = 1, r = 1e14;
while(l < r){
LL mid = (l + r) >> 1;
if(check(mid))r = mid;
else l = mid + 1;
}
printf("%lld\n", r);
}
return 0;
}
D. Magic Gems
考虑\(dp\),每次有两个决策,一个是放\(m\)个普通宝石,或者放一个\(1\)个魔法宝石。
设\(f[i]\)为填i个区间的方案数,状态转移方程\(f[i] = f[i - 1] + f[i - m]\)
初始化\(f[1] = f[2] = ... = f[m - 2] = f[m - 1] = 1\)。
然后我就不会优化了...只能看题解,发现要用矩阵快速幂 or 杜教优化,但是本蒟蒻两个都不会,所以这个坑以后再填...
E. Decypher the String
我自闭了。既然可以二进制确定一个范围,那么我们尝试\(26\)进制系列,因为字母各不相同可以确定转换位置。由于\(26 ^ 2 < 10000 < 26 ^ 3\),范围之内可以解决。
询问三个分别如下:
- \(aaaa(26 * 26)bbbb(26 * 26)...zzzz(26 * 26)\)
- \(aaaa(26)bbbb(26)...zzzz(26)aaaa...\)
- \(abcdefghijklmn...xyzabcd...xyz...\)
这样每一步可以将答案缩小至原来的\(\frac{1}{26}\),在范围可以解决问题。
为了方便找到交集,我们用\(bitset\)即可。
PS:这毒瘤输入输出...这个它提示我输入格式不正确。
#include <cstdio>
#include <iostream>
#include <bitset>
#include <cstring>
using namespace std;
const int N = 10000;
char str[N], s[3][N], ans[N];
bitset<N> a[3][26];
int n;
int main(){
scanf("%s", str);
n = strlen(str);
for(int i = 0; i < n; i++)
for(int j = 0, t = i; j < 3; j++)
s[j][i] = t % 26 + 'a', t /= 26;
for(int i = 0; i < 3; i++){
printf("? %s\n", s[i]), fflush(stdout), scanf("%d", s[i]);
}
for(int i = 0; i < 3; i++)
for(int j = 0; j < n; j++)
a[i][s[i][j] - 'a'].set(i);
for(int i = 0; i < n; i++){
bitset<N> u;
for(int j = 0, t = i; j < 3; j++)
u &= a[j][t % 26], t /= 26;
for(int j = 0; j < n; j++)
if(u[j]) { ans[i] = str[j]; break; }
}
printf("! %s\n", ans);
return 0;
}
然后我改成单个的就对了,wtf????
#include <cstdio>
#include <iostream>
#include <bitset>
#include <cstring>
using namespace std;
const int N = 10005;
char str[N], s1[N], s2[N], s3[N], ans[N];
bitset<N> a[3][26], now;
int n;
int main(){
scanf("%s", str);
n = strlen(str);
for (int i = 0; i< n; ++i) {
int t = i;
s1[i] = 'a' + t % 26; t /= 26;
s2[i] = 'a' + t % 26; t /= 26;
s3[i] = 'a' + t % 26; t /= 26;
}
printf("? "); puts(s1); fflush(stdout); scanf("%s", s1);
printf("? "); puts(s2); fflush(stdout); scanf("%s", s2);
printf("? "); puts(s3); fflush(stdout); scanf("%s", s3);
for (int i = 0; i < n; ++i) a[0][s1[i] - 'a'].set(i);
for (int i = 0; i < n; ++i) a[1][s2[i] - 'a'].set(i);
for (int i = 0; i < n; ++i) a[2][s3[i] - 'a'].set(i);
for (int i = 0; i < n; ++i) {
int t = i;
now = a[0][t % 26]; t /= 26;
now &= a[1][t % 26]; t /= 26;
now &= a[2][t % 26]; t /= 26;
for (int j = 0; j < n; ++j)
if (now[j]) { ans[i] = str[j]; break; }
}
printf("! %s\n", ans);
return 0;
}
原因应该是字符数组二维读入上和输出没有好的规定......
Codeforces Edu Round 60 A-E的更多相关文章
- Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship
Problem Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...
- Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)
Problem Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...
- Educational Codeforces Round 60 (Rated for Div. 2) 题解
Educational Codeforces Round 60 (Rated for Div. 2) 题目链接:https://codeforces.com/contest/1117 A. Best ...
- Codeforces Beta Round #13 C. Sequence (DP)
题目大意 给一个数列,长度不超过 5000,每次可以将其中的一个数加 1 或者减 1,问,最少需要多少次操作,才能使得这个数列单调不降 数列中每个数为 -109-109 中的一个数 做法分析 先这样考 ...
- Codeforces Beta Round #80 (Div. 2 Only)【ABCD】
Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...
- Codeforces Beta Round #62 题解【ABCD】
Codeforces Beta Round #62 A Irrational problem 题意 f(x) = x mod p1 mod p2 mod p3 mod p4 问你[a,b]中有多少个数 ...
- Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】
Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...
- CodeForces Global Round 1
CodeForces Global Round 1 CF新的比赛呢(虽然没啥区别)!这种报名的人多的比赛涨分是真的快.... 所以就写下题解吧. A. Parity 太简单了,随便模拟一下就完了. B ...
- Codeforces Global Round 1 - D. Jongmah(动态规划)
Problem Codeforces Global Round 1 - D. Jongmah Time Limit: 3000 mSec Problem Description Input Out ...
随机推荐
- 加速OSD的启动
ceph是目前开源分布式存储里面最好的一个,但是在高负载下会有很多异常的情况会发生,有些问题无法完全避免,但是可以进行一定的控制,比如:在虚拟化场景下,重启osd会让虚拟机挂起的情况 重新启动osd会 ...
- [LeetCode题解]24. 两两交换链表中的节点 | 递归
方法一:递归 解题思路 递归法,假设后续链表已经完成交换,此时只需要对前两个节点进行交换,然后再连接上后续已交换的链表即可. 代码 /** * Definition for singly-linked ...
- Netty源码解析 -- 内存对齐类SizeClasses
在学习Netty内存池之前,我们先了解一下Netty的内存对齐类SizeClasses,它为Netty内存池中的内存块提供大小对齐,索引计算等服务方法. 源码分析基于Netty 4.1.52 Nett ...
- java中高级面试利器(boot,cloud,vue前后端提升)
https://github.com/Snailclimb/JavaGuide Java知识大全(面试) https://github.com/doocs/advanced-java Java工 ...
- OCR之前这些因素必须考虑到!
用久了ABBYY FineReader 14OCR文字识别软件,相信大家都知道图像质量对OCR质量有很大的影响,本文将给大家讲解下在识别图像之前,有哪些因素需要考虑到! 1.OCR语言 ABBYY F ...
- Folx使用教程:怎么通过设置标签分类下载内容
很多Mac OS下载软件从网上下载各种各样的文件,一般默认都会存放在"下载"文件夹中.如果不是经常整理"下载"文件夹,久而久之,该文件夹会变得庞大而杂乱. 如果 ...
- JPA query between的多种方式(mongodb为例)
背景 JPA+MongoDB查询,给定一段时间范围查询分页结果,要求时间范围包含. Page<Log> findByCtimeBetweenOrderByCtime( LocalDateT ...
- 【C++】数组中的第k个最小元素
分治思想求解的问题,但是比较特殊,只有分解问题和求解小问题,不需要合并 每次也只需要经过判断,分解一半,所以比其他分解两边的效率高 最坏情况时间复杂度为O(n^2),期望时间复杂度为O(n) 找基准值 ...
- Win10定期执行python程序
一:windows10自带的计划程序 第一步:在 计算器右击 --> 选择管理 进入如下界面: 第二步:选择 系统工具 --> 任务计划程序 ,点击右侧的 "创建基本任务&q ...
- LaTeX相关自学文档
install-latex-guide-zh-cn: lshort-zh-cn: 百度网盘链接:https://pan.baidu.com/s/1cBv9Fu8KFaf0QFZ7_slxmw 提取码: ...