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. 「LuoguP3796」 【模板】AC自动机(加强版)

    题目描述 有N个由小写字母组成的模式串以及一个文本串T.每个模式串可能会在文本串中出现多次.你需要找出哪些模式串在文本串T中出现的次数最多. 输入输出格式 输入格式: 输入含多组数据. 每组数据的第一 ...

  2. Oracle数据库当前连接数、最大连接数的查询与设置

    在开发过程中Oracle数据库有时候连得上,有时候又连不上,提示如下异常“ORA-12519: TNS:no appropriate service handler found 解决”,可能是数据库上 ...

  3. setData 设置某个数组或者数组对象的值

    demo:list是一个对象数组,设置list数组某个对象的值 下标是动态index的value值 let item='list['+index+'].value'; this.setData({ [ ...

  4. socket学习目录

    深入探析c# Socket http://www.cnblogs.com/tianzhiliang/archive/2010/09/08/1821623.html Http和Socket连接区别 ht ...

  5. js搜索相同类型的控件全选、取值(Checkbox)

    function selectAll(obj) { if (obj.checked) { $("input[type='checkbox']").each(function () ...

  6. json : json数据解析(一)

    在项目中经常用到json格式的数据转换与解析,先前写过一些小例子,现在整理下,以备后用和帮助后来者. 言归正传: 使用到的jar包 :json-lib-2.4-jdk15.jar,当然你也可以用自己版 ...

  7. C++ TUTORIAL - MEMORY ALLOCATION - 2016

    http://www.bogotobogo.com/cplusplus/memoryallocation.php Variables and Memory Variables represent st ...

  8. TypeScript完全解读(26课时)_7.ES6精讲 - 类Class基础

    ES6精讲 - 类Class基础 es5中创建构造函数和实例 原来在es5中的写法 定义好Point后,在原型对象上定义getPostion的方法 实例自身是没有这个方法的,我们调用的时候会去创建他的 ...

  9. C#基础:使用Thread创建线程

    Thread类可以创建和控制线程,Thread类的构造函数重载为接受ThreadStart和ParameterizedThreadStart类型的委托参数.下面我们用一个例子来解释怎样用Thread类 ...

  10. Spring Boot + Vue 前后端分离开发,前端网络请求封装与配置

    前端网络访问,主流方案就是 Ajax,Vue 也不例外,在 Vue2.0 之前,网络访问较多的采用 vue-resources,Vue2.0 之后,官方不再建议使用 vue-resources ,这个 ...