Codeforces Round #505 Div. 1 + Div. 2
传送门:>Here<
从来没打过\(CF\)(由于太晚了)…… 不知道开学了以后有没有机会能够熬夜打几场,毕竟到现在为止都是\(unrated\)好尴尬啊~
今天早上打了几题前几天的比赛题……
A. \(Doggo \ Recoloring\)
此题应当是签到题,但我还是傻了很久。很容易发现只要有任意一种狗的颜色超过\(1\),那么这种狗就是可以变色的。那么它永远只需要变为任意一个与他相邻的狗的颜色,数量不会减少反而增多。因此可以不停变下去。于是我们只需要统计一下是否有一种颜色是大于等于两个的
代码就不贴了
B. \(Weakened \ Common \ Divisor\)
题意为给出\(N\)个整数对,要求找出任意一个数,能够被任意一对中的其中一个数整除。称为\(WCD\)
我的想法是先预处理出第一对的两个数的所有因子,然后遍历所有处理出来的因子,遍历后面的每一对——如果当前因子合法就输出。最后留下来的因子里随便取一个即可。\(T\)了第\(45\)个点……
事实上慢就慢在我们不能够处理因子,而是应当处理素因子。因为如果一个非素数\(x\)能够作为\(WCD\),那么\(x\)的所有素因子肯定都可以满足。
/*By DennyQi 2018*/
#include <cstdio>
#include <queue>
#include <cstring>
#include <algorithm>
#include <cmath>
#define r read()
using namespace std;
typedef long long ll;
const int MAXN = 10010;
const int MAXM = 20010;
const int INF = 1061109567;
inline int Max(const int a, const int b){ return (a > b) ? a : b; }
inline int Min(const int a, const int b){ return (a < b) ? a : b; }
inline int read(){
int x = 0; int w = 1; register char c = getchar();
for(; c ^ '-' && (c < '0' || c > '9'); c = getchar());
if(c == '-') w = -1, c = getchar();
for(; c >= '0' && c <= '9'; c = getchar()) x = (x<<3) + (x<<1) + c - '0'; return x * w;
}
int N,lim,t1;
ll f[200010],a[200010],b[200010];
inline void Fenjie(ll a){
for(ll i = 2; i * i <= a; ++i){
if(a % i == 0){
f[++t1] = i;
while(a % i == 0){
a /= i;
}
}
}
if(a > 1){
f[++t1] = a;
}
}
int main(){
N = r;
for(int i = 1; i <= N; ++i){
a[i] = r, b[i] =r ;
}
Fenjie(a[1]);
Fenjie(b[1]);
bool flg = 0;
for(int i = 1; i <= t1; ++i){
flg = 0;
for(int j = 2; j <= N; ++j){
if((a[j]%f[i] != 0) && (b[j]%f[i] != 0)){
flg = 1;
break;
}
}
if(!flg){
printf("%lld", f[i]);
return 0;
}
}
printf("-1");
return 0;
}
C. \(Plasticine \ zebra\)
给出一个字符串,每个字符不是\(b\)就是\(w\)。每一次操作可以选择一个断点,然后让断点两边的全部翻转。无论操作几次。定义一个斑马串,其相邻元素不重复、问最大的斑马串是多长?也就是要通过若干次操作找到最长的\(bwbwbw..\)或\(wbwbwb...\)
找到一个断点然后两边都翻转实际上是可以等价的。例如一个字符串\(abcdefgh\),在\(c\)后面断了,那么就变为\(abc \ | \ defgh\),翻转后得到\(cbahgfed\)。我们发现其等价于\(abc\)放到\(defgh\)后面,然后整个翻转。而如果我们找到了一个斑马串,其翻过来依然是斑马串。因此我们只需要把字符串本身复制一遍接在后面,然后在这个两倍的字符串中找到最长的斑马串。(长度不能超过\(N\))。
为什么这样就好了呢?依然距离,将\(abcdefg\)复制一遍得到\(abcdefgabcdefg\)。任取一段长度为\(N\)的连续的子序列,其头尾相当于断点。因此这就相当于枚举了断点了
/*By DennyQi 2018*/
#include <cstdio>
#include <queue>
#include <cstring>
#include <algorithm>
#define r read()
using namespace std;
typedef long long ll;
const int MAXN = 10010;
const int MAXM = 20010;
const int INF = 1061109567;
inline int Max(const int a, const int b){ return (a > b) ? a : b; }
inline int Min(const int a, const int b){ return (a < b) ? a : b; }
inline int read(){
int x = 0; int w = 1; register char c = getchar();
for(; c ^ '-' && (c < '0' || c > '9'); c = getchar());
if(c == '-') w = -1, c = getchar();
for(; c >= '0' && c <= '9'; c = getchar()) x = (x<<3) + (x<<1) + c - '0'; return x * w;
}
int N,ans;
char s[200010];
int f[200010];
int main(){
scanf("%s", s);
N = strlen(s);
for(int i = N; i < 2 * N; ++i) s[i] = s[i-N];
for(int i = 0; i < 2 * N; ++i){
if(i - 1 >= 0){
if(s[i] != s[i-1]){
f[i] = f[i-1] + 1;
}
else{
f[i] = 1;
}
}
else{
f[i] = 1;
}
if(f[i] <= N){
ans = Max(ans, f[i]);
}
}
printf("%d", ans);
return 0;
}
另外的几道题暂时还没做,有时间再更吧……
Codeforces Round #505 Div. 1 + Div. 2的更多相关文章
- 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 43 (Rated for Div. 2)
Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...
- Educational Codeforces Round 35 (Rated for Div. 2)
Educational Codeforces Round 35 (Rated for Div. 2) https://codeforces.com/contest/911 A 模拟 #include& ...
- Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings
Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings 题目连接: http://cod ...
- Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes
Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes 题目连接: http://code ...
- Educational Codeforces Round 63 (Rated for Div. 2) 题解
Educational Codeforces Round 63 (Rated for Div. 2)题解 题目链接 A. Reverse a Substring 给出一个字符串,现在可以对这个字符串进 ...
- Educational Codeforces Round 39 (Rated for Div. 2) G
Educational Codeforces Round 39 (Rated for Div. 2) G 题意: 给一个序列\(a_i(1 <= a_i <= 10^{9}),2 < ...
- Educational Codeforces Round 48 (Rated for Div. 2) CD题解
Educational Codeforces Round 48 (Rated for Div. 2) C. Vasya And The Mushrooms 题目链接:https://codeforce ...
- Educational Codeforces Round 60 (Rated for Div. 2) 题解
Educational Codeforces Round 60 (Rated for Div. 2) 题目链接:https://codeforces.com/contest/1117 A. Best ...
随机推荐
- 朱晔和你聊Spring系列S1E5:Spring WebFlux小探
阅读PDF版本 本文会来做一些应用对比Spring MVC和Spring WebFlux,观察线程模型的区别,然后做一下简单的压力测试. 创建一个传统的Spring MVC应用 先来创建一个新的web ...
- Linux stress 命令
stress 命令主要用来模拟系统负载较高时的场景,本文介绍其基本用法.文中 demo 的演示环境为 ubuntu 18.04. 基本语法 语法格式:stress <options> 常用 ...
- Python学习资源汇总,转载自他人
python3英文视频教程(全87集) http://pan.baidu.com/s/1dDnGBvV python从入门到精通视频(全60集)链接:http://pan.baidu.com/s/1e ...
- iOS中的截屏(屏幕截屏及scrollView或tableView的全部截屏)
iOS中的截屏(屏幕截屏及scrollView或tableView的全部截屏) 2017.03.16 12:18* 字数 52 阅读 563评论 4喜欢 2 1. 截取屏幕尺寸大小的图片并保存至相册 ...
- python 的内存回收,及深浅Copy详解
一.python中的变量及引用 1.1 python中的不可变类型: 数字(num).字符串(str).元组(tuple).布尔值(bool<True,False>) 接下来我们讲完后你就 ...
- Django之用户上传文件的参数配置
Django之用户上传文件的参数配置 models.py文件 class Xxoo(models.Model): title = models.CharField(max_length=128) # ...
- Angular ngRepea
<!DOCTYPE html><html ng-app><head lang="en"> <meta charset="UTF- ...
- vue.js 添加 fastclick的支持
fastclick:处理移动端click事件300毫秒延迟 1.兼容性 iOS 3及更高版本的移动Safari iOS 5及更高版本的Chrome Android上的Chrome(ICS) Opera ...
- idea中 maven打包时时报错User setting file does not exist C:\Users\lenevo\.m2\setting.xml,
第一种错误 :idea中 maven打包时时报错User setting file does not exist C:\Users\lenevo\.m2\setting.xml, 解决方案如下:将ma ...
- DAY01、计算机组成及操作系统
一.编程与编程的目的: 1.什么是语言?什么是编程语言? 语言是一事物与另一事物之间沟通的介质 编程语言就是程序员与计算机之间沟通的介质 2.什么是编程? 程序员把自己想要让计算机做的事用编程语言表达 ...