hackforces + fstforces

A

很明显当有一个字母出现次数>1时即合法

$n = 1$的情况需要特判

#include<cstdio>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<set>
#include<map>
#define Pair pair<int, int>
#define fi first
#define se second
#define MP(x, y) make_pair(x, y)
//#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1<<22, stdin), p1 == p2) ? EOF : *p1++)
//char buf[(1 << 22)], *p1 = buf, *p2 = buf;
const int MAXN = 1e6 + ;
using namespace std;
inline int read() {
char c = getchar(); int x = , f = ;
while(c < '' || c > '') {if(c == '-') f = -; c = getchar();}
while(c >= '' && c <= '') x = x * + c - '', c = getchar();
return x * f;
}
int N;
char s[MAXN];
int num[MAXN];
int main() {
N = read();
if(N == ) {
puts("Yes"); return ;
}
scanf("%s", s + );
bool flag = ;
for(int i = ; i <= N; i++) {
num[s[i]]++;
if(num[s[i]] >= ) flag = ;
}
puts(flag == ? "Yes" : "No");
return ;
}
/* */

A

B

我的做法比较naive,直接对第一对数分解质因数,然后依次判断是否可行即可

TM一开始读错题了以为要输出最大的白浪费半个小时

#include<cstdio>
#include<cstdlib>
const int MAXN = 1e6 + ;
int N, a[MAXN], b[MAXN], prime[MAXN], vis[MAXN * ], tot = ;
void check(int val) {
for(int i = ; i <= N; i++) if((a[i] % val) && (b[i] % val)) return ;
printf("%d", val); exit();
}
void work(int x) {
for(int i = ; i * i <= x; i++)
if(x % i == ) {check(i); while(x % i == ) x /= i;}
if(x != )check(x);
}
main() {
scanf("%d", &N);
for(int i = ; i <= N; i++) scanf("%d %d", &a[i], &b[i]);
work(a[]); work(b[]);
puts("-1");
return ;
}

C

C

自己手玩一下就可以发现:把字符串从某一位置劈开再旋转无非就是换一种读字符串的方式

那么只要在字符串的所有循环阅读方式中找一个交错序列最长的就行

可以通过拼接一次实现

#include<cstdio>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<set>
#include<map>
#define Pair pair<int, int>
#define fi first
#define se second
#define MP(x, y) make_pair(x, y)
#define int long long
//#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1<<22, stdin), p1 == p2) ? EOF : *p1++)
//char buf[(1 << 22)], *p1 = buf, *p2 = buf;
const int MAXN = 1e6 + ;
using namespace std;
inline int read() {
char c = getchar(); int x = , f = ;
while(c < '' || c > '') {if(c == '-') f = -; c = getchar();}
while(c >= '' && c <= '') x = x * + c - '', c = getchar();
return x * f;
}
int N;
char s[MAXN];
main() {
scanf("%s", s + );
N = strlen(s + );
for(int i = ; i <= N; i++) s[i + N] = s[i];
int mx = , cur = ;
N <<= ;
for(int i = ; i <= N; i++)
if(s[i] == s[i - ]) mx = max(mx, cur), cur = ;
else cur++;
mx = max(cur, mx);
printf("%d", min(N / , mx + ));
return ;
}
/*
bwbwbw
*/

C

D

比赛的时候一直以为是xjb贪心,居然忘了大力dp qwq

首先考虑一个很显然的区间dp, $f[l][r][root]$表示$(l, r)$区间内,以$root$为根是否可行

转移的时候需要枚举根,以及左儿子的根,右儿子的根。时间复杂度为$n ^ 4$

考虑我们在转移的时候仅仅需要知道左右儿子是否能拼接起来,因此我们换一种表示方法

$L[l][r]$表示以$r$为根,向左能否扩展到$l$

$R[l][r]$表示以$l$为根,向右能否扩展到$r$

转移的时候仍然需要枚举根节点,但是不需要枚举左右儿子。

时间复杂度$O(n^3)$

#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
const int MAXN = ;
int N;
int a[MAXN], can[MAXN][MAXN], L[MAXN][MAXN], R[MAXN][MAXN], ans[MAXN][MAXN];
int main() {
cin >> N;
for(int i = ; i <= N; i++) cin >> a[i], L[i][i] = R[i][i] = ;
for(int i = ; i <= N; i++)
for(int j = i + ; j <= N; j++)
can[i][j] = can[j][i] = (__gcd(a[i], a[j]) > );
for(int len = ; len <= N; len++)
for(int l = ; l + len - <= N; l++) {
int r = l + len - ;
for(int k = l; k <= r; k++)
if(L[l][k] && R[k][r])
ans[l][r] = , L[l][r + ] |= can[k][r + ], R[l - ][r] |= can[l - ][k];
}
puts(ans[][N] ? "Yes" : "No");
return ;
}

D

E

F

据说是原题?fateice大爷抄了题解?https://blog.csdn.net/lych_cys/article/details/51000549

G

codeforces1025的更多相关文章

随机推荐

  1. BZOJ_2216_[Poi2011]Lightning Conductor_决策单调性

    BZOJ_2216_[Poi2011]Lightning Conductor_决策单调性 Description 已知一个长度为n的序列a1,a2,...,an. 对于每个1<=i<=n, ...

  2. jquery跨域3

    这两天用 Jquery 跨域取数据的时候,经常碰到 invalid label 这个错误,十分的郁闷,老是取不到服务器端发送回来的 json 值, 一般跨域用到的两个方法为:$.ajax 和$.get ...

  3. IntelliJ IDEA 2018 设置代码提示对大小写不敏感

    setting->Editor->General->Code Completion取消勾选Match case

  4. vue 常用的表单验证,包括手机号码,固定电话和身份证...

    <template> <div> <pl-content-box> <pl-page-nav :show-previous=true></pl-p ...

  5. Linux线程退出、资源回收、资源清理的方法

    首先说明线程中要回收哪些资源,理解清楚了这点之后在思考资源回收的问题. 1.子线程创建时从父线程copy出来的栈内存; 线程退出有多种方式,如return,pthread_exit,pthread_c ...

  6. bzoj 2006 [NOI2010]超级钢琴——ST表+堆

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2006 每个右端点的左端点在一个区间内:用堆记录端点位置.可选区间,按价值排序:拿出一个后也许 ...

  7. 【旧文章搬运】深入分析Win7的对象引用跟踪机制

    原文发表于百度空间及看雪论坛,2010-09-12 看雪论坛地址:https://bbs.pediy.com/thread-120296.htm============================ ...

  8. OutputDebugString()输出调试的使用

  9. SpannableStringBuilder 用法浅析以及仿陌陌表情

    SpannableStringBuilder  官方文档解释:这个类可以使文本的内容和标记都可以改变.当我们要为TextView或者Edittext里面的文字加入加入一些效果,如下划线,颜色标 识,超 ...

  10. 20个Flutter实例视频教程-第02节: 底部导航栏制作-2

    视频地址: https://www.bilibili.com/video/av39709290?p=2 博客地址: https://jspang.com/post/flutterDemo.html#t ...