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 3028 食物 —— 生成函数

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3028 式子很好推,详细可以看这篇博客:https://blog.csdn.net/wu_to ...

  2. android自动化测试之uiautomator

    1.通过monkeyrunner.bat   monkey_record.py启动MonkeyRecorder进行拿到各个控件的坐标(要连上手机才可以启动) 2.也可以通过uiautomatorvie ...

  3. libvirt监控

  4. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">详解

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  5. VS Supercharger插件

    一.前言 Supercharger 是 VS 的一款插件,针对代码进行优化和着色,便于观察和区分. 二.下载及安装 下载的 URL 如下:Supercharger 下载地址 点击下载,下载完成以后,那 ...

  6. [开源]OSharpNS - .net core 快速开发框架 - 快速开始

    什么是OSharp OSharpNS全称OSharp Framework with .NetStandard2.0,是一个基于.NetStandard2.0开发的一个.NetCore快速开发框架.这个 ...

  7. Lightoj1003【判环操作】

    题意: 对于n个给出字符串a,b,理解成a在b之前办好这个事情,要求n个给出两个串,a都要在b之前完成: 题意: 所以一旦出现环就不行了: 以前在写最短路的时候,spfa就有一个判环,后来写着写着写到 ...

  8. HDU 3729【二分匹配】

    题意: 给出n个同学的排名,代表每个排名在哪个区间,要求保证最多人说的是实话,并在此前提下求一个说真话人最大字典序. 思路: 最后感觉就是点去填区间,点和区间建个边,然后跑个二分图,然后sort一发. ...

  9. [Xcode 实际操作]八、网络与多线程-(1)使用Reachability类库检测网络的连接状态

    目录:[Swift]Xcode实际操作 本文将演示如何使用Reachability网络状态检测库,检测设备的网络连接状态. 需要下载一个开源的类库:[ashleymills/Reachability. ...

  10. [Xcode 实际操作]九、实用进阶-(28)在iTunes Connect(苹果商店的管理后台)中创建一个新的新的APP

    目录:[Swift]Xcode实际操作 本文将演示如何在iTunes Connect(苹果商店的管理后台)中创建一个新的新的APP. 首先要做的是打开浏览器,并进入[iTunesConnect网站], ...