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. java第五天之---方法与数组

    案例一:从键盘输入两个数据,比较大小 import java.util.Scanner;class FunctionTest { public static void main(String[] ar ...

  2. bzoj 5092 分割序列 —— 高维前缀和

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=5092 首先,处理出异或前缀和 s[i],i 位置的答案就是 s[j] + s[j]^s[i] ...

  3. js遍历checkbox获取数据

    function GetCurrenetPoint() { debugger var currentTypes = ""; var display = $("#input ...

  4. 页面跳转问题,多次 push 到新的页面的问题的解决方法

    今日在做一个扫一扫的功能,突然发现多次点击了扫一扫的图片后,造成多次触发轻拍手势,就多次push到新的页面,本想在轻拍手势内对push的进行拦截,但是又觉得如果有好多的地方都要实现对该问题的解决岂不是 ...

  5. 【224】◀▶ IDL NetCDF 文件操作说明

    参考:I/O - NetCDF Routines —— NetCDF 操作函数 01   NCDF_OPEN 打开一个 NetCDF 文件. 02   NCDF_CLOSE 关闭一个 NetCDF 文 ...

  6. CodeForces 1098E. Fedya the Potter

    题目简述:给定长度为$n \leq 5\times 10^4$的序列$a_1, a_2, \dots, a_n \leq 10^5$.将$\gcd(a_l, a_{l+1}, \dots, a_r) ...

  7. Using MultiPath TCP to enhance home networks

    Over the last few months I’ve been playing with MultiPath TCP and in this post I will show how I use ...

  8. c++中stl----vector

    1 vector是啥玩意 (1)可以使用下标访问个别的元素 (2)迭代器可以按照不同的方式遍历 (3)可以在容器的末尾增加或者删除元素 2 容器大小和容器的容量区别 (1)大小是元素的个数,容量是分配 ...

  9. 【Linux学习】Linux文件系统2—linux常用目录结构、绝对路径、相对路径

    Linux文件系统2-linux常用目录结构.绝对路径.相对路径 一. 常见目录结构总结 Linux目录结构就是"树形结构",常见的目录结构: /bin  系统需要的命令位于此目录 ...

  10. TypeScript完全解读(26课时)_9.TypeScript完全解读-TS中的类

    9.TypeScript完全解读-TS中的类 创建class.ts文件,并在index.ts内引用 创建一个类,这个类在创建好后有好几个地方都标红了 这是tslint的一些验证规则 一保存就会自动修复 ...