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. Gibonacci number-斐波那契数列

    Description In mathematical terms, the normal sequence F(n) of Fibonacci numbers is defined by the r ...

  2. MTCNN人脸检测识别笔记

    论文:Joint Face Detection and Alignment using Multi-task Cascaded Convolutional Networks 论文链接:https:// ...

  3. 网络应用软件结构-----CS与BS结构(网络基本知识小结)

    1.网络的大致结构 2.网络编程 通过直接或间接地使用网络通讯的协议实现计算机与计算机之间的通讯.在TCP/IP协议层主要麦网络主机的定位,数据传输的路由,由IP地址可以唯一地确定Internet上的 ...

  4. java定时器Timer的使用

    Time类主要负责完成定时计划任务的功能,就是在指定的时间的开始执行某个任务. Timer类的作用是设置计划任务,而封装任务内容的类是TimerTask类.此类是一个抽象类,继承需要实现一个run方法 ...

  5. java mysql编码问题

    今天使用jdbc连接数据库,sql语句明明是正确的,可就是查不到数据,问题是编码问题,好大的坑啊!!! 我的问题:where语句带汉字找不到信息,如果是英文却可以 第一步:在url后面加上如下的utf ...

  6. Ubuntu 下编译libjingle-0.6.14 (转载)

    转自:http://blog.csdn.net/feifei454498130/article/details/8197103 添加依赖库: sudo apt-get install build-es ...

  7. 201621123016《Java程序设计》第1周学习总结

    1. 本周学习总结 本周的学习内容:java的发展历史,java程序设计环境,java简单语法. java与c++一样是一门面向对象的程序设计语言(相比于c++它是一门更彻底的面向对象的程序设计语言) ...

  8. Codeforces691A【读题-水】

    妈蛋wa了两次.. 时尚的定义是length大于1的要破个洞,一定要破个洞.. According to rules of the Berland fashion, a jacket should b ...

  9. [Xcode 实际操作]二、视图与手势-(7)UIView视图的渐变填充

    目录:[Swift]Xcode实际操作 本文将演示创建一个具有渐变填充色的图形 import UIKit class ViewController: UIViewController { overri ...

  10. nmon性能监控工具学习

    nmon在AIX环境上,是一款很出名的系统性能监控工具,其实它除了可以运行在AIX,还可以在Linux环境下编译.使用. 源码下载地址: http://nmon.sourceforge.net/pmw ...