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 ...
随机推荐
- tar命令打包和压缩与解压
Linux里压缩与打包时分开的: 打包:多个文件变一个文件.该一个文件会大于整体所有文件,因为会添加各个信息说明哪到哪是一个文件. 压缩:大文件变小文件. 归档:将多个文件变成一个文件,这个文件就是归 ...
- 02 Filter过滤器
Filter 一.Filter过滤器 Filter过滤器它是JavaWeb的三大组件之一.三大组件分别是:Servlet程序.Listener监听器.Filter过滤器 Filter过滤器是JavaE ...
- 慢话crush-各种crush组合
前言 ceph已经是一个比较成熟的开源的分布式存储了,从功能角度上来说,目前的功能基本能够覆盖大部分场景,而社区的工作基本上是在加入企业级的功能和易用性还有性能等方面在发力在,不管你是新手还是老手,都 ...
- vue中父子间传值和非父子间传值
vue传值一般分三种方式:父组件向子组件传值.子组件向父子间传值.非父子组件进行传值 一.父组件向子组件传值:父组件引用子组件后,通过数据绑定(v-bind)向子组件传值 父组件: <templ ...
- Android ALSPS驱动分析
一.alsps的初始化函数和重要结构体 epl2182_init // Epl2182.c (kernel-3.10\drivers\misc\mediatek\alsps\epl2182-new) ...
- H5系列之video自己编写控制栏
首先来了解一下 video, video呢,是H5 的标签,别人说的 H5播放器,没错 就是他了,利用video标签,可以实现视频播放. 但是啊,你会发现,在不同的浏览器上,播放器的 控制栏,都是不一 ...
- 这可能是项目中最实用的java8示例了,还不来看?
一.组成及特点 数据源.中间操作.终端操作 流只能使用一次 并行流 和 串行流 二.可以产生流的数据源 集合.文件 三.中间操作 字符串操作拼接joining(""),底层实现是 ...
- ②SpringCloud 实战:引入Feign组件,完善服务间调用
这是SpringCloud实战系列中第二篇文章,了解前面第一篇文章更有助于更好理解本文内容: ①SpringCloud 实战:引入Eureka组件,完善服务治理 简介 Feign 是一个声明式的 RE ...
- 无效的HTTP_主机头Invalid HTTP_HOST header: '192.168.56.100:8888'. You may need to add '192.168.56.100' to ALLOWED_HOSTS.
Invalid HTTP_HOST header: '192.168.56.100:8888'. You may need to add '192.168.56.100' to ALLOWED_HOS ...
- python+selenium通过加载用户配置实现免登陆
1查看profile路径 在Chrome地址栏访问chrome://version,可以查看个人资料存储位置: 2 python代码如下: from selenium import webdriver ...